Tutorial by Examples: c

There are two functions that can be used to obtain a readable representation of an object. repr(x) calls x.__repr__(): a representation of x. eval will usually convert the result of this function back to the original object. str(x) calls x.__str__(): a human-readable string that describes the obje...
There are two main approaches to creating a thread in Java. In essence, creating a thread is as easy as writing the code that will be executed in it. The two approaches differ in where you define that code. In Java, a thread is represented by an object - an instance of java.lang.Thread or its subcl...
A simple example of using multiple processes would be two processes (workers) that are executed separately. In the following example, two processes are started: countUp() counts 1 up, every second. countDown() counts 1 down, every second. import multiprocessing import time from random impor...
import UIKit import WebKit class ViewController: UIViewController, UISearchBarDelegate, WKNavigationDelegate, WKUIDelegate { var searchbar: UISearchBar! //All web-browsers have a search-bar. var webView: WKWebView! //The WKWebView we'll use. var toolbar: UIToolbar! //Toolb...
A file can be locked using the FileChannel API that can be acquired from Input Output streams and readers Example with streams // Open a file stream FileInputStream ios = new FileInputStream(filename); // get underlying channel FileChannel channel = ios.getChannel(); /* * t...
To ensure that our collection can be iterated using iterator or for-each loop, we have to take care of following steps: The stuff we want to iterate upon has to be Iterable and expose iterator(). Design a java.util.Iterator by overriding hasNext(), next() and remove(). I have added a simple ...
You should remember that regex was designed for matching a date (or not). Saying that a date is valid is a much more complicated struggle, since it will require a lot of exception handling (see leap year conditions). Let's start by matching the month (1 - 12) with an optional leading 0: 0?[1-9]|1[...
Matching an email address within a string is a hard task, because the specification defining it, the RFC2822, is complex making it hard to implement as a regex. For more details why it is not a good idea to match an email with a regex, please refer to the antipattern example when not to use a ...
Here's how to match a prefix code (a + or (00), then a number from 1 to 1939, with an optional space): This doesn't look for a valid prefix but something that might be a prefix. See the full list of prefixes (?:00|\+)?[0-9]{4} Then, as the entire phone number length is, at most, 15, we can look...
A simple example: CL-USER> (defun make-apply-twice (fun) "return a new function that applies twice the function`fun' to its argument" (lambda (x) (funcall fun (funcall fun x)))) MAKE-APPLY-TWICE CL-USER> (funcall (make-apply-twice #'1+) 3) 5 ...
Sometimes we need preserve whole model and transfer it across actions or even controllers. Storing model at session good solution for this type of requirements. If we combine this with powerful model binding features of MVC we get elegant way of doing so. We can create generic session based model bi...
Read the accelerometer Sensor with precision. This example allocates memory: void Update() { //Get Precise Accelerometer values Vector3 accelValue = preciseAccelValue(); Debug.Log("PRECISE X: " + accelValue.x + " Y: " + accelValue.y + " Z: " + acc...
Given a String containing the name of a class, it's Class object can be accessed using Class.forName: Class clazz = null; try { clazz = Class.forName("java.lang.Integer"); } catch (ClassNotFoundException ex) { throw new IllegalStateException(ex); } Java SE 1.2 It can be s...
You can reload the current state using the $state.reload method from your controller $state.reload() This is a shorthand for (code taken from the official docs) $state.transitionTo($state.current, $stateParams, { reload: true, inherit: false, notify: false }); Running a reload on your ...
Constants in Go may be typed or untyped. For instance, given the following string literal: "bar" one might say that the type of the literal is string, however, this is not semantically correct. Instead, literals are Untyped string constants. It is a string (more correctly, its default ...
If you have only just popped it and the terminal is still open, you will still have the hash value printed by git stash pop on screen: $ git stash pop [...] Dropped refs/stash@{0} (2ca03e22256be97f9e40f08e6d6773c7d41dbfd1) (Note that git stash drop also produces the same line.) Otherwise, you...
Sometimes it makes sense to nest view's or routes within one another. For example on the dashboard you want several sub views, similar to tabs but implemented via the routing system, to show the users' projects, contacts, messages ets. In order to support such scenarios the router allows us to defin...
Analysis of Variance (aov) is used to determine if the means of two or more groups differ significantly from each other. Responses are assumed to be independent of each other, Normally distributed (within each group), and the within-group variances are assumed equal. In order to complete the analys...
In many cases, for instance when using web views in table view cells, it's important to determine the content size of the rendered HTML page. After loading the page, this can be calculated in the UIWebViewDelegate delegate method: - (void) webViewDidFinishLoad:(UIWebView *) aWebView { CGRect f...
[ alias ] ignored = ! git ls-files --others --ignored --exclude-standard --directory \ && git ls-files --others -i --exclude-standard Shows one line per file, so you can grep (only directories): $ git ignored | grep '/$' .yardoc/ doc/ Or count: ~$ git ignored | ...

Page 296 of 826