Django makes it really easy to add additional data onto requests for use within the view. For example, we can parse out the subdomain on the request's META and attach it as a separate property on the request by using middleware.
class SubdomainMiddleware:
def process_request(self, request):
...
resources :photos do
member do
get 'preview'
end
collection do
get 'dashboard'
end
end
This creates the following routes in addition to default 7 RESTful routes:
get '/photos/:id/preview', to: 'photos#preview'
get '/photos/dashboards', to: '...
To add a new unique column email to users, run the following command:
rails generate migration AddEmailToUsers email:string:uniq
This will create the following migration:
class AddEmailToUsers < ActiveRecord::Migration[5.0]
def change
add_column :users, :email, :string
add_index...
package {
import flash.display.Sprite;
import flash.events.Event;
public class Viewport extends Sprite {
/** Constructor */
public function Viewport() {
super();
// Listen for added to stage event
addEventListener(Event.ADDED_TO_STAGE, addedToStageHandle...
Function level annotations help IDEs identify return values or potentially dangerous code
/**
* Adds two numbers together.
*
* @param Int $a First parameter to add
* @param Int $b Second parameter to add
* @return Int
*/
function sum($a, $b)
{
return (int) $a + $b;
}
/**
* ...
File level metadata applies to all the code within the file and should be placed at the top of the file:
<?php
/**
* @author John Doe ([email protected])
* @copyright MIT
*/
Html5-Canvas ...
Is an Html5 element.
Is supported in most modern browsers (Internet Explorer 9+).
Is a visible element that is transparent by default
Has a default width of 300px and a default height of 150px.
Requires JavaScript because all content must be programmatically added to the Canv...
The URLVariables class allows you to define data to be sent along with a URLRequest.
Example:
var variables:URLVariables = new URLVariables();
variables.prop = "hello";
variables.anotherProp = 10;
var request:URLRequest = new URLRequest('http://someservice.com');
request.data = v...
You can easily add a breakpoint to your code by clicking on the grey column to the left of the line of your VBA code where you want execution to stop. A red dot appears in the column and the breakpoint code is also highlighted in red.
You can add multiple breakpoints throughout your code and resumi...
A commonly used CSS/Javascript library is Bootstrap. To install it into your Aurelia CLI driven application first you need to install it using Npm.
npm install bootstrap --save
Because Bootstrap has a hard dependency on jQuery, we need to make sure we also have jQuery installed:
npm install jqu...
Sometimes you want to add an element to the beginning of an array without modifying any of the current elements (order) within the array. Whenever this is the case, you can use array_unshift().
array_unshift() prepends passed elements to the front of the array.
Note that the list of elements is ...
We can use partial application to "lock" the first argument. After applying one argument we are left with a function which expects one more argument before returning the result.
(+) :: Int -> Int -> Int
addOne :: Int -> Int
addOne = (+) 1
We can then use addOne in order to...
User can add custom route, mapping an URL to a specific action in a controller. This is used for search engine optimization purpose and make URLs readable.
routes.MapRoute(
name: "AboutUsAspx", // Route name
url: "AboutUs.aspx", // URL with parameters
defaults: new { c...
The procedure describes how to add an Object library reference, and afterwards how to declare new variables with reference to the new library class objects.
The example below shows how to add the PowerPoint library to the existing VB Project.
As can be seen, currently the PowerPoint Object library...
Syntax: add_months(p_date, integer) return date;
Add_months function adds amt months to p_date date.
SELECT add_months(date'2015-01-12', 2) m FROM dual;
M2015-03-12
You can also substract months using a negative amt
SELECT add_months(date'2015-01-12', -2) m FROM dual;
M2014-11-12
When the...
Let's suppose we have a reference to the JQuery type definition and we want to extend it to have additional functions from a plugin we included and which doesn't have an official type definition. We can easily extend it by declaring functions added by plugin in a separate interface declaration with ...
There are multiple ways to populate an array.
Directly
'one-dimensional
Dim arrayDirect1D(2) As String
arrayDirect(0) = "A"
arrayDirect(1) = "B"
arrayDirect(2) = "C"
'multi-dimensional (in this case 3D)
Dim arrayDirectMulti(1, 1, 2)
arrayDirectMulti(0, 0, 0...
Install the necessary Python Library via:
$ pip install elasticsearch
Connect to Elasticsearch, Create a Document (e.g. data entry) and "Index" the document using Elasticsearch.
from datetime import datetime
from elasticsearch import Elasticsearch
# Connect to Elasticsearch using ...