Posts

Showing posts from January, 2017

AngularJS : When To Use Service Instead Of Factory

Image
Answer : Explanation You got different things here: First: If you use a service you will get the instance of a function (" this " keyword). If you use a factory you will get the value that is returned by invoking the function reference (the return statement in factory). ref: angular.service vs angular.factory Second: Keep in mind all providers in AngularJS (value, constant, services, factories) are singletons! Third: Using one or the other (service or factory) is about code style. But, the common way in AngularJS is to use factory . Why ? Because "The factory method is the most common way of getting objects into AngularJS dependency injection system. It is very flexible and can contain sophisticated creation logic. Since factories are regular functions, we can also take advantage of a new lexical scope to simulate "private" variables. This is very useful as we can hide implementation details of a given service." (

Border None Bootstrap 5 Code Example

Example 1: border radius bootstrap Border-radius Add classes to an element to easily round its corners. < img src = " ... " alt = " ... " class = " rounded " > < img src = " ... " alt = " ... " class = " rounded-top " > < img src = " ... " alt = " ... " class = " rounded-right " > < img src = " ... " alt = " ... " class = " rounded-bottom " > < img src = " ... " alt = " ... " class = " rounded-left " > < img src = " ... " alt = " ... " class = " rounded-circle " > < img src = " ... " alt = " ... " class = " rounded-0 " > Example 2: border-radius class in bootstrap 4 < img src = " ... " alt = " ... " class = " rounded " > < img src = " ... " alt = &quo

Clear Cache In React Native Code Example

Example 1: react native clear cach watchman watch - del - all && rm - rf $ TMPDIR / react - native - packager - cache - * && rm - rf $ TMPDIR / metro - bundler - cache - * && rm - rf node_modules / && npm cache clean -- force && npm install && npm start -- -- reset - cache Example 2: npm start reset cache npm start -- -- reset - cache Example 3: cache clear in laravel php artisan cache : clear php artisan view : clear php artisan route : clear php artisan clear - compiled php artisan config : cache Example 4: how to clear pod cache in react native rm - rf ~ / Library / Caches / CocoaPods rm - rf Pods rm - rf ~ / Library / Developer / Xcode / DerivedData /* pod deintegrate pod setup pod install Example 5: yarn start --reset-cache watchman watch - del - all && rm - f yarn . lock && rm - rf node_modules && yarn && yarn start -- reset - cache

Can JavaScript Break Anonimity Provided By Tor?

Image
Answer : tl;dr: Yes, JavaScript can break anonymity provided by Tor if there's a browser vulnerability involved, if you enable features that weren't designed anonymity in mind (like WebRTC or Geolocation API), or through giving out more information for browser fingerprinting . This particular site (https://pearsonpte.com/) uses the Geolocation API on line 31: navigator.geolocation.getCurrentPosition() . This doesn't use geolocation data for your IP address, but a location provider like GPS chip on your device. Usually the browser prompts you for a permission per site, but this can be allowed or denied globally. Allowing geolocation globally would be dangerous as it reveals your location in much more detail than your IP address. Configuring your browser to prevent everything that could reveal your identity takes a lot of effort and is likely to fail. Even if you have all the knowledge to disable everything necessary, the more you customize your settings the more uniqu

Can Anyone Give A Real Life Example Of Supervised Learning And Unsupervised Learning?

Answer : Supervised learning: You get a bunch of photos with information about what is on them and then you train a model to recognize new photos. You have a bunch of molecules and information about which are drugs and you train a model to answer whether a new molecule is also a drug. Unsupervised learning: You have a bunch of photos of 6 people but without information about who is on which one and you want to divide this dataset into 6 piles, each with the photos of one individual. You have molecules, part of them are drugs and part are not but you do not know which are which and you want the algorithm to discover the drugs. Supervised Learning: is like learning with a teacher training dataset is like a teacher the training dataset is used to train the machine Example: Classification: Machine is trained to classify something into some class. classifying whether a patient has disease or not classifying whether an email is spam or no

Update Multiple Columns Sql Code Example

Example 1: update column sql server UPDATE table_name SET column1 = value1 , column2 = value2 , . . . WHERE condition ; Example 2: add multiple columns to table sql //Example ALTER TABLE employees ADD last_name VARCHAR ( 50 ) , first_name VARCHAR ( 40 ) ; Example 3: sql update multiple columns from another table -- Oracle UPDATE table2 t2 SET ( VALUE1 , VALUE2 ) = ( SELECT COL1 AS VALUE1 , COL1 AS VALUE2 FROM table1 t1 WHERE t1 . ID = t2 . ID ) ; -- SQL Server UPDATE table2 t2 SET t2 . VALUE1 = t1 . COL1 , t2 . VALUE2 = t1 . COL2 FROM table1 t1 INNER JOIN t2 ON t1 . ID = t2 . ID ; -- MySQL UPDATE table2 t2 INNER JOIN table1 t1 USING ( ID ) SET T2 . VALUE1 = t1 . COL1 , t2 . VALUE2 = t1 . COL2 ; Example 4: sql server update multiple columns at once UPDATE Person . Person Set FirstName = 'Kenneth' , LastName = 'Smith' WHERE BusinessEntityID = 1 Example 5: update multi

Altium Designer - Create Keepout Based On Board Outline

Answer : Go to Design -> Board Shape -> Create Primitives From Board Shape. Then select what layer you want to create the primitives on and how thick you want the outline to be. I don't have access to Altium at the moment so this is from memory. I use it all the time, though I use a separate mechanical layer specifically for the board outline (usually Mechanical Layer 6 renamed to "BOARD_OUTLINE"). What @DerStrom8 had suggested is correct. +1 to him. I'd like to elaborate a little. Go to Design → Board Shape → Create Primitives from Board Shape Pick layer and width in the dialog. Click OK. Altium will create a track around the PCB. This isn't the keep-out yet. Select this new track around the outline of the PCB. Go to Tolls → Convert → Convert Selected Primitives to Keepouts . Now you have the keep-out around the board outline. At the time of writing, I'm running Altium 20.1.10 . added: Related function in Altium: Board O

Write Hello World In Cobol Code Example

Example: hello world in cobol $ vim helloworld IDENTIFICATION DIVISION. PROGRAM-ID. HELLO-WORLD. * simple hello world program PROCEDURE DIVISION. DISPLAY 'Hello world!' . STOP RUN.

Print Double C Code Example

Example: print double in c # include <stdio.h> int main ( ) { double d = 123.32445 ; //using %f format specifier printf ( "Value of d = %f\n" , d ) ; //using %lf format specifier printf ( "Value of d = %lf\n" , d ) ; return 0 ; }

Any Way To Specify Optional Parameter Values In PHP?

Answer : PHP does not support named parameters for functions per se. However, there are some ways to get around this: Use an array as the only argument for the function. Then you can pull values from the array. This allows for using named arguments in the array. If you want to allow optional number of arguments depending on context, then you can use func_num_args and func_get_args rather than specifying the valid parameters in the function definition. Then based on number of arguments, string lengths, etc you can determine what to do. Pass a null value to any argument you don't want to specify. Not really getting around it, but it works. If you're working in an object context, then you can use the magic method __call() to handle these types of requests so that you can route to private methods based on what arguments have been passed. A variation on the array technique that allows for easier setting of default values: function foo($arguments) { $defaults = array(

Clear/truncate File In C When Already Open In "r+" Mode

Answer : With standard C, the only way is to reopen the file in "w+" mode every time you need to truncate. You can use freopen() for this. "w+" will continue to allow reading from it, so there's no need to close and reopen yet again in "r+" mode. The semantics of "w+" are: Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file. (Taken from the fopen(3) man page.) You can pass a NULL pointer as the filename parameter when using freopen() : my_file = freopen(NULL, "w+", my_file); If you don't need to read from the file anymore at all, when "w" mode will also do just fine. You can write a function something like this:(pseudo code) if(this is linux box) use truncate() else if (this is windows box) use _chsize_s() This is the most straightforward solution for your requirement. Refer: man truncate and

Create Controller Laravel Code Example

Example 1: laravel create controller php artisan make : controller MyController Example 2: laravel create controller command php artisan make : controller UserController Example 3: laravel route controller use App\Http\Controllers\UserController ; Route :: get ( 'user/{id}' , [ UserController :: class , 'show' ] ) ; Example 4: how to create controller in laravel php artisan make : controller PhotoController -- resource Example 5: how to make controller in laravel php artisan make : controller ShowProfile Example 6: laravel controller middleware class UserController extends Controller { /** * Instantiate a new controller instance. * * @return void */ public function __construct ( ) { $this -> middleware ( 'auth' ) ; $this -> middleware ( 'log' ) -> only ( 'index' ) ; $this -> middleware ( 'subscribed' ) -> except ( 'store' ) ; } }

