Tutorial by Examples: o

Declaration annotations should be put on a separate line from the declaration being annotated. @SuppressWarnings("unchecked") public T[] toArray(T[] typeHolder) { ... } However, few or short annotations annotating a single-line method may be put on the same line as the method if...
Runnable r = () -> System.out.println("Hello World"); Supplier<String> c = () -> "Hello World"; // Collection::contains is a simple unary method and its behavior is // clear from the context. A method reference is preferred here. appendFilter(goodStrings::cont...
In this example, a function map named funcMap is supplied to the template via the Funcs() method and then invoked inside the template. Here, the function increment() is used to get around the lack of a less than or equal function in the templating language. Note in the output how the final item in t...
First, here's what can happen when text/template is used for HTML. Note Harry's FirstName property). package main import ( "fmt" "html/template" "os" ) type Person struct { FirstName string LastName string Street string Cit...
Using regular recursion, each recursive call pushes another entry onto the call stack. When the recursion is completed, the application has to pop each entry off all the way back down. If there are much recursive function calls it can end up with a huge stack. Scala automatically removes the recurs...
Methods in Go are just like functions, except they have receiver. Usually receiver is some kind of struct or type. package main import ( "fmt" ) type Employee struct { Name string Age int Rank int } func (empl *Employee) Promote() { empl.Rank++ } ...
With methods in golang you can do method "chaining" passing pointer to method and returning pointer to the same struct like this: package main import ( "fmt" ) type Employee struct { Name string Age int Rank int } func (empl *Employee) Promote() *...
It is possible to specify log destination with something that statisfies io.Writer interface. With that we can log to file: package main import ( "log" "os" ) func main() { logfile, err := os.OpenFile("test.log", os.O_RDWR|os.O_CREATE|os.O_APPEND,...
It is also possible to log to syslog with log/syslog like this: package main import ( "log" "log/syslog" ) func main() { syslogger, err := syslog.New(syslog.LOG_INFO, "syslog_example") if err != nil { log.Fatalln(err) } l...
context.lineJoin=joinStyle // miter (default), round, bevel Sets the style used to connect adjoining line segments. miter, the default, joins line segments with a sharp joint. round, joins line segments with a rounded joint. bevel, joins line segments with a blunted joint. <!doctype...
context.strokeStyle=color Sets the color that will be used to stroke the outline of the current path. These are color options (these must be quoted): A CSS named color, for example context.strokeStyle='red' A hex color, for example context.strokeStyle='#FF0000' An RGB color, for e...
shadowColor = color // CSS color shadowBlur = width // integer blur width shadowOffsetX = distance // shadow is moved horizontally by this offset shadowOffsetY = distance // shadow is moved vertically by this offset This set of attributes will add a shadow around a path. Bo...
var gradient = createLinearGradient( startX, startY, endX, endY ) gradient.addColorStop(gradientPercentPosition, CssColor) gradient.addColorStop(gradientPercentPosition, CssColor) [optionally add more color stops to add to the variety of the gradient] Creates a reusable linear gradient (object...
var gradient = createRadialGradient( centerX1, centerY1, radius1, // this is the "display' circle centerX2, centerY2, radius2 // this is the "light casting" circle ) gradient.addColorStop(gradientPercentPosition, CssColor) gradient.addColorStop(gradientPerce...
JavaScript supports several types of group in it's Regular Expressions, capture groups, non-capture groups and look-aheads. Currently, there is no look-behind support. Capture Sometimes the desired match relies on it's context. This means a simple RegExp will over-find the piece of the String that...
Once you have setup and configured the php5-fpm and wordpress settings you can configure the /etc/nginx/conf/nginx.conf file as below. You need to define the location blocks inside the server block and rewrite the url there as defined. server { listen 443 ssl; server_name abc.co.uk; ...
for /L %%A in (1,2,40) do echo %%A This line will iterate from 1 to 39, increasing by 2 each time. The first parameter, 1, is the starting number. The second parameter, 2, is the increment. The third parameter, 40, is the maximum.
Use itertools.chain to create a single generator which will yield the values from several generators in sequence. from itertools import chain a = (x for x in ['1', '2', '3', '4']) b = (x for x in ['x', 'y', 'z']) ' '.join(chain(a, b)) Results in: '1 2 3 4 x y z' As an alternate constructo...
import std.stdio; T min(T)(in T arg1, in T arg2) { return arg1 < arg2 ? arg1 : arg2; } void main() { //Automatic type inference writeln(min(1, 2)); //Explicit type writeln(min!(ubyte)(1, 2)); //With single type, the parenthesis might be ommited ...
package main import ( "fmt" "net/http" "os" "text/template" ) var requestTemplate string = ` {{range $i, $url := .URLs}} {{ $url }} {{(status_code $url)}} {{ end }}` type Requests struct { URLs []string } func main() {...

Page 394 of 1038