Tutorial by Examples: pre

Placeholders in the query string need to be set by using the set* methods: String sql = "SELECT * FROM EMP WHERE JOB = ? AND SAL > ?"; //Create statement to make your operations PreparedStatement statement = connection.prepareStatement(sql); statement.setString(1, "MANAGER&...
Consider the following C# code Expression<Func<int, int>> expression = a => a + 1; Because the C# compiler sees that the lambda expression is assigned to an Expression type rather than a delegate type it generates an expression tree roughly equivalent to this code ParameterExpres...
You can test if a string matches several regular expressions using a switch statement. Example case "Ruby is #1!" when /\APython/ puts "Boooo." when /\ARuby/ puts "You are right." else puts "Sorry, I didn't understand that." end This w...
If-statements can be expressions: val str = if (condition) "Condition met!" else "Condition not met!" Note that the else-branch is not optional if the if-statement is used as an expression. This can also been done with a multi-line variant with curly brackets and multiple el...
Like if, when can also be used as an expression: val greeting = when (x) { "English" -> "How are you?" "German" -> "Wie geht es dir?" else -> "I don't know that language yet :(" } print(greeting) To be used as an express...
functions.php //Localize the AJAX URL and Nonce add_action('wp_enqueue_scripts', 'example_localize_ajax'); function example_localize_ajax(){ wp_localize_script('jquery', 'ajax', array( 'url' => admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('example_ajax_nonc...
main.go: package main import ( "fmt" "io/ioutil" "log" "net/http" ) func fetchContent(url string) (string, error) { res, err := http.Get(url) if err != nil { return "", nil } defer res.Body.Clo...
An element whose implicit native role semantics will not be mapped to the accessibility API. <div style="float:left;">Some content on the left.</div> <div style="float:right;">Some content on the right</div> <div role="presentation" style=&...
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 ...
When an expression contains multiple operators, it can potentially be read in different ways. For example, the mathematical expression 1 + 2 x 3 could be read in two ways: Add 1 and 2 and multiply the result by 3. This gives the answer 9. If we added parentheses, this would look like ( 1 + 2 )...
A simple context tree (containing some common values that might be request scoped and included in a context) built from Go code like the following: // Pseudo-Go ctx := context.WithValue( context.WithDeadline( context.WithValue(context.Background(), sidKey, sid), time.Now().A...
Haskell has list comprehensions, which are a lot like set comprehensions in math and similar implementations in imperative languages such as Python and JavaScript. At their most basic, list comprehensions take the following form. [ x | x <- someList ] For example [ x | x <- [1..4] ] -...
Before C++17, having pointers with a value of nullptr commonly represented the absence of a value. This is a good solution for large objects that have been dynamically allocated and are already managed by pointers. However, this solution does not work well for small or primitive types such as int, w...
Before C++17, a function typically represented failure in one of several ways: A null pointer was returned. e.g. Calling a function Delegate *App::get_delegate() on an App instance that did not have a delegate would return nullptr. This is a good solution for objects that have been dynamicall...
Some C implementations permit code to write to one member of a union type then read from another in order to perform a sort of reinterpreting cast (parsing the new type as the bit representation of the old one). It is important to note however, this is not permitted by the C standard current or pas...
// RawRepresentable has an associatedType RawValue. // For this struct, we will make the compiler infer the type // by implementing the rawValue variable with a type of String // // Compiler infers RawValue = String without needing typealias // struct NotificationName: RawRepresentable { ...
We define the type of boolean expressions whose atoms are identified by strings as type expr = | Atom of string | Not of expr | And of expr * expr | Or of expr * expr and can evaluate these expressions using an oracle : string -> bool giving the values of the atoms we find as follows: le...
It is considered good practice to use a prefix when creating git archives, so that extraction will place all files inside a directory. To create an archive of HEAD with a directory prefix: git archive --output=archive-HEAD.zip --prefix=src-directory-name HEAD When extracted all the files will be...
This hook is executed every time you run git commit, to verify what is about to be committed. You can use this hook to inspect the snapshot that is about to be committed. This type of hook is useful for running automated tests to make sure the incoming commit doesn't break existing functionality of...
This hook is called after the pre-commit hook to populate the text editor with a commit message. This is typically used to alter the automatically generated commit messages for squashed or merged commits. One to three arguments are passed to this hook: The name of a temporary file that contains ...

Page 9 of 34