Tutorial by Examples: er

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))
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 ...
It is possible, inside a closure, to use an external variable with the special keyword use. For instance: <?php $quantity = 1; $calculator = function($number) use($quantity) { return $number + $quantity; }; var_dump($calculator(2)); // Shows "3" You can go further by ...
In general, an observer is a class with a specific method being called when an action on the observed object occurs. In certain situations, closures can be enough to implement the observer design pattern. Here is a detailed example of such an implementation. Let's first declare a class whose purpos...
We define two sets a and b >>> a = {1, 2, 2, 3, 4} >>> b = {3, 3, 4, 4, 5} NOTE: {1} creates a set of one element, but {} creates an empty dict. The correct way to create an empty set is set(). Intersection a.intersection(b) returns a new set with elements present in bot...
Even though Python natively supports big integers, taking the nth root of very large numbers can fail in Python. x = 2 ** 100 cube = x ** 3 root = cube ** (1.0 / 3) OverflowError: long int too large to convert to float When dealing with such large integers, you will need to use a custom f...
Common Lisp already has a reverse function, but if it didn't, then it could be implemented easily using reduce. Given a list like (1 2 3) === (cons 1 (cons 2 (cons 3 '()))) the reversed list is (cons 3 (cons 2 (cons 1 '()))) === (3 2 1) That may not be an obvious use of reduce, but if we ha...
To verify that nvm has been installed, do: command -v nvm which should output 'nvm' if the installation was successful.
Listing available remote versions for installation nvm ls-remote Installing a remote version nvm install <version> For example nvm install 0.10.13
To list available local versions of node through NVM: nvm ls For example, if nvm ls returns: $ nvm ls v4.3.0 v5.5.0 You can switch to v5.5.0 with: nvm use v5.5.0
Three methods are provided that offer the ability to strip leading and trailing characters from a string: str.strip, str.rstrip and str.lstrip. All three methods have the same signature and all three return a new string object with unwanted characters removed. str.strip([chars]) str.strip acts o...
To connect using java.sql.DriverManager you need a JDBC url to connect to your database. JDBC urls are database specific, but they are all of the form jdbc:<subprotocol>:<subname> Where <subprotocol> identifies the driver or database (for example postgresql, mysql, firebirdsql,...
Problem: Some data needs to be passed to a scene loaded from a fxml. Solution Specify a controller using the fx:controller attribute and get the controller instance created during the loading process from the FXMLLoader instance used to load the fxml. Add methods for passing the data to the contr...
Problem: Some data needs to be passed to a scene loaded from a fxml. Solution Set the controller using the FXMLLoader instance used later to load the fxml. Make sure the controller contains the relevant data before loading the fxml. Note: in this case the fxml file must not contain the fx:contro...
Problem: Some data needs to be passed to a scene loaded from a fxml. Solution Specify a controller factory that is responsible for creating the controllers. Pass the data to the controller instance created by the factory. FXML <?xml version="1.0" encoding="UTF-8"?> &...
LinqPad is a great tool that allows you to learn and test features of .Net languages (C#, F# and VB.Net.) Install LinqPad Create a new Query (Ctrl + N) Under language, select "C# statements" Type the following code and hit run (F5) string hw = "Hello World&quo...
A common task is to convert all columns of a data.frame to character class for ease of manipulation, such as in the cases of sending data.frames to a RDBMS or merging data.frames containing factors where levels may differ between input data.frames. The best time to do this is when the data is read ...
Rational represents a rational number as numerator and denominator: r1 = Rational(2, 3) r2 = 2.5.to_r r3 = r1 + r2 r3.numerator # => 19 r3.denominator # => 6 Rational(2, 4) # => (1/2) Other ways of creating a Rational Rational('2/3') # => (2/3) Rational(3) # => (3/1...
1i # => (0+1i) 1.to_c # => (1+0i) rectangular = Complex(2, 3) # => (2+3i) polar = Complex('1@2') # => (-0.4161468365471424+0.9092974268256817i) polar.rectangular # => [-0.4161468365471424, 0.9092974268256817] rectangular.polar # => [3.605551275463989, 0.9827937232...

Page 106 of 417