Code Canyon Code Example

Example: code camp // Main function fn main(){ let arr:[i32;4] = [1,2,3,4]; println!("array size is {}",arr.len()); }

Check Is String Javascript Code Example

Example 1: is string javascript function isString ( value ) { return typeof value === 'string' || value instanceof String ; } isString ( '' ) ; // true isString ( 1 ) ; // false isString ( { } ) ; // false isString ( [ ] ) ; // false isString ( new String ( 'teste' ) ) // true Example 2: if string javascript if ( typeof myVar === 'string' ) { /* code */ } ; Example 3: js check if variable is string if ( typeof myVar === 'integer' ) { //I am indeed an integer } if ( typeof myVar === 'boolean' ) { //I am indeed a boolean } Example 4: if variable is string javascript var booleanValue = true ; var numericalValue = 354 ; var stringValue = "This is a String" ; var stringObject = new String ( "This is a String Object" ) ; alert ( typeof booleanValue ) // displays "boolean" alert ( typeof numericalValue ) // displays "number" alert (

Antimatter To Infinity Points Antimatter Dimensions Code Example

Example: antimatter dimensions setinterval setInterval(() => document.getElementById("maxall").click(), 100); //type into console //for maxall, other button names: //dimension sacrifice: "sacrifice" dimension boost: "softReset" //Antimatter galaxy: "secondSoftReset"

