Tutorial by Examples: c

Using threading & queue: from socket import socket, AF_INET, SOCK_STREAM from threading import Thread from queue import Queue def echo_server(addr, nworkers): print('Echo server running at', addr) # Launch the client workers q = Queue() for n in range(nworkers): ...
Interfaces may have variant type parameters. interface IEnumerable<out T> { // ... } interface IComparer<in T> { // ... } but classes and structures may not class BadClass<in T1, out T2> // not allowed { } struct BadStruct<in T1, out T2> // not allo...
Record syntax can be used with newtype with the restriction that there is exactly one constructor with exactly one field. The benefit here is the automatic creation of a function to unwrap the newtype. These fields are often named starting with run for monads, get for monoids, and un for other typ...
In a non-strict-mode scope, when a variable is assigned without being initialized with the var, const or the let keyword, it is automatically declared in the global scope: a = 12; console.log(a); // 12 In strict mode however, any access to an undeclared variable will throw a reference error: &...
Differences in subsetting syntax A data.table is one of several two-dimensional data structures available in R, besides data.frame, matrix and (2D) array. All of these classes use a very similar but not identical syntax for subsetting, the A[rows, cols] schema. Consider the following data stored i...
Category theory is a modern mathematical theory and a branch of abstract algebra focused on the nature of connectedness and relation. It is useful for giving solid foundations and common language to many highly reusable programming abstractions. Haskell uses Category theory as inspiration for some o...
A category C consists of: A collection of objects called Obj(C) ; A collection (called Hom(C)) of morphisms between those objects. If a and b are in Obj(C), then a morphism f in Hom(C) is typically denoted f : a -> b, and the collection of all morphism between a and b is denoted hom(a,b) ; A...
Using Kestrel you can specify port using next approaches: Defining ASPNETCORE_URLS environment variable. Windows SET ASPNETCORE_URLS=https://0.0.0.0:5001 OS X export ASPNETCORE_URLS=https://0.0.0.0:5001 Via command line passing --server.urls parameter dotnet run --server.urls=http...
If you have a string that contains Python literals, such as strings, floats etc, you can use ast.literal_eval to evaluate its value instead of eval. This has the added feature of allowing only certain syntax. >>> import ast >>> code = """(1, 2, {'foo': 'bar'})&quot...
It is not possible to use eval or exec to execute code from untrusted user securely. Even ast.literal_eval is prone to crashes in the parser. It is sometimes possible to guard against malicious code execution, but it doesn't exclude the possibility of outright crashes in the parser or the tokenizer....
You can select elements with different selectors : by tag : "div" by class : ".class" by id : "#id" by attribute : "[color=blue]" multiple selectors (OR): "div1, div2, class1" multiple selectors (AND): "div1 div2 class1"
This will give current system version. Objective-C NSString *version = [[UIDevice currentDevice] systemVersion] Swift let version = UIDevice.currentDevice().systemVersion Swift 3 let version = UIDevice.current.systemVersion
<div class="navbar navbar-inverse navbar-fixed-top"> <div class="container"> <div class="navbar-header"> <!--- vvv Hamburger icon that gets shown when window reaches a certain scale vvv ---> <button type...
With ASP.NET Core 1.0, the MVC and Web API framework have been merged into one framework called ASP.NET Core MVC. This is a good thing, since MVC and Web API share a lot of functionality, yet there always were subtle differences and code duplication. However, merging these two into framework one ...
In Scala operators (such as +, -, *, ++, etc.) are just methods. For instance, 1 + 2 can be written as 1.+(2). These sorts of methods are called 'infix operators'. This means custom methods can be defined on your own types, reusing these operators: class Matrix(rows: Int, cols: Int, val data: Seq[...
To make a custom pipe available application wide, During application bootstrap, extending PLATFORM_PIPES. import { bootstrap } from '@angular/platform-browser-dynamic'; import { provide, PLATFORM_PIPES } from '@angular/core'; import { AppComponent } from './app.component'; import { MyPipe }...
The case modifier causes the Scala compiler to automatically generate common boilerplate code for the class. Implementing this code manually is tedious and a source of errors. The following case class definition: case class Person(name: String, age: Int) ... will have the following code automati...
Sometimes when you make a game you need to create and destroy a lot of objects of the same type over and over again. You can simply do this by making a prefab and instantiate/destroy this whenever you need to, however, doing this is inefficient and can slow your game down. One way to get around thi...
A topological ordering, or a topological sort, orders the vertices in a directed acyclic graph on a line, i.e. in a list, such that all directed edges go from left to right. Such an ordering cannot exist if the graph contains a directed cycle because there is no way that you can keep going right ...
Unity works with hierarchies in order to keep your project organized. You can assign objects a place in the hierarchy using the editor but you can also do this through code. Parenting You can set an object's parent with the following methods var other = GetOtherGameObject(); other.transform.Se...

Page 173 of 826