Tutorial by Examples: c

String#squish Returns a version of the given string without leading or trailing whitespace, and combines all consecutive whitespace in the interior to single spaces. Destructive version squish! operates directly on the string instance. Handles both ASCII and Unicode whitespace. %{ Multi-line ...
String#pluralize Returns of plural form of the string. Optionally takes a count parameter and returns singular form if count == 1. Also accepts a locale parameter for language-specific pluralization. 'post'.pluralize # => "posts" 'octopus'.pluralize # => &quot...
When this program #include <stdio.h> #include <string.h> int main(void) { int num = 0; char str[128], *lf; scanf("%d", &num); fgets(str, sizeof(str), stdin); if ((lf = strchr(str, '\n')) != NULL) *lf = '\0'; printf("%d \"%s\&...
Asset Packages (with the file format of .unitypackage) are a commonly used way of distributing Unity projects to other users. When working with peripherals that have their own SDKs (eg. Oculus), you may be asked to download and import one of these packages. Importing a .unitypackage To import a pa...
Say you want to add a foreign key company_id to the users table, and you want to have a NOT NULL constraint on it. If you already have data in users, you will have to do this in multiple steps. class AddCompanyIdToUsers < ActiveRecord::Migration def up # add the column with NULL allowed ...
Depending on the version of Chart.JS you are using (the current one being 2.X), the syntax is different to create a minimal example of a bar chart (JSFiddle Demo for 2.X). Chart.js 2.X <html> <body> <canvas id="myChart" width="400" height="400&...
const foobar = `foo bar` encoding := base64.StdEncoding encodedFooBar := make([]byte, encoding.EncodedLen(len(foobar))) encoding.Encode(encodedFooBar, []byte(foobar)) fmt.Printf("%s", encodedFooBar) // Output: Zm9vIGJhcg== Playground
str := base64.StdEncoding.EncodeToString([]byte(`foo bar`)) fmt.Println(str) // Output: Zm9vIGJhcg== Playground
encoding := base64.StdEncoding data := []byte(`Zm9vIGJhcg==`) decoded := make([]byte, encoding.DecodedLen(len(data))) n, err := encoding.Decode(decoded, data) if err != nil { log.Fatal(err) } // Because we don't know the length of the data that is encoded // (only the max length), we n...
decoded, err := base64.StdEncoding.DecodeString(`biws`) if err != nil { log.Fatal(err) } fmt.Printf("%s", decoded) // Output: n,, Playground
Anything that needs to happen with data in an IndexedDB database happens in a transaction. There are a few things to note about transactions that are mentioned in the Remarks section at the bottom of this page. We'll use the database we set up in Opening a database. // Create a new readwrite (sinc...
Create a new project dotnet new -l f# Restore any packages listed in project.json dotnet restore A project.lock.json file should be written out. Execute the program dotnet run The above will compile the code if required. The output of the default project created by dotnet new -l f# con...
Espresso by default has many matchers that help you find views that you need to do some checks or interactions with them. Most important ones can be found in the following cheat sheet: https://google.github.io/android-testing-support-library/docs/espresso/cheatsheet/ Some examples of matchers are...
Activity class takes care of creating a window for you in which you can place your UI with setContentView. There are three setContentView methods: setContentView(int layoutResID) - Set the activity content from a layout resource. setContentView(View view) - Set the activity content to an explic...
There are two Collections.sort() methods: One that takes a List<T> as a parameter where T must implement Comparable and override the compareTo() method that determines sort order. One that takes a List and a Comparator as the arguments, where the Comparator determines the sort order. ...
Instead of adding an observer with a selector, a block can be used: id testObserver = [[NSNotificationCenter defaultCenter] addObserverForName:@"TestNotification" object:nil ...
Think this could example could be better but you get the gist import numpy as np from scipy.optimize import _minimize from scipy import special import matplotlib.pyplot as plt from matplotlib import cm from numpy.random import randn x, y = np.mgrid[-2:2:100j, -2:2:100j] plt.pcolor(x, y, op...
Creating a Window with OpenGL context (extension loading through GLEW): #define GLEW_STATIC #include <GL/glew.h> #include <SDL2/SDL.h> int main(int argc, char* argv[]) { SDL_Init(SDL_INIT_VIDEO); /* Initialises Video Subsystem in SDL */ /* Setting up OpenGL version a...
Create User Model # Schema: User(token:string, auth_token:string) class User < ActiveRecord::Base has_secure_token has_secure_token :auth_token end Now when you create a new user a token and auth_token are automatically generated user = User.new user.save user.token # => "p...
$username = 'Hadibut'; $email = '[email protected]'; $variables = compact('username', 'email'); // $variables is now ['username' => 'Hadibut', 'email' => '[email protected]'] This method is often used in frameworks to pass an array of variables between two components.

Page 377 of 826