When assigning named methods to delegates, they will refer to the same underlying object if:
They are the same instance method, on the same instance of a class
They are the same static method on a class
public class Greeter
{
public void WriteInstance()
{
Console.Write...
The System namespace contains Func<..., TResult> delegate types with between 0 and 15 generic parameters, returning type TResult.
private void UseFunc(Func<string> func)
{
string output = func(); // Func with a single generic type parameter returns that type
Console.WriteLine...
Closures in Python are created by function calls. Here, the call to makeInc creates a binding for x that is referenced inside the function inc. Each call to makeInc creates a new instance of this function, but each instance has a link to a different binding of x.
def makeInc(x):
def inc(y):
...
One of the things that can really boost your productivity while writing the code is effectively navigating the workspace. This also means making it comfortable for the moment. It's possible to achieve this by adjusting which areas of workspaces you see.
The buttons on the top of the navigation and ...
/**
* Enables output buffer streaming. Calling this function
* immediately flushes the buffer to the client, and any
* subsequent output will be sent directly to the client.
*/
function _stream() {
ob_implicit_flush(true);
ob_end_flush();
}
When in a loop, the loop variable (val) in the following example is a single variable that changes value as it goes over the loop. Therefore one must do the following to actually pass each val of values to the goroutine:
for val := range values {
go func(val interface{}) {
fmt.Println...
m := make(map[string][]int)
Accessing a non-existent key will return a nil slice as a value. Since nil slices act like zero length slices when used with append or other built-in functions you do not normally need to check to see if a key exists:
// m["key1"] == nil && len(m[&qu...
Relative positioning moves the element in relation to where it would have been in normal flow .Offset properties:
top
left
right
bottom
are used to indicate how far to move the element from where it would have been in normal flow.
.relpos{
position:relative;
top:20px;
left:3...
Let's create our own error type for this example.
2.2
enum CustomError: ErrorType {
case SomeError
case AnotherError
}
func throwing() throws {
throw CustomError.SomeError
}
3.0
enum CustomError: Error {
case someError
case anotherError
}
func throwing() thr...
If you are using the default bash prompt on Linux, you should see the name of the virtual environment at the start of your prompt.
(my-project-env) user@hostname:~$ which python
/home/user/my-project-env/bin/python
To help to maintain clean code, Rails follows the principle of DRY.
It involves whenever possible, re-using as much code as possible rather than duplicating similar code in multiple places (for example, using partials). This reduces errors, keeps your code clean and enforces the principle of writin...
By default, the various Collection types are not thread-safe.
However, it's fairly easy to make a collection thread-safe.
List<String> threadSafeList = Collections.synchronizedList(new ArrayList<String>());
Set<String> threadSafeSet = Collections.synchronizedSet(new HashSet<S...
Given the following history, imagine you make a change that you want to squash into the commit bbb2222 A second commit:
$ git log --oneline --decorate
ccc3333 (HEAD -> master) A third commit
bbb2222 A second commit
aaa1111 A first commit
9999999 Initial commit
Once you've made your change...
The default value for an enum is zero. If an enum does not define an item with a value of zero, its default value will be zero.
public class Program
{
enum EnumExample
{
one = 1,
two = 2
}
public void Main()
{
var e =...
Now that the routes are set up, we need some way to actually change routes.
This example will show how to change routes using the template, but it is possible to change routes in TypeScript.
Here is one example (without binding):
<a routerLink="/home">Home</a>
If the user...
docker rm can be used to remove a specific containers like this:
docker rm <container name or id>
To remove all containers you can use this expression:
docker rm $(docker ps -qa)
By default docker will not delete a container that is running. Any container that is running will produce a...
execute the following command to insert the text into a view with a focus (if it supports text input)
6.0
Send text on SDK 23+
adb shell "input keyboard text 'Paste text on Android Device'"
If already connected to your device via adb:
input text 'Paste text on Android Device'
6...