Tutorial by Examples

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, ...
Swift timer.fire() Objective-C [timer fire]; Calling the fire method causes an NSTimer to perform the task it would have usually performed on a schedule. In a non-repeating timer, this will automatically invalidate the timer. That is, calling fire before the time interval is up will result ...
Swift timer.invalidate() Objective-C [timer invalidate]; This will stop the timer from firing. Must be called from the thread the timer was created in, see Apple's notes: You must send this message from the thread on which the timer was installed. If you send this message from another thr...
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...
Keyword for storing the Boolean values true and false. bool is an alias of System.Boolean. The default value of a bool is false. bool b; // default value is false b = true; // true b = ((5 + 2) == 6); // false For a bool to allow null values it must be initialized as a bool?. The default val...
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.
The two functions fn1 and fn2 can return multiple tensors, but they have to return the exact same number and types of outputs. x = tf.constant(1.) bool = tf.constant(True) def fn1(): return tf.add(x, 1.), x def fn2(): return tf.add(x, 10.), x res1, res2 = tf.cond(bool, fn1, fn2)...
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...
Below won't work on a Windows machine $file = $request->file('file_upload'); $sampleName = 'UserUpload'; $destination = app_path() . '/myStorage/'; $fileName = $sampleName . '-' . date('Y-m-d-H:i:s') . '.' . $file->getClientOriginalExtension(); $file->move($destination, $fileName); ...
The following values are considered falsey, in that they evaluate to False when applied to a boolean operator. None False 0, or any numerical value equivalent to zero, for example 0L, 0.0, 0j Empty sequences: '', "", (), [] Empty mappings: {} User-defined types where the __bool__ o...
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...
add 'django.contrib.postgres' to your INSTALLED_APPS install psycopg2
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))
This query gets all overlapping appointments from six to ten. Appointment.objects.filter(time_span__overlap=(6, 10))
This query selects all books with any rating greater than or equal to four. maybe_good_books = Books.objects.filter(ratings_range__contains=(4, None))

Page 329 of 1336