Tutorial by Examples: ect

There are two ways to achieve that, the first and most known is the following: docker attach --sig-proxy=false <container> This one literally attaches your bash to the container bash, meaning that if you have a running script, you will see the result. To detach, just type: Ctl-P Ctl-Q Bu...
Sometimes it's necessary to convert a Discriminated Union to and from a string: module UnionConversion open Microsoft.FSharp.Reflection let toString (x: 'a) = match FSharpValue.GetUnionFields(x, typeof<'a>) with | case, _ -> case.Name let fromStri...
Date and LocalDate objects cannot be exactly converted between each other since a Date object represents both a specific day and time, while a LocalDate object does not contain time or timezone information. However, it can be useful to convert between the two if you only care about the actual date i...
The order of keys in Python dictionaries is arbitrary: they are not governed by the order in which you add them. For example: >>> d = {'foo': 5, 'bar': 6} >>> print(d) {'foo': 5, 'bar': 6} >>> d['baz'] = 7 >>> print(a) {'baz': 7, 'foo': 5, 'bar': 6} >&g...
Slices are objects in themselves and can be stored in variables with the built-in slice() function. Slice variables can be used to make your code more readable and to promote reuse. >>> programmer_1 = [ 1956, 'Guido', 'van Rossum', 'Python', 'Netherlands'] >>> programmer_2 = [ 18...
Comparing sets In R, a vector may contain duplicated elements: v = "A" w = c("A", "A") However, a set contains only one copy of each element. R treats a vector like a set by taking only its distinct elements, so the two vectors above are regarded as the same: set...
The %in% operator compares a vector with a set. v = "A" w = c("A", "A") w %in% v # TRUE TRUE v %in% w # TRUE Each element on the left is treated individually and tested for membership in the set associated with the vector on the right (consisting of all its...
To find every vector of the form (x, y) where x is drawn from vector X and y from Y, we use expand.grid: X = c(1, 1, 2) Y = c(4, 5) expand.grid(X, Y) # Var1 Var2 # 1 1 4 # 2 1 4 # 3 2 4 # 4 1 5 # 5 1 5 # 6 2 5 The result is a data.frame with one...
unique drops duplicates so that each element in the result is unique (only appears once): x = c(2, 1, 1, 2, 1) unique(x) # 2 1 Values are returned in the order they first appeared. duplicated tags each duplicated element: duplicated(x) # FALSE FALSE TRUE TRUE TRUE anyDuplicated(x) >...
To count how many elements of two sets overlap, one could write a custom function: xtab_set <- function(A, B){ both <- union(A, B) inA <- both %in% A inB <- both %in% B return(table(inA, inB)) } A = 1:20 B = 10:30 xtab_set(A, B) # inB ...
BeautifulSoup has a limited support for CSS selectors, but covers most commonly used ones. Use select() method to find multiple elements and select_one() to find a single element. Basic example: from bs4 import BeautifulSoup data = """ <ul> <li class="item&quo...
All built-in Clojure collections are immutable and heterogeneous, have literal syntax, and support the conj, count, and seq functions. conj returns a new collection that is equivalent to an existing collection with an item "added", in either "constant" or logarithmic time. Wha...
A vector is denoted by square brackets: [] ;;=> [] [:foo] ;;=> [:foo] [:foo :bar] ;;=> [:foo :bar] [1 (+ 1 1) 3] ;;=> [1 2 3] In addition using to the literal syntax, you can also use the vector function to construct a vector: (vector) ;;=> [] (vector :foo) ;;=&...
For if you have to fine-tune what is published. import { Mongo } from 'meteor/mongo'; import { Meteor } from 'meteor/meteor'; import { Random } from 'meteor/random'; if (Meteor.isClient) { // established this collection on the client only. // a name is required (first parameter) and this...
Using the dateutil library as in the previous example on parsing timezone-aware timestamps, it is also possible to parse timestamps with a specified "short" time zone name. For dates formatted with short time zone names or abbreviations, which are generally ambiguous (e.g. CST, which coul...
As with primitives, objects can be cast both explicitly and implicitly. Implicit casting happens when the source type extends or implements the target type (casting to a superclass or interface). Explicit casting has to be done when the source type is extended or implemented by the target type (ca...
Given the model: class MyModel(models.Model): name = models.CharField(max_length=10) model_num = models.IntegerField() flag = models.NullBooleanField(default=False) We can use Q objects to create AND , OR conditions in your lookup query. For example, say we want all objects that ...
Assuming a class from django.db import models class Author(models.Model): name = models.CharField(max_length=50) def __str__(self): return self.name def get_absolute_url(self): return reverse('view_author', args=[str(self.id)]) class Book(models.Mo...
When you want to use user generated content in the SQL, it with done with parameters. For example for searching user with the name aminadav you should do: var username = 'aminadav'; var querystring = 'SELECT name, email from users where name = ?'; connection.query(querystring, [username], functi...
a. Running multiple queries at same time All queries in MySQL connection are done one after another. It means that if you want to do 10 queries and each query takes 2 seconds then it will take 20 seconds to complete whole execution. The solution is to create 10 connection and run each query in a di...

Page 12 of 99