Assuming a class
from django.db import models
class Author(models.Model):
name = models.CharField(max_length=50)
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('view_author', args=[str(self.id)])
class Book(models.Mo...
To run a container interactively, pass in the -it options:
$ docker run -it ubuntu:14.04 bash
root@8ef2356d919a:/# echo hi
hi
root@8ef2356d919a:/#
-i keeps STDIN open, while -t allocates a pseudo-TTY.
You can group multiple boolean logic statements within parenthesis in order to create a more complex logic evaluation, especially useful in if statements.
if ((age >= 18 && height >= 5.11) || (status === 'royalty' && hasInvitation)) {
console.log('You can enter our club');
...
After setting up Xcode, it is not difficult to get your first iOS up and running.
In the following example we will:
Start a new project
Add a label
Printing message to console.
Run in the simulator
Starting a new project
When the Xcode welcome screen comes up, choose Create a new Xcode pr...
Create a class which extends Service class and in overridden method onBind return your local binder instance:
public class LocalService extends Service {
// Binder given to clients
private final IBinder mBinder = new LocalBinder();
/**
* Class used for the client Binder. Bec...
To get a value from the map, you just have to do something like:00
value := mapName[ key ]
If the map contains the key, it returns the corresponding value.
If not, it returns zero-value of the map's value type (0 if map of int values, "" if map of string values...)
m := map[string]s...
If you want to cancel an alarm, and you don't have a reference to the original PendingIntent used to set the alarm, you need to recreate a PendingIntent exactly as it was when it was originally created.
An Intent is considered equal by the AlarmManager:
if their action, data, type, class, and ca...
Executing code after 1.5 seconds:
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
//The code you want to run after the time is up
}
}, 1500); //the time you want to delay in milliseconds
Executing code repeatedly every...
HTML 4.01/XHTML 1.0 Strict includes the following void elements:
area - clickable, defined area in an image
base - specifies a base URL from which all links base
br - line break
col - column in a table [deprecated]
hr - horizontal rule (line)
img - image
input - field where users enter data...
This example creates a Polymer element named x-foo, whose template binds to a string property, named "message". The element's HTML is imported into the main document, which allows usage of <x-foo> tags in <body>.
x-foo.html
<dom-module id="x-foo">
<templ...
A shell script is a very versatile way to extend your build to basically anything you can think of.
As an exmaple, here is a simple script to compile protobuf files and add the result java files to the source directory for further compilation:
def compilePb() {
exec {
// NOTICE: grad...
The following prints the message Hello, World! to console
public void hello() {
Observable.just("Hello, World!") // create new observable
.subscribe(new Action1<String>() { // subscribe and perform action
@Override
public void call(String st) {
Sy...
DELETE FROM `table_name` WHERE `field_one` = 'value_one'
This will delete all rows from the table where the contents of the field_one for that row match 'value_one'
The WHERE clause works in the same way as a select, so things like >, <, <> or LIKE can be used.
Notice: It is necessa...
DELETE FROM table_name ;
This will delete everything, all rows from the table. It is the most basic example of the syntax. It also shows that DELETE statements should really be used with extra care as they may empty a table, if the WHERE clause is omitted.
DELETE FROM `table_name` WHERE `field_one` = 'value_one' LIMIT 1
This works in the same way as the 'Delete with Where clause' example, but it will stop the deletion once the limited number of rows have been removed.
If you are limiting rows for deletion like this, be aware that it will delete th...
Statement-level parallel hints are the easiest:
SELECT /*+ PARALLEL(8) */ first_name, last_name FROM employee emp;
Object-level parallel hints give more control but are more prone to errors; developers often forget to use the alias instead of the object name, or they forget to include some objec...
The model is named using the class naming convention of unbroken MixedCase and is always the singular of the table name.
For Example: If a table was named orders, the associated model would be named Order
For Example: If a table was named posts, the associated model would be named Post
Rails will...
Swift
let alert = UIAlertController(title: "Hello",
message: "Welcome to the world of iOS",
preferredStyle: UIAlertControllerStyle.alert)
let defaultAction = UIAlertAction(title: "OK", style: UIAlertActionS...
You may want to create a duplicate of a table:
CREATE TABLE ClonedEmployees AS SELECT * FROM Employees;
You can use any of the other features of a SELECT statement to modify the data before passing it to the new table. The columns of the new table are automatically created according to the selec...