Tutorial by Examples

app.js const readline = require('readline'); const fs = require('fs'); var file = 'path.to.file'; var linesCount = 0; var rl = readline.createInterface({ input: fs.createReadStream(file), output: process.stdout, terminal: false }); rl.on('line', function (line) { linesCo...
app.js const readline = require('readline'); const fs = require('fs'); var file = 'path.to.file'; var rl = readline.createInterface({ input: fs.createReadStream(file), output: process.stdout, terminal: false }); rl.on('line', function (line) { console.log(line) // print...
NodeJS executes the module only the first time you require it. Any further require functions will re-use the same Object, thus not executing the code in the module another time. Also Node caches the modules first time they are loaded using require. This reduces the number of file reads and helps to...
The following example shows how to merge two arrays into one associative array, where the key values will be the items of the first array, and the values will be from the second: $array_one = ['key1', 'key2', 'key3']; $array_two = ['value1', 'value2', 'value3']; $array_three = array_combine($ar...
If you want to hide a keyboard by tap outside of it, it's possible to use this hacky trick (works only with Objective-C): - (void)viewDidLoad { [super viewDidLoad]; // dismiss keyboard when tap outside a text field UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecogn...
In many environments, you have access to a global console object that contains some basic methods for communicating with standard output devices. Most commonly, this will be the browser's JavaScript console (see Chrome, Firefox, Safari, and Edge for more information). // At its simplest, you can 'l...
Hstore columns can be useful to store settings. They are available in PostgreSQL databases after you enabled the extension. class CreatePages < ActiveRecord::Migration[5.0] def change create_table :pages do |t| enable_extension 'hstore' unless extension_enabled?('hstore') t...
The ng-click directive attaches a click event to a DOM element. The ng-click directive allows you to specify custom behavior when an element of DOM is clicked. It is useful when you want to attach click events on buttons and handle them at your controller. This directive accepts an expression wit...
Get Focus Swift textField.becomeFirstResponder() Objective-C [textField becomeFirstResponder]; Resign Swift textField.resignFirstResponder() Objective-C [textField resignFirstResponder];
Vagrantfile Vagrant.configure("2") do |config| config.vm.box = "ubuntu/trusty64" config.vm.provision "ansible" do |ansible| ansible.playbook = "vagrant-playbook.yml" end end vagrant-playbook.yml --- - hosts: default tasks: - name: ...
vagrant up By default the box will be provisioned.
vagrant up --no-provision
vagrant provision
F# allows functions to be added as "members" to types when they are defined (for example, Record Types). However F# also allows new instance members to be added to existing types - even ones declared elsewhere and in other .net languages. The following example adds a new instance method D...
F# allow existing types to be extended with new static functions. type System.String with static member EqualsCaseInsensitive (a, b) = String.Equals(a, b, StringComparison.OrdinalIgnoreCase) This new function can be invoked like this: let x = String.EqualsCaseInsensitive("abc", &...
Modules can be used to add new functions to existing Modules and Types. namespace FSharp.Collections module List = let pair item1 item2 = [ item1; item2 ] The new function can then be called as if it was an original member of List. open FSharp.Collections module Testing = le...
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; With an Identifier: Give the scene a Storyboard ID within the identity inspector of the storyboard. Instantiate in code: UIViewController *controller = [storyboard instantiateViewControllerWithIdentifi...
[<Measure>] type m // meters [<Measure>] type cm // centimeters // Conversion factor let cmInM = 100<cm/m> let distanceInM = 1<m> let distanceInCM = distanceInM * cmInM // 100<cm> // Conversion function let cmToM (x : int<cm>) = x / 100<cm/m> l...
from struct import pack print(pack('I3c', 123, b'a', b'b', b'c')) # b'{\x00\x00\x00abc'
from struct import unpack print(unpack('I3c', b'{\x00\x00\x00abc')) # (123, b'a', b'b', b'c')

Page 385 of 1336