Tutorial by Examples: ad

Forms can be defined, in a similar manner to models, by subclassing django.forms.Form. Various field input options are available such as CharField, URLField, IntegerField, etc. Defining a simple contact form can be seen below: from django import forms class ContactForm(forms.Form): contac...
use std::fs::File; use std::io::Read; fn main() { let filename = "src/main.rs"; // Open the file in read-only mode. match File::open(filename) { // The file is open (no error). Ok(mut file) => { let mut content = String::new(); ...
use std::fs::File; use std::io::{BufRead, BufReader}; fn main() { let filename = "src/main.rs"; // Open the file in read-only mode (ignoring errors). let file = File::open(filename).unwrap(); let reader = BufReader::new(file); // Read the file line by line us...
Channels can be used to send data from one thread to another. Below is an example of a simple producer-consumer system, where the main thread produces the values 0, 1, ..., 9, and the spawned thread prints them: use std::thread; use std::sync::mpsc::channel; fn main() { // Create a channel...
return Socialite::driver('facebook')->redirect(); This will redirect an incoming request to the appropriate URL to be authenticated. A basic example would be in a controller <?php namespace App\Http\Controllers\Auth; use Socialite; class AuthenticationController extends Controller...
docker exec -it <container id> /bin/bash It is common to log in an already running container to make some quick tests or see what the application is doing. Often it denotes bad container use practices due to logs and changed files should be placed in volumes. This example allows us log in the...
9.0 // Since the anchor system simply returns constraints, you still need to add them somewhere. View.AddConstraints( new[] { someLabel.TopAnchor.ConstraintEqualTo(TopLayoutGuide.GetBottomAnchor()), anotherLabel.TopAnchor.ConstraintEqualTo(someLabel.BottomAnchor, 6), ...
// Using Visual Format Language requires a special look-up dictionary of names<->views. var views = new NSDictionary( nameof(someLabel), someLabel, nameof(anotherLabel), anotherLabel, nameof(oneMoreLabel), oneMoreLabel ); // It can also take a look-up dictionary for metrics (...
It is possible to mount a host directory to a specific path in your container using the -v or --volume command line option. The following example will mount /etc on the host to /mnt/etc in the container: (on linux) docker run -v "/etc:/mnt/etc" alpine cat /mnt/etc/passwd (on windows) do...
All these are shell commands If you need to log onto a running docker-machine directly, you can do that: docker-machine ssh to ssh into the default docker-machine docker-machine ssh machinename to ssh into a non-default docker-machine If you just want to run a single command, you can do so...
With this example, we will see how to load a color image from disk and display it using OpenCV's built-in functions. We can use the C/C++, Python or Java bindings to accomplish this. In C++: #include <opencv2/core.hpp> #include <opencv2/highgui.hpp> #include <iostream> usi...
Background threads cannot modify the UI; almost all UIKit methods must be called on the main thread. From a subclass of NSObject (including any UIViewController or UIView): InvokeOnMainThread(() => { // Call UI methods here }); From a standard C# class: UIApplication.SharedApplicat...
This example assumes you have already installed Java and Gradle. Use the following project structure: src/ main/ java/ com/ example/ Application.java build.gradle build.gradle is your build script for Gradle build system with the following content: buildscri...
You can add items to a user's Reading List in Safari by calling the addItem method on the SSReadingList singleton. let readingList = SSReadingList.default() readingList?.addItem(with: yourURL, title: "optional title", previewText: "optional preview text") The default Reading...
In the material design, a Floating action button represents the primary action in an Activity. They are distinguished by a circled icon floating above the UI and have motion behaviors that include morphing, launching, and a transferring anchor point. Make sure the following dependency is added to ...
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 ...
Similarly to the SimpleXML, you can use DOMDocument to parse XML from a string or from a XML file 1. From a string $doc = new DOMDocument(); $doc->loadXML($string); 2. From a file $doc = new DOMDocument(); $doc->load('books.xml');// use the actual file path. Absolute or relative Exa...
Once your setup.py is fully functional (see Introduction), it is very easy to upload your package to PyPI. Setup a .pypirc File This file stores logins and passwords to authenticate your accounts. It is typically stored in your home directory. # .pypirc file [distutils] index-servers = py...
Retrofit requests can be logged using an intercepter. There are several levels of detail available: NONE, BASIC, HEADERS, BODY. See Github project here. Add dependency to build.gradle: compile 'com.squareup.okhttp3:logging-interceptor:3.8.1' Add logging interceptor when creating Retrofit:...
After extending the Http class, we need to tell angular to use this class instead of Http class. In order to do this, in our main module(or depending on the needs, just a particular module), we need to write in the providers section: export function httpServiceFactory(xhrBackend: XHRBackend, reque...

Page 14 of 114