Tutorial by Examples

When you deploy your app to a (Node.js-specific) hosted environment, this environment usually offers a PORT-environment variable that you can use to run your server on. Changing the port number to process.env.PORT allows you to access the application. For example, http.createServer(function(reques...
You can use the node-inspector. Run this command to install it via npm: npm install -g node-inspector Then you can debug your application using node-debug app.js The Github repository can be found here: https://github.com/node-inspector/node-inspector Debugging natively You can also debu...
strpos can be understood as the number of bytes in the haystack before the first occurrence of the needle. var_dump(strpos("haystack", "hay")); // int(0) var_dump(strpos("haystack", "stack")); // int(3) var_dump(strpos("haystack", "stackoverf...
Tips & Tricks to avoid nasty situations EC2 Instances and EBS Set IAM Roles. Unlike tags, the IAM Role is set once and for all on EC2 instanciation (even after 4 years) ! Try to identify and categorize beforehand your instances so you can give an them appropriate IAM roles. IAM Roles are ...
The intrinsic pack function packs an array into a vector, selecting elements based on a given mask. The function has two forms PACK(array, mask) PACK(array, mask, vector) (that is, the vector argument is optional). In both cases array is an array, and mask of logical type and conformable with...
Consider the following component with one input myInput and an internal value called someInternalValue. Both of them are used in a component's template. import {Component, Input} from '@angular/core'; @Component({ template:` <div> <p>{{myInput}}</p> <p>{...
Python 2.x2.7 Python 2 import urllib response = urllib.urlopen('http://stackoverflow.com/documentation/') Using urllib.urlopen() will return a response object, which can be handled similar to a file. print response.code # Prints: 200 The response.code represents the http return value. 20...
To POST data pass the encoded query arguments as data to urlopen() Python 2.x2.7 Python 2 import urllib query_parms = {'username':'stackoverflow', 'password':'me.me'} encoded_parms = urllib.urlencode(query_parms) response = urllib.urlopen("https://stackoverflow.com/users/login", enco...
trait Hello { public function sayHello() { echo 'Hello '; } } trait World { public function sayWorld() { echo 'World'; } } class MyHelloWorld { use Hello, World; public function sayExclamationMark() { echo '!'; } } $o = new My...
trait HelloWorld { public function sayHello() { echo 'Hello World!'; } } // Change visibility of sayHello class MyClass1 { use HelloWorld { sayHello as protected; } } // Alias method with changed visibility // sayHello visibility not changed class MyClass2 { u...
Any array can be quickly decomposed by assigning its elements into multiple variables. A simple example: arr = [1, 2, 3] # --- a = arr[0] b = arr[1] c = arr[2] # --- or, the same a, b, c = arr Preceding a variable with the splat operator (*) puts into it an array of all the elements that h...
Variables don't necessarily have to expand to their values - substrings can be extracted during expansion, which can be useful for extracting file extensions or parts of paths. Globbing characters keep their usual meanings, so .* refers to a literal dot, followed by any sequence of characters; it's ...
Consider this broken snippet: def foo bar = [1, 2, 3, 4].map do |x| return 0 if x.even? x end puts 'baz' bar end foo # => 0 One might expect return to yield a value for map's array of block results. So the return value of foo would be [1, 0, 3, 0]. Instead, return retu...
The following compares two files with diff using process substitution instead of creating temporary files. diff <(curl http://www.example.com/page1) <(curl http://www.example.com/page2)
This feeds a while loop with the output of a grep command: while IFS=":" read -r user _ do # "$user" holds the username in /etc/passwd done < <(grep "hello" /etc/passwd)
Problem: Some data needs to be passed to a scene loaded from a fxml. Solution Specify a controller using the fx:controller attribute and get the controller instance created during the loading process from the FXMLLoader instance used to load the fxml. Add methods for passing the data to the contr...
Problem: Some data needs to be passed to a scene loaded from a fxml. Solution Set the controller using the FXMLLoader instance used later to load the fxml. Make sure the controller contains the relevant data before loading the fxml. Note: in this case the fxml file must not contain the fx:contro...
Problem: Some data needs to be passed to a scene loaded from a fxml. Solution Specify a controller factory that is responsible for creating the controllers. Pass the data to the controller instance created by the factory. FXML <?xml version="1.0" encoding="UTF-8"?> &...
LinqPad is a great tool that allows you to learn and test features of .Net languages (C#, F# and VB.Net.) Install LinqPad Create a new Query (Ctrl + N) Under language, select "C# statements" Type the following code and hit run (F5) string hw = "Hello World&quo...
In Elm, values are declared by writing a name, an equals sign, and then the actual value: someValue = 42 Functions are also values, with the addition of taking a value or values as arguments. They are usually written as follows: double n = n * 2 Every value in Elm has a type. The types of th...

Page 332 of 1336