Can I Embed HTML Into An HTML5 SVG Fragment?

Answer : Yes, with the <foreignObject> element, see this question for some examples. Alternatively, if you have an html5 document you can also use CSS positioning and z-index to make parts of html visible where you want laid out on top of the svg. If you do it like that you don't need to nest the html inside the svg fragment. This will give you the most consistent behaviour across browsers in my experience. Foreign Objects are not supported on Internet explorer. Please check ForeignObject Copied from bl.ocks.org (thank you, Janu Verma) <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>HTML inside SVG</title> <style type="text/css"></style></head> <body> <div>I'm a div inside the HTML</div> <svg width="500" height="300" style="border:1px red solid" xmlns="http://www.w3.org/2000/svg">

Cmd Dns Flush Code Example

Example: windows flush dns ipconfig /flushdns

Git Rebase Vs Merge Code Example

Example 1: what is git rebase the rebase command integrates changes from one branch into another . It is an alternative to the better known "merge" command . Most visibly , rebase differs from merge by rewriting the commit history in order to produce a straight , linear succession of commits . Example 2: git rebase vs merge Git rebase and merge both integrate changes from one branch into another . Where they differ is how it's done . Git rebase moves a feature branch into a master . Git merge adds a new commit , preserving the history Example 3: how to rebasde $ git checkout experiment $ git rebase master First , rewinding head to replay your work on top of it . . . Applying : added staged command Example 4: VS github merge // Go to the main branch you want the side branch to be merged to git checkout < Main branch name > // Merge your side branch git merge < Side branch name > Example 5: git pull vs rebase git pull fetches the lat

Android Webview Set Proxy Programmatically Kitkat

