Tutorial by Examples: f

Executing code after 1.5 seconds: Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { //The code you want to run after the time is up } }, 1500); //the time you want to delay in milliseconds Executing code repeatedly every...
__FUNCTION__ returns only the name of the function whereas __METHOD__ returns the name of the class along with the name of the function: <?php class trick { public function doit() { echo __FUNCTION__; } public function doitagain() { echo __METHOD_...
__CLASS__ magic constant returns the same result as get_class() function called without parameters and they both return the name of the class where it was defined (i.e. where you wrote the function call/constant name ). In contrast, get_class($this) and get_called_class() functions call, will both ...
Type hinting for classes and interfaces was added in PHP 5. Class type hint <?php class Student { public $name = 'Chris'; } class School { public $name = 'University of Edinburgh'; } function enroll(Student $student, School $school) { echo $student->name . ' is b...
const fs = require('fs'); const readline = require('readline'); const rl = readline.createInterface({ input: fs.createReadStream('text.txt') }); // Each new line emits an event - every time the stream receives \r, \n, or \r\n rl.on('line', (line) => { console.log(line); }); ...
git diff [HEAD|--staged...] --word-diff Rather than displaying lines changed, this will display differences within lines. For example, rather than: -Hello world +Hello world! Where the whole line is marked as changed, word-diff alters the output to: Hello [-world-]{+world!+} You can omit...
In this approach, the single is accessed via the static method: Singleton.getInstance(); To enforce only one instance of the singleton, a private static variable retains the instance, while any additional attempts to instantiate an instance are enforced within the constructor. package { publ...
More complicated tests sometimes need to have things set up before you run the code you want to test. It is possible to do this in the test function itself, but then you end up with large test functions doing so much that it is difficult to tell where the setup stops and the test begins. You can als...
To ignore a file foo.txt in any directory you should just write its name: foo.txt # matches all files 'foo.txt' in any directory If you want to ignore the file only in part of the tree, you can specify the subdirectories of a specific directory with ** pattern: bar/**/foo.txt # matches all file...
The setup script is the centre of all activity in building, distributing, and installing modules using the Distutils. It's purpose is the correct installation of the software. If all you want to do is distribute a module called foo, contained in a file foo.py, then your setup script can be as simpl...
Travis CI has CMake 2.8.7 pre-installed. A minimal .travis.yml script for an out-of source build language: cpp compiler: - gcc before_script: # create a build folder for the out-of-source build - mkdir build # switch to build directory - cd build # run cmake; here we assume...
The CMake version preinstalled on Travis is very old. You can use the official Linux binaries to build with a newer version. Here is an example .travis.yml: language: cpp compiler: - gcc # the install step will take care of deploying a newer cmake version install: # first we creat...
int a = 1; int *a_pointer = &a; To dereference a_pointer and change the value of a, we use the following operation *a_pointer = 2; This can be verified using the following print statements. printf("%d\n", a); /* Prints 2 */ printf("%d\n", *a_pointer); /* Also prints...
public class LogActionFilter : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { Log("OnActionExecuting", filterContext.RouteData); } public override void OnActionExecuted(ActionExecute...
The PrettyPrinter utility will 'pretty print' XML documents. The following code snippet pretty prints unformatted xml: import scala.xml.{PrettyPrinter, XML} val xml = XML.loadString("<a>Alana<b><c>Beth</c><d>Catie</d></b></a>") val formatt...
std::async is also able to make threads. Compared to std::thread it is considered less powerful but easier to use when you just want to run a function asynchronously. Asynchronously calling a function #include <future> #include <iostream> unsigned int square(unsigned int i){ r...
nuget sources add -name feedname -source http://sourcefeedurl
Defining Strings in the strings.xml file also allows for string formatting. The only caveat is that the String will need to be dealt with in code like below, versus simply attaching it to a layout. <string name="welcome_trainer">Hello Pokémon Trainer, %1$s! You have caught %2$d Poké...
To find all the files of a certain extension within the current path you can use the following find syntax. It works by making use of bash's built-in glob construct to match all the names having the .extension. find /directory/to/search -maxdepth 1 -type f -name "*.extension" To find ...
Subclass UINavigationController and then override these methods: In Objective-C: - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; } In Swift: override func preferredStatusBarStyle() -> UIStatusBarStyle { return .lightContent } Alternativel...

Page 57 of 457