Tutorial by Examples: ast

C++11 Basic example: template<typename T> using pointer = T*; This definition makes pointer<T> an alias of T*. For example: pointer<int> p = new int; // equivalent to: int* p = new int; Alias templates cannot be specialized. However, that functionality can be obtained indi...
Cryptography is something very hard and after spending a lot of time reading different examples and seeing how easy it is to introduce some form of vulnerability I found an answer originally written by @jbtule that I think is very good. Enjoy reading: "The general best practice for symmetric e...
The macro WITH-OUTPUT-TO-STRING can be used to create a string output stream, and return the resulting string at the end. (with-output-to-string (str) (write-line "Foobar!" str) (write-string "Barfoo!" str)) ;=> "Foobar! ; Barfoo!" The same can be done ...
JsonReader reads a JSON encoded value as a stream of tokens. public List<Message> readJsonStream(InputStream in) throws IOException { JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8")); try { return readMessagesArray(reader); } finall...
Split Function returns a zero-based, one dimensional array containing a specified number of substrings. Syntax Split(expression [, delimiter [, limit [, compare]]]) PartDescriptionexpressionRequired. String expression containing substrings and delimiters. If expression is a zero-length string(&q...
A variable can be downcasted to a subtype using the type cast operators as?, and as!. The as? operator attempts to cast to a subtype. It can fail, therefore it returns an optional. let value: Any = "John" let name = value as? String print(name) // prints Optional("John") ...
The switch statement can also be used to attempt casting into different types: func checkType(_ value: Any) -> String { switch value { // The `is` operator can be used to check a type case is Double: return "value is a Double" // The `as` operator will ...
Schema Statics are methods that can be invoked directly by a Model (unlike Schema Methods, which need to be invoked by an instance of a Mongoose document). You assign a Static to a schema by adding the function to the schema's statics object. One example use case is for constructing custom queries:...
(Copy an item and send the copies to every block that it’s linked to) Unlike BufferBlock, BroadcastBlock’s mission in life is to enable all targets linked from the block to get a copy of every element published, continually overwriting the “current” value with those propagated to it. Additionally,...
std::ifstream f("file.txt"); if (f) { std::stringstream buffer; buffer << f.rdbuf(); f.close(); // The content of "file.txt" is available in the string `buffer.str()` } The rdbuf() method returns a pointer to a streambuf that can be pushed into buffer...
Most times when people have to reverse a string, they do it more or less like this: char[] a = s.ToCharArray(); System.Array.Reverse(a); string r = new string(a); However, what these people don't realize is that this is actually wrong. And I don't mean because of the missing NULL check. It ...
It's possible to send broadcast to BroadcastReceiver with adb. In this example we are sending broadcast with action com.test.app.ACTION and string extra in bundle 'foo'='bar': adb shell am broadcast -a action com.test.app.ACTION --es foo "bar" You can put any other supported type to b...
Having your scripts call Raycast directly may lead to problems if you need to change the collision matrices in the future, as you'll have to track down every LayerMask field to accommodate the changes. Depending on the size of your project, this may become a huge undertaking. Encapsulating Raycast ...
WITH cte AS ( SELECT ProjectID, ROW_NUMBER() OVER (PARTITION BY ProjectID ORDER BY InsertDate DESC) AS rn FROM ProjectNotes ) DELETE FROM cte WHERE rn > 1;
A string can reversed using the built-in reversed() function, which takes a string and returns an iterator in reverse order. >>> reversed('hello') <reversed object at 0x0000000000000000> >>> [char for char in reversed('hello')] ['o', 'l', 'l', 'e', 'h'] reversed() can ...
A pointer to a const object can be converted to a pointer to non-const object using the const_cast keyword. Here we use const_cast to call a function that is not const-correct. It only accepts a non-const char* argument even though it never writes through the pointer: void bad_strlen(char*); const...
If you are using multiple namespaces that may have same-name classes(such as System.Random and UnityEngine.Random), you can use an alias to specify that Random comes from one or the other without having to use the entire namespace in the call. For instance: using UnityEngine; using System; Ran...
BroadcastReceivers are used to receive broadcast Intents that are sent by the Android OS, other apps, or within the same app. Each Intent is created with an Intent Filter, which requires a String action. Additional information can be configured in the Intent. Likewise, BroadcastReceivers register ...
Elasticsearch uses a YAML (Yet Another Markup Language) configuration file that can be found inside the default Elasticsearch directory (RPM and DEB installs change this location amongst other things). You can set basic settings in config/elasticsearch.yml: # Change the cluster name. All nodes in ...
import std.stdio; struct A { int b; void c(); string d; }; void main() { // The following foreach is unrolled in compile time foreach(name; __traits(allMembers, A)) { pragma(msg, name); } } The allMembers traits returns a tuple of string containing t...

Page 10 of 26