Tutorial by Examples: ear

NSArray *myColors = [NSArray arrayWithObjects: @"Red", @"Green", @"Blue", @"Yellow", nil]; // Convert myColors to mutable NSMutableArray *myColorsMutable = [myColors mutableCopy];
To search if a String contains a substring, do the following: NSString *myString = @"This is for checking substrings"; NSString *subString = @"checking"; BOOL doesContainSubstring = [myString containsString:subString]; // YES If targeting iOS 7 or OS X 10.9 (or earlier)...
HTML <input type="range"></input> CSS EffectPseudo SelectorThumbinput[type=range]::-webkit-slider-thumb, input[type=range]::-moz-range-thumb, input[type=range]::-ms-thumbTrackinput[type=range]::-webkit-slider-runnable-track, input[type=range]::-moz-range-track, input[type=...
Given the text: foo: bar I would like to replace anything following "foo: " with "baz", but I want to keep "foo: ". This could be done with a capturing group like this: s/(foo: ).*/$1baz/ Which results in the text: foo: baz Example 1 or we could use \K,...
The recommended way (Since ES5) is to use Array.prototype.find: let people = [ { name: "bob" }, { name: "john" } ]; let bob = people.find(person => person.name === "bob"); // Or, more verbose let bob = people.find(function(person) { return person.na...
After receiving the arguments, you can print them as follows: int main(int argc, char **argv) { for (int i = 1; i < argc; i++) { printf("Argument %d: [%s]\n", i, argv[i]); } } Notes The argv parameter can be also defined as char *argv[]. argv[0] may co...
To get your most recent stash after running git stash, use git stash apply To see a list of your stashes, use git stash list You will get a list that looks something like this stash@{0}: WIP on master: 67a4e01 Merge tests into develop stash@{1}: WIP on master: 70f0d95 Add user role to lo...
hash( (1, 2) ) # ok hash( ([], {"hello"}) # not ok, since lists and sets are not hashabe Thus a tuple can be put inside a set or as a key in a dict only if each of its elements can. { (1, 2) } # ok { ([], {"hello"}) ) # not ok
Add years on the dateTime object: DateTime baseDate = new DateTime(2000, 2, 29); Console.WriteLine("Base Date: {0:d}\n", baseDate); // Show dates of previous fifteen years. for (int ctr = -1; ctr >= -15; ctr--) Console.WriteLine("{0,2} year(s) ago:{1:d}", ...
// Obtain an instance of JavaScript engine ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("JavaScript"); //String to be evaluated String str = "3+2*4+5"; //Value after doing Arithmetic operation with operator preceden...
const auto input = "Some people, when confronted with a problem, think \"I know, I'll use regular expressions.\""s; smatch sm; cout << input << endl; // If input ends in a quotation that contains a word that begins with "reg" and another word begining...
The following code will print the arguments to the program, and the code will attempt to convert each argument into a number (to a long): #include <stdlib.h> #include <stdio.h> #include <errno.h> #include <limits.h> int main(int argc, char* argv[]) { for (int ...
From guides.rubyonrails.org: Instead of generating a model directly . . . let's set up a scaffold. A scaffold in Rails is a full set of model, database migration for that model, controller to manipulate it, views to view and manipulate the data, and a test suite for each of the above. Here's a...
The following code will show week of the year number on the left side of the datepicker. By default the week start on Monday, but it can be customized using firstDay option. The first week of the year contains the first Thursday of the year, following the ISO 8601 definition. <input type="t...
If you want two or more arguments to be mutually exclusive. You can use the function argparse.ArgumentParser.add_mutually_exclusive_group(). In the example below, either foo or bar can exist but not both at the same time. import argparse parser = argparse.ArgumentParser() group = parser.add_mut...
To get any random color: function randomColor():uint { return Math.random() * 0xFFFFFF; } If you need more control over the red, green and blue channels: var r:uint = Math.random() * 0xFF; var g:uint = Math.random() * 0xFF; var b:uint = Math.random() * 0xFF; var color:uint = r <&...
To round a value to the nearest multiple of x: function roundTo(value:Number, to:Number):Number { return Math.round(value / to) * to; } Example: roundTo(8, 5); // 10 roundTo(17, 3); // 18
julia> sub2ind((3,3), 1, 1) 1 julia> sub2ind((3,3), 1, 2) 4 julia> sub2ind((3,3), 2, 1) 2 julia> sub2ind((3,3), [1,1,2], [1,2,1]) 3-element Array{Int64,1}: 1 4 2
function isLeapYear(year:int):Boolean { return daysInMonth(year, 1) == 29; }
Sometimes two arrays of the same length need to be iterated together, for example: $people = ['Tim', 'Tony', 'Turanga']; $foods = ['chicken', 'beef', 'slurm']; array_map is the simplest way to accomplish this: array_map(function($person, $food) { return "$person likes $food\n"; ...

Page 3 of 21