Tutorial by Examples

Use quasiquotes to create a Tree in a macro. object macro { def addCreationDate(): java.util.Date = macro impl.addCreationDate } object impl { def addCreationDate(c: Context)(): c.Expr[java.util.Date] = { import c.universe._ val date = q"new java.util.Date()" // this...
std::optional<float> divide(float a, float b) { if (b!=0.f) return a/b; return {}; } Here we return either the fraction a/b, but if it is not defined (would be infinity) we instead return the empty optional. A more complex case: template<class Range, class Pred> auto find_if...
void print_name( std::ostream& os, std::optional<std::string> const& name ) { std::cout "Name is: " << name.value_or("<name missing>") << '\n'; } value_or either returns the value stored in the optional, or the argument if there is nothing s...
You can quit GHCi simply with :q or :quit ghci> :q Leaving GHCi. ghci> :quit Leaving GHCi. Alternatively, the shortcut CTRL+D (Cmd+D for OSX) has the same effect as :q.
If you have loaded a file into GHCi (e.g. using :l filename.hs) and you have changed the file in an editor outside of GHCi you must reload the file with :r or :reload in order to make use of the changes, hence you don't need to type again the filename. ghci> :r OK, modules loaded: Main. ghci...
Launch mode defines the behaviour of new or existing activity in the task. There are possible launch modes: standard singleTop singleTask singleInstance It should be defined in android manifest in <activity/> element as android:launchMode attribute. <activity android:launchM...
The FASTA file format is used for representing one or more nucleotide or amino acid sequences as a continuous string of characters. Sequences are annotated with a comment line, which starts with the > character, that precedes each sequence. The comment line is typically formatted in a uniform w...
A string can be written to a file with an instance of the File class. file = File.new('tmp.txt', 'w') file.write("NaNaNaNa\n") file.write('Batman!\n') file.close The File class also offers a shorthand for the new and close operations with the open method. File.open('tmp.txt', 'w') ...
You can call an instance method using the . special form: (.trim " hello ") ;;=> "hello" You can call instance methods with arguments like this: (.substring "hello" 0 2) ;;=> "he"
You can call an instance field using the .- syntax: (def p (java.awt.Point. 0 1)) (.-x p) ;;=> 0 (.-y p) ;;=> 1
You can create instance of objects in one of two ways: (java.awt.Point. 0 1) ;;=> => #object[java.awt.Point 0x3776d535 "java.awt.Point[x=0,y=1]"] Or (new java.awt.Point 0 1) ;;=> => #object[java.awt.Point 0x3776d535 "java.awt.Point[x=0,y=1]"]
You can call static methods like this: (System/currentTimeMillis) ;;=> 1469493415265 Or pass in arguments, like this: (System/setProperty "foo" "42") ;;=> nil (System/getProperty "foo") ;;=> "42"
You can call a Clojure function from Java code by looking up the function and invoking it: IFn times = Clojure.var("clojure.core", "*"); times.invoke(2, 2); This looks up the * function from the clojure.core namespace and invokes it with the arguments 2 & 2.
The macro() function allows you to add new functionality to Illuminate\Support\Collection objects Usage: Collection::macro("macro_name", function ($parameters) { // Your macro }); For example: Collection::macro('uppercase', function () { return $this->map(function ($i...
Also known as triple equals. This operator does not test equality, but rather tests if the right operand has an IS A relationship with the left operand. As such, the popular name case equality operator is misleading. This SO answer describes it thus: the best way to describe a === b is "if I ...
Goto https://atom.io/ and install the atom editor. Then install some Atom packages for easier Titanium coding: NameTypeFeaturestitanium language javascriptLanguageJS Autocomplete (non alloy)Titanium Alloyadd-onAll-in-one packageJump to definitionOpen relatedTSS HighlightTi-Createadd-onCreate proje...
We are just creating an empty Alloy app using CLI and Atom. Open a new terminal and add the following: ti create --id com.test -d . -n APPNAME -p all -t app -u http://migaweb.de cd APPNAME/ alloy new This will create a basic app (name: APPNAME, bundle identifier: com.test, type: app, platform...
There are several ways to compile your app. You can use the simulator/emulator, deploy it to your device or create store apk's/ipa's. There is also a live test tool (TiShadow) which saves you a lot of time waiting for the compiler. cli way # android to device ti build -p android -T device # a...
Is the relative path to the file from the current execution directory Assume we have this directory structure: /home/stackoverflow/script.rb script.rb contains: puts __FILE__ If you are inside /home/stackoverflow and execute the script like ruby script.rb then __FILE__ will output script.rb ...
__dir__ is not a constant but a function __dir__ is equal to File.dirname(File.realpath(__FILE__))

Page 542 of 1336