SpriteKit functionality can be implemented in a subclass of SKScene. For example, a game may implement the main game functionality within an SKScene subclass called GameScene.
In Swift:
import SpriteKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
/* Co...
Chaining assignments as part of a var declaration will create global variables unintentionally.
For example:
(function foo() {
var a = b = 0;
})()
console.log('a: ' + a);
console.log('b: ' + b);
Will result in:
Uncaught ReferenceError: a is not defined
'b: 0'
In the above examp...
Character escaping is what allows certain characters (reserved by the regex engine for manipulating searches) to be literally searched for and found in the input string. Escaping depends on context, therefore this example does not cover string or delimiter escaping.
Backslashes
Saying that backsla...
The easiest and quickest way to encode a Haskell data type to JSON with Aeson is using generics.
{-# LANGUAGE DeriveGeneric #-}
import GHC.Generics
import Data.Text
import Data.Aeson
import Data.ByteString.Lazy
First let us create a data type Person:
data Person = Person { firstName :...
Sometimes you doesn't want to simply replace or remove the string. Sometimes you want to extract and process matches. Here an example of how you manipulate matches.
What is a match ? When a compatible substring is found for the entire regex in the string, the exec command produce a match. A match i...
Some regex engines (such as .NET) can handle context-free expressions, and will work it out. But that's not the case for most standard engines. And even if they do, you'll end up having a complex hard-to-read expression, whereas using a parsing library could make the job easier.
How to find all p...
If you want to extract something from a webpage (or any representation/programming language), a regex is the wrong tool for the task. You should instead use your language's libraries to achieve the task.
If you want to read HTML, or XML, or JSON, just use the library that parses it properly and ser...
By using the .HasKey() method, a property can be explicitly configured as primary key of the entity.
using System.Data.Entity;
// ..
public class PersonContext : DbContext
{
// ..
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// ..
...
By using the .HasKey() method, a set of properties can be explicitly configured as the composite primary key of the entity.
using System.Data.Entity;
// ..
public class PersonContext : DbContext
{
// ..
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{...
There are two common ways to encode a POST request body: URL encoding (application/x-www-form-urlencoded) and form data (multipart/form-data). Much of the code is similar, but the way you construct the body data is different.
Sending a request using URL encoding
Be it you have a server for your s...
Using alarm, user can schedule SIGALARM signal to be raised after specified interval. In case user did not blocked, ignored or specified explicit signal handler for this signal, the default action for this signal will be performed on arrival. Per specification default action for SIGALARM is to termi...
@parallel can be used to parallellize a loop, dividing steps of the loop up over different workers. As a very simple example:
addprocs(3)
a = collect(1:10)
for idx = 1:10
println(a[idx])
end
For a slightly more complex example, consider:
@time begin
@sync begin
@paral...
The Julia documentation advises that
pmap() is designed for the case where each function call does a large amount of work. In contrast, @parallel for can handle situations where each iteration is tiny, perhaps merely summing two numbers.
There are several reasons for this. First, pmap incurs ...
Stored procedures can return values using the OUTPUT keyword in its parameter list.
Creating a stored procedure with a single out parameter
CREATE PROCEDURE SprocWithOutParams
(
@InParam VARCHAR(30),
@OutParam VARCHAR(30) OUTPUT
)
AS
BEGIN
SELECT @OutParam = @InParam + ' must co...
-- Identity primary key - unique arbitrary increment number
create table person (
id int identity(1,1) primary key not null,
firstName varchar(100) not null,
lastName varchar(100) not null,
dob DateTime not null,
ssn varchar(9) not null
)
-- GUID primary key - arbitrary unique value for table
create table person (
id uniqueIdentifier default (newId()) primary key,
firstName varchar(100) not null,
lastName varchar(100) not null,
dob DateTime not null,
ssn varchar(9) not null
)
ALTER TABLE person
ADD CONSTRAINT pk_PersonSSN PRIMARY KEY (ssn)
Note, if the primary key column (in this case ssn) has more than one row with the same candidate key, the above statement will fail, as primary key values must be unique.
In the absence of explicit initialization, external and static variables are guaranteed to be initialized to zero; automatic variables (including register variables) have indeterminate1 (i.e., garbage) initial values.
Scalar variables may be initialized when they are defined by following the name w...