Tutorial by Examples: c

We will model the process #Load the forecast package library(forecast) #Generate an AR1 process of length n (from Cowpertwait & Meltcalfe) # Set up variables set.seed(1234) n <- 1000 x <- matrix(0,1000,1) w <- rnorm(n) # loop to create x for (t in 2:n) x[t] <- 0.7...
Sometimes you want to do something with the exception you catch (like write to log or print a warning) and let it bubble up to the upper scope to be handled. To do so, you can rethrow any exception you catch: try { ... // some code here } catch (const SomeException& e) { std::cout &l...
Color state lists can be used as colors, but will change depending on the state of the view they are used for. To define one, create a resource file in res/color/foo.xml <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/ap...
A type that conforms to the SequenceType protocol can iterate through it's elements within a closure: collection.forEach { print($0) } The same could also be done with a named parameter: collection.forEach { item in print(item) } *Note: Control flow statements (such as break or continu...
You can create one table from another by adding a SELECT statement at the end of the CREATE TABLE statement: CREATE TABLE stack ( id_user INT, username VARCHAR(30), password VARCHAR(30) ); Create a table in the same database: -- create a table from another table in the same data...
A static class is lazily initialized on member access and lives for the duration of the application domain. void Main() { Console.WriteLine("Static classes are lazily initialized"); Console.WriteLine("The static constructor is only invoked when the class is first accessed&...
import pandas as pd import numpy as np np.random.seed(123) x = np.random.standard_normal(4) y = range(4) df = pd.DataFrame({'X':x, 'Y':y}) >>> df X Y 0 -1.085631 0 1 0.997345 1 2 0.282978 2 3 -1.506295 3
If you want to catch all routes, then you could use a regular expression as shown: Route::any('{catchall}', 'CatchAllController@handle')->where('catchall', '.*'); Important: If you have other routes and you don't want for the catch-all to interfere, you should put it in the end. For example: ...
A select case construct conditionally executes one block of constructs or statements depending on the value of a scalar expression in a select case statement. This control construct can be considered as a replacement for computed goto. [name:] SELECT CASE (expr) [CASE (case-value [, case-value] .....
To download the entire repository including the full history and all branches, type: git clone <url> The example above will place it in a directory with the same name as the repository name. To download the repository and save it in a specific directory, type: git clone <url> [dire...
You can create a DataFrame from a list of simple tuples, and can even choose the specific elements of the tuples you want to use. Here we will create a DataFrame using all of the data in each tuple except for the last element. import pandas as pd data = [ ('p1', 't1', 1, 2), ('p1', 't2', 3, 4)...
Component code: angular.module('myModule', []).component('myComponent', { bindings: { myValue: '<' }, controller: function(MyService) { this.service = MyService; this.componentMethod = function() { return 2; }; } }); The test: describe('myComponent', f...
By default, all types in TypeScript allow null: function getId(x: Element) { return x.id; } getId(null); // TypeScript does not complain, but this is a runtime error. TypeScript 2.0 adds support for strict null checks. If you set --strictNullChecks when running tsc (or set this flag in you...
if ([object respondsToSelector:@selector(someOptionalMethodInProtocol:)]) { [object someOptionalMethodInProtocol:argument]; }
Move Blue to the beginning of the array: NSMutableArray *myColors = [NSMutableArray arrayWithObjects: @"Red", @"Green", @"Blue", @"Yellow", nil]; NSUInteger fromIndex = 2; NSUInteger toIndex = 0; id blue = [[[self.array objectAtIndex:fromIndex] retain]...
You can define scripts that can be executed or are triggered before or after another script. { "scripts": { "pretest": "scripts/pretest.js", "test": "scripts/test.js", "posttest": "scripts/posttest.js" } } ...
The dynamic keyword is used with dynamically typed objects. Objects declared as dynamic forego compile-time static checks, and are instead evaluated at runtime. using System; using System.Dynamic; dynamic info = new ExpandoObject(); info.Id = 123; info.Another = 456; Console.WriteLine(info...
Oracle's CONNECT BY functionality provides many useful and nontrivial features that are not built-in when using SQL standard recursive CTEs. This example replicates these features (with a few additions for sake of completeness), using SQL Server syntax. It is most useful for Oracle developers findin...
Deleting files The unlink function deletes a single file and returns whether the operation was successful. $filename = '/path/to/file.txt'; if (file_exists($filename)) { $success = unlink($filename); if (!$success) { throw new Exception("Cannot delete $filename&qu...
An implicit conversion allows the compiler to automatically convert an object of one type to another type. This allows the code to treat an object as an object of another type. case class Foo(i: Int) // without the implicit Foo(40) + 2 // compilation-error (type mismatch) // defines how t...

Page 130 of 826