Tutorial by Examples: c

Some languages include a list data structure. Common Lisp, and other languages in the Lisp family, make extensive use of lists (and the name Lisp is based on the idea of a LISt Processor). However, Common Lisp doesn't actually include a primitive list datatype. Instead, lists exist by convention....
A cons cell, also known as a dotted pair (because of its printed representation), is simply a pair of two objects. A cons cell is created by the function cons, and elements in the pair are extracted using the functions car and cdr. (cons "a" 4) For instance, this returns a pair whose ...
Following is most basic expression tree that is created by lambda. Expression<Func<int, bool>> lambda = num => num == 42; To create expression trees 'by hand', one should use Expression class. Expression above would be equivalent to: ParameterExpression parameter = Expression.Pa...
This will create a timer to call the doSomething method on self in 5 seconds. Swift let timer = NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: Selector(doSomething()), userInfo: nil, ...
5.1 JavaScript does not directly support enumerators but the functionality of an enum can be mimicked. // Prevent the enum from being changed const TestEnum = Object.freeze({ One:1, Two:2, Three:3 }); // Define a variable with a value from the enum var x = TestEnum.Two; // Prin...
For example, if t1 is currently not an InnoDB table, this statement changes its storage engine to InnoDB: ALTER TABLE t1 ENGINE = InnoDB; If the table is already InnoDB, this will rebuild the table and its indexes and have an effect similar to OPTIMIZE TABLE. You may gain some disk space improv...
x = tf.constant(1.) bool = tf.constant(True) res = tf.cond(bool, lambda: tf.add(x, 1.), lambda: tf.add(x, 10.)) # sess.run(res) will give you 2.
Functions in python are first-class objects. They can be defined in any scope def fibonacci(n): def step(a,b): return b, a+b a, b = 0, 1 for i in range(n): a, b = step(a, b) return a Functions capture their enclosing scope can be passed around like any other...
Thread synchronization can be accomplished using mutexes, among other synchronization primitives. There are several mutex types provided by the standard library, but the simplest is std::mutex. To lock a mutex, you construct a lock on it. The simplest lock type is std::lock_guard: std::mutex m; vo...
Like lists and tuples, you can include a trailing comma in your dictionary. role = {"By day": "A typical programmer", "By night": "Still a typical programmer", } PEP 8 dictates that you should leave a space between the trailing comma and the closi...
There are three kinds of numeric RangeFields in Python. IntegerField, BigIntegerField, and FloatField. They convert to psycopg2 NumericRanges, but accept input as native Python tuples. The lower bound is included and the upper bound is excluded. class Book(models.Model): name = CharField(max_l...
It's simpler and easier to input values as a Python tuple instead of a NumericRange. Book.objects.create(name='Pro Git', ratings_range=(5, 5)) Alternative method with NumericRange: Book.objects.create(name='Pro Git', ratings_range=NumericRange(5, 5))
This query selects all books with any rating less than three. bad_books = Books.objects.filter(ratings_range__contains=(1, 3))
This query gets all books with ratings greater than or equal to zero and less than six. all_books = Book.objects.filter(ratings_range_contained_by=(0, 6))
the timedelta module comes in handy to compute differences between times: from datetime import datetime, timedelta now = datetime.now() then = datetime(2016, 5, 23) # datetime.datetime(2016, 05, 23, 0, 0, 0) Specifying time is optional when creating a new datetime object delta = now-then ...
To remove extraneous packages (packages that are installed but not in dependency list) run the following command: npm prune To remove all dev packages add --production flag: npm prune --production More on it
To generate a list (tree view) of currently installed packages, use npm list ls, la and ll are aliases of list command. la and ll commands shows extended information like description and repository. Options The response format can be changed by passing options. npm list --json json - Sh...
The PieChart class draws data in the form of circle which is divided into slices. Every slice represents a percentage (part) for a particular value. The pie chart data is wrapped in PieChart.Data objects. Each PieChart.Data object has two fields: the name of the pie slice and its corresponding valu...
When using a VCS such as Git or SVN, there are some secret data that must never be versioned (whether the repository is public or private). Among those data, you find the SECRET_KEY setting and the database password. A common practice to hide these settings from version control is to create a file...
The try { ... } catch ( ... ) { ... } control structure is used for handling Exceptions. String age_input = "abc"; try { int age = Integer.parseInt(age_input); if (age >= 18) { System.out.println("You can vote!"); } else { System.out.println(...

Page 203 of 826