Tutorial by Examples: ast

A standard toast notification appears at the bottom of the screen aligned in horizontal centre. You can change this position with the setGravity(int, int, int). This accepts three parameters: a Gravity constant, an x-position offset, and a y-position offset. For example, if you decide that the toas...
Objective-C NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:@"Your String here"]; [attributeString addAttribute:NSStrikethroughStyleAttributeName value:@2 range:NSMakeRange(0, [attributeString length...
Use .split to go from strings to an array of the split substrings: var s = "one, two, three, four, five" s.split(", "); // ["one", "two", "three", "four", "five"] Use the array method .join to go back to a string: s.split(&...
To detect whether a parameter is a primitive string, use typeof: var aString = "my string"; var anInt = 5; var anObj = {}; typeof aString === "string"; // true typeof anInt === "string"; // false typeof anObj === "string"; // false If you ev...
Arrays are objects, but their type is defined by the type of the contained objects. Therefore, one cannot just cast A[] to T[], but each A member of the specific A[] must be cast to a T object. Generic example: public static <T, A> T[] castArray(T[] target, A[] array) { for (int i = 0; i...
Let's say we have the following structure: struct MY_STRUCT { int my_int; float my_float; }; We can define MY_STRUCT to omit the struct keyword so we don't have to type struct MY_STRUCT each time we use it. This, however, is optional. typedef struct MY_STRUCT MY_STRUCT; If we th...
Token pasting allows one to glue together two macro arguments. For example, front##back yields frontback. A famous example is Win32's <TCHAR.H> header. In standard C, one can write L"string" to declare a wide character string. However, Windows API allows one to convert between wide c...
Stored procedures can be created through a database management GUI (SQL Server example), or through a SQL statement as follows: -- Define a name and parameters CREATE PROCEDURE Northwind.getEmployee @LastName nvarchar(50), @FirstName nvarchar(50) AS -- Define the query to be...
Broadcast variables are read only shared objects which can be created with SparkContext.broadcast method: val broadcastVariable = sc.broadcast(Array(1, 2, 3)) and read using value method: val someRDD = sc.parallelize(Array(1, 2, 3, 4)) someRDD.map( i => broadcastVariable.value.apply(...
In Android, a Toast is a simple UI element that can be used to give contextual feedback to a user. To display a simple Toast message, we can do the following. // Declare the parameters to use for the Toast Context context = getApplicationContext(); // in an Activity, you may also use "th...
If you don't want to use the default Toast view, you can provide your own using the setView(View) method on a Toast object. First, create the XML layout you would like to use in your Toast. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="...
This topic specifically talks about UTF-8 and considerations for using it with a database. If you want more information about using databases in PHP then checkout this topic. Storing Data in a MySQL Database: Specify the utf8mb4 character set on all tables and text columns in your database. ...
Using the timeit module from the command line: > python -m timeit 'for x in xrange(50000): b = x**3' 10 loops, best of 3: 51.2 msec per loop > python -m timeit 'from math import pow' 'for x in xrange(50000): b = pow(x,3)' 100 loops, best of 3: 9.15 msec per loop The built-in ** operato...
Given a String and a Character let text = "Hello World" let char: Character = "o" We can count the number of times the Character appears into the String using let sensitiveCount = text.characters.filter { $0 == char }.count // case-sensitive let insensitiveCount = text.low...
To convert a string to boolean use Boolean(myString) or the shorter but less clear form !!myString All strings except the empty string (of length zero) are evaluated to true as booleans. Boolean('') === false // is true Boolean("") === false // is true Boolean('0') === fals...
C++11 char *str = "hello world"; str[0] = 'H'; "hello world" is a string literal, so modifying it gives undefined behaviour. The initialisation of str in the above example was formally deprecated (scheduled for removal from a future version of the standard) in C++03. A num...
Let's say you need to implement an automatic search box, but the search operation is somewhat costly, like sending a web request or hitting up a database. You may want to limit the amount of search being done. For example, the user is typing "C# Reactive Extensions" in the search box : I...
2.2 func removeCharactersNotInSetFromText(text: String, set: Set<Character>) -> String { return String(text.characters.filter { set.contains( $0) }) } let text = "Swift 3.0 Come Out" var chars = Set([Character]("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLKMNOPQRSTUVWXYZ&...
Addition + and subtraction - operations can be used to combine delegate instances. The delegate contains a list of the assigned delegates. using System; using System.Reflection; using System.Reflection.Emit; namespace DelegatesExample { class MainClass { private delegate void MyD...
Analog to get a collection for a Stream by collect() an array can be obtained by the Stream.toArray() method: List<String> fruits = Arrays.asList("apple", "banana", "pear", "kiwi", "orange"); String[] filteredFruits = fruits.stream() ....

Page 6 of 26