Tutorial by Examples: f

We prepare a file called reverser.ml with the following contents: let acc = ref [] in try while true do acc := read_line () :: !acc; done with End_of_file -> print_string (String.concat "\n" !acc) We then compile our program using ...
A reference to an option &Option<T> cannot be unwrapped if the type T is not copyable. The solution is to change the option to &Option<&T> using as_ref(). Rust forbids transferring of ownership of objects while the objects are borrowed. When the Option itself is borrowed (&a...

For

for loops are simplified syntax for a very common loop pattern, which could be accomplished in more lines with a while loop. The following is a common example of a for loop, which will execute 100 times and then stop. for (int i = 0; i < 100; i++) { // do something } This is equivalen...
There are some ways to break or change a loop's flow. break; will exit the current loop, and will not execute any more lines within that loop. continue; will not execute any more code within the current iteration of the loop, but will remain in the loop. The following loop will execute 101 times ...
localStorage, sessionStorage are JavaScript Objects and you can treat them as such. Instead of using Storage Methods like .getItem(), .setItem(), etc… here's a simpler alternative: // Set localStorage.greet = "Hi!"; // Same as: window.localStorage.setItem("greet", "Hi!&qu...
Functions are of the type Function: function example():void { } trace(example is Function); // true They can be referenced by other variables with the type Function: var ref:Function = example; ref(); // ref.call(), ref.apply(), etc. And they can be passed in as arguments for parameters wh...
Before ECMAScript 2015 (ES6), a parameter's default value could be assigned in the following way: function printMsg(msg) { msg = typeof msg !== 'undefined' ? // if a value was provided msg : // then, use that value in the reassignemnt 'Default value for ...
Sometimes we need to change type from Collection<T?> to Collections<T>. In that case, filterNotNull is our solution. val a: List<Int?> = listOf(1, 2, 3, null) val b: List<Int> = a.filterNotNull()
Holy Grail layout is a layout with a fixed height header and footer, and a center with 3 columns. The 3 columns include a fixed width sidenav, a fluid center, and a column for other content like ads (the fluid center appears first in the markup). CSS Flexbox can be used to achieve this with a very s...
A simple example on how to read a UTF text file synchronously. import flash.filesystem.File; import flash.filesystem.FileMode; import flash.filesystem.FileStream; //First, get a reference to the file you want to load var myFile:File = File.documentsDirectory.resolvePath("lifestory.txt&...
Declare the AppWidgetProvider class in your application's AndroidManifest.xml file. For example: <receiver android:name="ExampleAppWidgetProvider" > <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter&gt...
This is MATLAB's long-winded way of saying that it cannot find the function that you're trying to call. There are a number of reasons you could get this error: That function was introduced after your current version of MATLAB The MATLAB online documentation provides a very nice feature which allow...
Early bound (requires a reference to Microsoft Scripting Runtime): Public Sub EnumerateDirectory() Dim fso As Scripting.FileSystemObject Set fso = New Scripting.FileSystemObject Dim targetFolder As Folder Set targetFolder = fso.GetFolder("C:\") Dim foundFi...
It is considered good practice to use a prefix when creating git archives, so that extraction will place all files inside a directory. To create an archive of HEAD with a directory prefix: git archive --output=archive-HEAD.zip --prefix=src-directory-name HEAD When extracted all the files will be...
It is also possible to create archives of other items than HEAD, such as branches, commits, tags, and directories. To create an archive of a local branch dev: git archive --output=archive-dev.zip --prefix=src-directory-name dev To create an archive of a remote branch origin/dev: git archive --...
With git archive it is possible to create compressed archives of a repository, for example for distributing releases. Create a tar archive of current HEAD revision: git archive --format tar HEAD | cat > archive-HEAD.tar Create a tar archive of current HEAD revision with gzip compression: gi...
This program illustrates how one can copy a file using readable and writable streams using the createReadStream(), and createWriteStream() functions provided by the file system module. //Require the file System module var fs = require('fs'); /* Create readable stream to file in current direc...
Sometimes it might be necessary to manually promisify a callback function. This could be for a case where the callback does not follow the standard error-first format or if additional logic is needed to promisify: Example with fs.exists(path, callback): var fs = require('fs'); var existsAsync =...
Sometimes you just need a diff to apply using patch. The regular git --diff does not work. Try this instead: git diff --no-prefix > some_file.patch Then somewhere else you can reverse it: patch -p0 < some_file.patch
It's a regular pattern in design these days to vertically align call to actions inside its containing cards like this: This can be achieved using a special trick with flexbox HTML <div class="cards"> <div class="card"> <p>Lorem ipsum Magna proident ...

Page 116 of 457