Tutorial by Examples

' This method is useful for iterating Enum values ' Enum Animal Dog = 1 Cat = 2 Frog = 4 End Enum Dim Animals = [Enum].GetValues(GetType(Animal)) For Each animal in Animals Console.WriteLine(animal) Next Prints: 1 2 4
using (new Sitecore.SecurityModel.SecurityDisabler()) { var item = Sitecore.Context.Database.GetItem("/sitecore/content/home"); }
var user = Sitecore.Security.Accounts.User.FromName("sitecore/testname", false); using (new Sitecore.Security.Accounts.UserSwitcher(user)) { var item = Sitecore.Context.Database.GetItem("/sitecore/content/home"); }
NSError *e = nil; NSString *jsonString = @"[{\"id\": \"1\", \"name\":\"sam\"}]"; NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingMutabl...
Just like in case of the function arguments, template parameters can have their default values. All template parameters with a default value have to be declared at the end of the template parameter list. The basic idea is that the template parameters with default value can be omitted while template ...
Useful if your program is outputting web pages along the way. from http.server import HTTPServer, CGIHTTPRequestHandler import webbrowser import threading def start_server(path, port=8000): '''Start a simple webserver serving path on port''' os.chdir(path) httpd = HTTPServer((''...
When you create an argparse ArgumentParser() and run your program with '-h' you get an automated usage message explaining what arguments you can run your software with. By default, positional arguments and conditional arguments are separated into two categories, for example, here is a small script ...
The main app file loads the routes file where routes are defined. app.js var express = require('express'); var app = express(); app.use('/', require('./routes')); app.listen('3000'); routes.js var router = require('express').Router(); router.get('/', function(req, res) { res.sen...
Middleware is executed prior to the route execution and can decide whether to execute the router according to the URL. var router = require('express').Router(); router.use(function (req, res, next) { var weekDay = new Date().getDay(); if (weekDay === 0) { res.send('Web is clos...
Use associated type when there is a one-to-one relationship between the type implementing the trait and the associated type. It is sometimes also known as the output type, since this is an item given to a type when we apply a trait to it. Creation trait GetItems { type First; // ^~~~ d...
Rust's #[path] attribute can be used to specify the path to search for a particular module if it is not in the standard location. This is typically discouraged, however, because it makes the module hierarchy fragile and makes it easy to break the build by moving a file in a completely different dire...
Say you have implemented some logic to detect attempts to modify an object in the database while the client that submitted changes didn't have the latest modifications. If such case happens, you raise a custom exception ConfictError(detailed_message). Now you want to return an HTTP 409 (Confict) st...
Use the maxlen parameter while creating a deque to limit the size of the deque: from collections import deque d = deque(maxlen=3) # only holds 3 items d.append(1) # deque([1]) d.append(2) # deque([1, 2]) d.append(3) # deque([1, 2, 3]) d.append(4) # deque([2, 3, 4]) (1 is removed because i...
Creating empty deque: dl = deque() # deque([]) creating empty deque Creating deque with some elements: dl = deque([1, 2, 3, 4]) # deque([1, 2, 3, 4]) Adding element to deque: dl.append(5) # deque([1, 2, 3, 4, 5]) Adding element left side of deque: dl.appendleft(0) # deque([0, 1, 2, ...
A basic User Schema: var mongoose = require('mongoose'); var userSchema = new mongoose.Schema({ name: String, password: String, age: Number, created: {type: Date, default: Date.now} }); var User = mongoose.model('User', userSchema); Schema Types.
Methods can be set on Schemas to help doing things related to that schema(s), and keeping them well organized. userSchema.methods.normalize = function() { this.name = this.name.toLowerCase(); }; Example usage: erik = new User({ 'name': 'Erik', 'password': 'pass' }); erik.nor...
Often times you will see an exception Anti forgery token is meant for user "" but the current user is "username" This is because the Anti-Forgery token is also linked to the current logged-in user. This error appears when a user logs in but their token is still linked to bein...
String to a primitive numeric type or a numeric wrapper type: Each numeric wrapper class provides a parseXxx method that converts a String to the corresponding primitive type. The following code converts a String to an int using the Integer.parseInt method: String string = "59"; int p...
Haxe is available on Windows, Linux, and OS X. It is distributed in two forms: as an installer, providing an optional Neko VM dependency and configuring haxe and haxelib environment variables; as binaries, providing only the Haxe compiler and package manager. Windows Installer and binaries a...
The tile pane layout is similar to the FlowPane layout. TilePane places all of the nodes in a grid in which each cell, or tile, is the same size. It arranges nodes in neat rows and columns, either horizontally or vertically. import javafx.application.Application; import javafx.scene.Scene;...

Page 324 of 1336