Tutorial by Examples: ast

Prerequisites The Windows version of Elasticsearch can be obtained from this link: https://www.elastic.co/downloads/elasticsearch. The latest stable release is always at the top. As we are installing on Windows, we need the .ZIP archive. Click the link in the Downloads: section and save the file t...
The .split() method splits a string into an array of substrings. By default .split() will break the string into substrings on spaces (" "), which is equivalent to calling .split(" "). The parameter passed to .split() specifies the character, or the regular expression, to use for...
import java.nio.charset.StandardCharsets; import java.util.Arrays; public class GetUtf8BytesFromString { public static void main(String[] args) { String str = "Cyrillic symbol Ы"; //StandardCharsets is available since Java 1.7 //for ealier version use ...
Suppose you have types like the following: interface IThing { } class Thing : IThing { } LINQ allows you to create a projection that changes the compile-time generic type of an IEnumerable<> via the Enumerable.Cast<>() and Enumerable.OfType<>() extension methods. IEnumerabl...
Array.join(separator) can be used to output an array as a string, with a configurable separator. Default (separator = ","): ["a", "b", "c"].join() === "a,b,c" With a string separator: [1, 2, 3, 4].join(" + ") === "1 + 2 + 3 + 4&q...
Occasionally you may want to use the same tuple type in multiple places throughout your code. This can quickly get messy, especially if your tuple is complex: // Define a circle tuple by its center point and radius let unitCircle: (center: (x: CGFloat, y: CGFloat), radius: CGFloat) = ((0.0, 0.0), ...
You can call memset to zero out a string (or any other memory block). Where str is the string to zero out, and n is the number of bytes in the string. #include <stdlib.h> /* For EXIT_SUCCESS */ #include <stdio.h> #include <string.h> int main(void) { char str[42] = &quo...
Type casting is done with either the as operator: var chair:Chair = furniture as Chair; Or by wrapping the value in Type(): var chair:Chair = Chair(furniture); If the cast fails with as, the result of that cast is null. If the cast fails by wrapping in Type(), a TypeError is thrown.
This function casts a ray from point origin in direction direction of length maxDistance against all colliders in the scene. The function takes in the origin direction maxDistance and calculate if there is a collider in front of the GameObject. Physics.Raycast(origin, direction, maxDistance); F...
Rails have very easy way to get first and last record from database. To get the first record from users table we need to type following command: User.first It will generate following sql query: SELECT `users`.* FROM `users` ORDER BY `users`.`id` ASC LIMIT 1 And will return following recor...
public class MainApplication extends Application { private static Context context; //application context private Handler mainThreadHandler; private Toast toast; public Handler getMainThreadHandler() { if (mainThreadHandler == null) { mainThreadHand...
Arithmetic operations are performed elementwise on Numpy arrays. For arrays of identical shape, this means that the operation is executed between elements at corresponding indices. # Create two arrays of the same size a = np.arange(6).reshape(2, 3) b = np.ones(6).reshape(2, 3) a # array([0, 1...
string str = "this--is--a--complete--sentence"; string[] tokens = str.Split(new[] { "--" }, StringSplitOptions.None); Result: [ "this", "is", "a", "complete", "sentence" ]
The .indexOf method returns the index of a substring inside another string (if exists, or -1 if otherwise) 'Hellow World'.indexOf('Wor'); // 7 .indexOf also accepts an additional numeric argument that indicates on what index should the function start looking "harr dee harr dee harr&quot...
To create a human-readable presentation of a model object you need to implement Model.__str__() method (or Model.__unicode__() on python2). This method will be called whenever you call str() on a instance of your model (including, for instance, when the model is used in a template). Here's an exampl...
The trim() method returns a new String with the leading and trailing whitespace removed. String s = new String(" Hello World!! "); String t = s.trim(); // t = "Hello World!!" If you trim a String that doesn't have any whitespace to remove, you will be returned the same S...
You can use raycasts to check if an ai can walk without falling off the edge of a level. using UnityEngine; public class Physics2dRaycast: MonoBehaviour { public LayerMask LineOfSightMask; void FixedUpdate() { RaycastHit2D hit = Physics2D.Raycas...
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; With an Identifier: Give the scene a Storyboard ID within the identity inspector of the storyboard. Instantiate in code: UIViewController *controller = [storyboard instantiateViewControllerWithIdentifi...
Catamorphisms, or folds, model primitive recursion. cata tears down a fixpoint layer by layer, using an algebra function (or folding function) to process each layer. cata requires a Functor instance for the template type f. cata :: Functor f => (f a -> a) -> Fix f -> a cata f = f . fma...
Anamorphisms, or unfolds, model primitive corecursion. ana builds up a fixpoint layer by layer, using a coalgebra function (or unfolding function) to produce each new layer. ana requires a Functor instance for the template type f. ana :: Functor f => (a -> f a) -> a -> Fix f ana f = Fi...

Page 9 of 26