Tutorial by Examples: ti

Python supports using a for loop directly on a list: my_list = ['foo', 'bar', 'baz'] for item in my_list: print(item) # Output: foo # Output: bar # Output: baz You can also get the position of each item at the same time: for (index, item) in enumerate(my_list): print('The item i...
GitHub is a huge collection of Git repositories. In other words, you can think of GitHub as a collection of many projects! Creating An Account Visit GitHub's main page Here Pick a username, enter in your email address, and pick a secure password and you're ready to go! Useful Tools For Git/...
Writing a view to create object can be quite boring. You have to display a form, you have to validate it, you have to save the item or return the form with an error. Unless you use one of the generic editing views. app/views.py from django.core.urlresolvers import reverse_lazy from django.views.g...
In order to create a random user password we can use the symbols provided in the string module. Specifically punctuation for punctuation symbols, ascii_letters for letters and digits for digits: from string import punctuation, ascii_letters, digits We can then combine all these symbols in a name...
To start a new thread: use std::thread; fn main() { thread::spawn(move || { // The main thread will not wait for this thread to finish. That // might mean that the next println isn't even executed before the // program exits. println!("Hello from spa...
The jQuery UI framework helps to extend and increase the User Interface controls for jQuery JavaScript library. When you wish to use jQuery UI, you will need to add these libraries to your HTML. A quick way to start is using the Content Delivery Network available code sources: jQuery Libraries ht...
You can create a tuple and use a switch like so: var str: String? = "hi" var x: Int? = 5 switch (str, x) { case (.Some,.Some): print("Both have values") case (.Some, nil): print("String has a value") case (nil, .Some): print("Int has a value&...
<script> $( ".inclas").datepicker({ minDate: new Date(2007, 1 - 1, 1) maxDate: new Date(2008, 1 - 1, 1) }); </script> <input type ="text" id="datepick" class="inclas">
Many-to-One Relationship from django.db import models class Author(models.Model): name = models.CharField(max_length=50) #Book has a foreignkey (many to one) relationship with author class Book(models.Model): author = models.ForeignKey(Author, on_delete=models.CASCADE) publish_...
While the math.sqrt function is provided for the specific case of square roots, it's often convenient to use the exponentiation operator (**) with fractional exponents to perform nth-root operations, like cube roots. The inverse of an exponentiation is exponentiation by the exponent's reciprocal. S...
The background-position property is used to specify the starting position for a background image or gradient .myClass { background-image: url('path/to/image.jpg'); background-position: 50% 50%; } The position is set using an X and Y co-ordinate and be set using any of the units used withi...
The most simple example of widget is custom text input. For instance, to create an <input type="tel">, you have to subclass TextInput and set input_type to 'tel'. from django.forms.widgets import TextInput class PhoneInput(TextInput): input_type = 'tel'
This assumes that you have read the documentation about starting a new Django project. Let us assume that the main app in your project is named td (short for test driven). To create your first test, create a file named test_view.py and copy paste the following content into it. from django.test impo...
Detailed instructions on getting couchbase set up or installed.
To demystify Template Haskell, suppose you have data Example a = Example { _foo :: Int, _bar :: a } then makeLenses 'Example produces (more or less) foo :: Lens' (Example a) Int bar :: Lens (Example a) (Example b) a b There's nothing particularly magical going on, though. You can write ...
This type of tests make sure that your code compiles properly and will appear in the generated documentation for your project. In addition to that, the example tests can assert that your test produces proper output. sum.go: package sum // Sum calculates the sum of two integers func Sum(a, b in...
You can use Optional Chaining in order to call a method, access a property or subscript an optional. This is done by placing a ? between the given optional variable and the given member (method, property or subscript). struct Foo { func doSomething() { print("Hello World!") ...
Create a new playground file: First option: From Xcode welcome screen, select the first option (Get started with a playground). Second option: From menu select File → New → Playground (⌥⇧⌘N). Name your playground and select the platform (iOS/macOS/tvOS), then click Next. ...
Install gunicorn pip install gunicorn From django project folder (same folder where manage.py resides), run the following command to run current django project with gunicorn gunicorn [projectname].wsgi:application -b 127.0.0.1:[port number] You can use the --env option to set the pat...
OptionSetType is a protocol designed to represent bit mask types where individual bits represent members of the set. A set of logical and/or functions enforce the proper syntax: struct Features : OptionSet { let rawValue : Int static let none = Features(rawValue: 0) static let feature0 = F...

Page 60 of 505