Tutorial by Examples: am

The delete built-in function removes the element with the specified key from a map. people := map[string]int{"john": 30, "jane": 29} fmt.Println(people) // map[john:30 jane:29] delete(people, "john") fmt.Println(people) // map[jane:29] If the map is nil or ther...
params allows a method parameter to receive a variable number of arguments, i.e. zero, one or multiple arguments are allowed for that parameter. static int AddAll(params int[] numbers) { int total = 0; foreach (int number in numbers) { total += number; } ret...
Given the flavors, the named capture group may looks like this: (?'name'X) (?<name>X) (?P<name>X) With X being the pattern you want to capture. Let's consider the following string: Once upon a time there was a pretty little girl... Once upon a time there was a unicorn with an h...
As you may (or not) know, you can reference a capture group with: $1 1 being the group number. In the same way, you can reference a named capture group with: ${name} \{name} g\{name} Let's take the preceding example and replace the matches with The hero of the story is a ${subject}. T...
To parse lots of parameters, the prefered way of doing this is using a while loop, a case statement, and shift. shift is used to pop the first parameter in the series, making what used to be $2, now be $1. This is useful for processing arguments one at a time. #!/bin/bash # Load the user define...
Assuming the following Person class: public class Person { public string Name { get; set; } public int Age { get; set; } } The following lambda: p => p.Age > 18 Can be passed as an argument to both methods: public void AsFunc(Func<Person, bool> func) public void AsE...
dynamic foo = 123; Console.WriteLine(foo + 234); // 357 Console.WriteLine(foo.ToUpper()) // RuntimeBinderException, since int doesn't have a ToUpper method foo = "123"; Console.WriteLine(foo + 234); // 123234 Console.WriteLine(foo.ToUpper()): // NOW A STRING
using System; public static void Main() { var value = GetValue(); Console.WriteLine(value); // dynamics are useful! } private static dynamic GetValue() { return "dynamics are useful!"; }
using System; using System.Dynamic; dynamic info = new ExpandoObject(); info.Id = 123; info.Another = 456; Console.WriteLine(info.Another); // 456 Console.WriteLine(info.DoesntExist); // Throws RuntimeBinderException
Anonymous types allow the creation of objects without having to explicitly define their types ahead of time, while maintaining static type checking. var anon = new { Value = 1 }; Console.WriteLine(anon.Id); // compile time error Conversely, dynamic has dynamic type checking, opting for runtime ...
If you have cloned a fork (e.g. an open source project on Github) you may not have push access to the upstream repository, so you need both your fork but be able to fetch the upstream repository. First check the remote names: $ git remote -v origin https://github.com/myusername/repo.git (fetch...
The typeof operator works on type parameters. class NameGetter<T> { public string GetTypeName() { return typeof(T).Name; } }
The accessibility frame is used by VoiceOver for hit testing touches, drawing the VoiceOver cursor, and calculating where in the focused element to simulate a tap when the user double-taps the screen. Note that the frame is in screen coordinates! myElement.accessibilityFrame = frameInScreenCoordina...
div { font-size: 7px; border: 3px dotted pink; background-color: yellow; color: purple; } body.mystyle > div.myotherstyle { font-size: 11px; background-color: green; } #elmnt1 { font-size: 24px; border-color: red; } .mystyle .myotherstyle { ...
SQL injection is a kind of attack that allows a malicious user to modify the SQL query, adding unwanted commands to it. For example, the following code is vulnerable: // Do not use this vulnerable code! $sql = 'SELECT name, email, user_level FROM users WHERE userID = ' . $_GET['user']; $conn->...
The return type of a method can depend on the type of the parameter. In this example, x is the parameter, A is the type of x, which is known as the type parameter. def f[A](x: A): A = x f(1) // 1 f("two") // "two" f[Float](3) // 3.0F Scala will use type infe...
Any Chrome extension starts as an unpacked extension: a folder containing the extension's files. One file it must contain is manifest.json, which describes the basic properties of the extension. Many of the properties in that file are optional, but here is an absolute minimum manifest.json file: ...
Rename the branch you have checked out: git branch -m new_branch_name Rename another branch: git branch -m branch_you_want_to_rename new_branch_name
Boilerplate code example override func viewDidLoad() { super.viewDidLoad() let myView = UIView() myView.backgroundColor = UIColor.blueColor() myView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(myView) // Add constraints code here // ... ...
Java SE 8 Converting an array of objects to Stream: String[] arr = new String[] {"str1", "str2", "str3"}; Stream<String> stream = Arrays.stream(arr); Converting an array of primitives to Stream using Arrays.stream() will transform the array to a primitive sp...

Page 9 of 129