Answer : Here is my solution: public static void setKitKatWebViewProxy(Context appContext, String host, int port) { System.setProperty("http.proxyHost", host); System.setProperty("http.proxyPort", port + ""); System.setProperty("https.proxyHost", host); System.setProperty("https.proxyPort", port + ""); try { Class applictionCls = Class.forName("android.app.Application"); Field loadedApkField = applictionCls.getDeclaredField("mLoadedApk"); loadedApkField.setAccessible(true); Object loadedApk = loadedApkField.get(appContext); Class loadedApkCls = Class.forName("android.app.LoadedApk"); Field receiversField = loadedApkCls.getDeclaredField("mReceivers"); receiversField.setAccessible(true); ArrayMap receivers = (ArrayMap) receiversField.get(loadedApk); for (Object receiverMap : receivers.values())

Arctan(1/x) Derivative Code Example

Example: derivative of arctan d/dx arctan(x) = 1/(1+x^2)

Android: Picasso Load Image Failed . How To Show Error Message

Answer : Use builder: Picasso.Builder builder = new Picasso.Builder(this); builder.listener(new Picasso.Listener() { @Override public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) { exception.printStackTrace(); } }); builder.build().load(URL).into(imageView); Edit For version 2.71828 they have added the exception to the onError callback: Picasso.get() .load("yoururlhere") .into(imageView, new Callback() { @Override public void onSuccess() { } @Override public void onError(Exception e) { } }) When you use callback, the picaso will call method onSuccess and onError! File fileImage = new File(mPathImage); Picasso.with(mContext).load(fileImage) .placeholder(R.drawable.draw_detailed_view_display) .error

Book Recommendation : Olympiad Combinatorics Book

Answer : Here is a list of books for perfect olympiad combinatorics preparation. For general study: (1) A Path to Combinatorics for Undergraduates (2) Principles and Techniques in Combinatorics (3) Problem-Solving Methods in Combinatorics: An Approach to Olympiad Problems For practising problem-solving: (1) 102 Combinatorial Problems (2) Combinatorics: A Problem-Based Approach (3) The IMO Compendium: A Collection of Problems Suggested for The International Mathematical Olympiads: 1959-2009 Second Edition For Olympiad Graph theory: Olympiad uses of graph theory is a bit different from formal graph theory taught in university courses. The best book for this is (1) Graph Theory: In Mathematical Olympiad And Competitions (2) IMO Training 2008: Graph Theory For probabilistic methods in olympiad combinatorics: (1) Expected uses of probability (2) Unexpected uses of probability For generating functions and recurrence relations: Generatingfunctionology For combinatorial in

Default Ssh Password Raspberry Pi Code Example

Example: default password raspberry pi User management in Raspberry Pi OS is done on the command line . The default user is pi , and the password is raspberry .

AWS: Cloud Formation: Is It Possible To Use Multiple "DependsOn"?

Answer : Yes, The DependsOn attribute can take a single string or list of strings . http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html Syntax: "DependsOn" : [ String, ... ] This answer comes up first in Google, so I will include how to do multiple dependson attributes in YAML, which I found in this answer. AnotherProductionResource: Type: AWS::CloudFormation::Stack Condition: ISProduction DependsOn: - AResource - MyProductionResource Properties: [...] Yes, "DependsOn" can take multiple strings. I have listed an example below: "DependsOn": [ "S3BucketAppElbLogs", "ElbLogAppBucketPolicy" ]

Amd Ryzen 5 3500u Vs Intel I5 11th Gen Code Example

Example: ryzen 5 vs intel i5 10th gen AMD won by 1 point overall they all are dope

Bootstrap Navbar W3school Code Example

Example: bootstrap navbar right <! DOCTYPE html > < html lang = " en " > < head > < title > Bootstrap Example </ title > < meta charset = " utf-8 " > < meta name = " viewport " content = " width=device-width, initial-scale=1 " > < link rel = " stylesheet " href = " https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css " > < script src = " https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js " > </ script > < script src = " https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js " > </ script > </ head > < body > < nav class = " navbar navbar-inverse " > < div class = " container-fluid " > < div class = " navbar-header " > < a class = " navbar-brand " href = " # &qu

C Perror Example

Defined in header <stdio.h> void perror ( const char * s ) ; Prints a textual description of the error code currently stored in the system variable errno to stderr . The description is formed by concatenating the following components: the contents of the null-terminated byte string pointed to by s , followed by ": " (unless s is a null pointer or the character pointed to by s is the null character) implementation-defined error message string describing the error code stored in errno , followed by '\n' . The error message string is identical to the result of strerror ( errno ) . Parameters s - pointer to a null-terminated string with explanatory message Return value (none). Example # include <stdio.h> int main ( void ) { FILE * f = fopen ( "non_existent" , "r" ) ; if ( f == NULL ) { perror ( "fopen() failed" ) ; } else { fclose