Tutorial by Examples: context

The following is a simple example of using the strategy pattern without a context class. There are two implementation strategies which implement the interface and solve the same problem in different ways. Users of the EnglishTranslation class can call the translate method and choose which strategy t...
1.7+ Timing out an HTTP request with a context can be accomplished with only the standard library (not the subrepos) in 1.7+: import ( "context" "net/http" "time" ) req, err := http.NewRequest("GET", `https://example.net`, nil) ctx, _ := ...
There are several scopes that are available only in a web-aware application context: request - new bean instance is created per HTTP request session - new bean instance is created per HTTP session application - new bean instance is created per ServletContext globalSession - new bean instance i...
Static variables and methods are not part of an instance, There will always be a single copy of that variable no matter how many objects you create of a particular class. For example you might want to have an immutable list of constants, it would be a good idea to keep it static and initialize it j...
While server side-code can run with elevated privileges, there is not an equivalent method to elevate privileges in client-side code (for obvious security reasons). As an alternative, you can specify credentials to emulate the access of a specific user or service account. To specify credentials, bu...
In order to create a hotkey or hotstring that only triggers when certain windows are active or exist, you can put one or several of the following directives before the hotkey definition: #IfWinActive [, WinTitle, WinText] #IfWinExist [, WinTitle, WinText] #IfWinNotActive [, WinTitle, WinText] #I...
Another way, which is very readable and elegant, but far less efficient than a if/else structure, is to build a class such as follows, that will read and store the value to compare with, expose itself within the context as a callable that will return true if it matches the stored value: class Switc...
When you need to pass some data from the parent task to its children tasks, so it logically flows with the execution, use AsyncLocal class: void Main() { AsyncLocal<string> user = new AsyncLocal<string>(); user.Value = "initial user"; // this does not aff...
Creating a Window with OpenGL context (extension loading through GLEW): #define GLEW_STATIC #include <GL/glew.h> #include <SDL2/SDL.h> int main(int argc, char* argv[]) { SDL_Init(SDL_INIT_VIDEO); /* Initialises Video Subsystem in SDL */ /* Setting up OpenGL version a...
trigger ContactTrigger on Contact (before insert, after insert, before update, after update, before delete, after delete, after undelete) { /** Before or After trigger execution**/ /...
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context Context is important if you ship your class for others to use.Context lets your class observer verify that its you observer which is being called. The ...
In this example every positioned element creates its own stacking context, because of their positioning and z-index values. The hierarchy of stacking contexts is organized as follows: Root DIV #1 DIV #2 DIV #3 DIV #4 DIV #5 DIV #6 It is important to note that DIV #4, DIV #5 and D...
Using the overflow property with a value different to visible will create a new block formatting context. This is useful for aligning a block element next to a floated element. CSS img { float:left; margin-right: 10px; } div { overflow:hidden; /* creates block formatting context...
Many bugs in knockout data binds are caused by undefined properties in a viewmodel. Knockout has two handy methods to retrieve the binding context of an HTML element: // Returns the binding context to which an HTMLElement is bound ko.contextFor(element); // Returns the viewmodel to which ...
Setup Spark context in R To start working with Sparks distributed dataframes, you must connect your R program with an existing Spark Cluster. library(SparkR) sc <- sparkR.init() # connection to Spark context sqlContext <- sparkRSQL.init(sc) # connection to SQL context Here are infos how...
The clauses in a SELECT have a specific order: SELECT ... FROM ... WHERE ... GROUP BY ... HAVING ... ORDER BY ... -- goes here LIMIT ... OFFSET ...; ( SELECT ... ) UNION ( SELECT ... ) ORDER BY ... -- for ordering the result of the UNION. SELECT ... GROUP_CONCAT(DISTINCT x ORDER B...
Html5 Canvas gives you the ability to fetch and change the color of any pixel on the canvas. You can use Canvas's pixel manipulation to: Create a color-picker for an image or select a color on a color-wheel. Create complex image filters like blurring and edge detection. Recolor any part of an ...
If you have code (a routine) you want to execute under a specific (constraint) context, you can use dependency injection. The following example shows the constraint of executing under an open SSL connection. This first part would be in your library or framework, which you won't expose to the client...
The per-directory context is a part of the static configuration file between <Directory> and </Directory> tags. The entire content of dynamic configuration files is within the per-directory context of the folder in which the .htaccess resides. RewriteRule's in per-directory context matc...
The virtual host context is a part of the static configuration file between <VirtualHost> and </VirtualHost> tags. RewriteRule's in virtual host context match against the part of an url after the protocol, hostname and port, and before the query string. When the following rule is used ...

Page 2 of 4