Find properties with a custom attribute - MyAttribute
var props = t.GetProperties(BindingFlags.NonPublic | BindingFlags.Public |
BindingFlags.Instance).Where(
prop => Attribute.IsDefined(prop, typeof(MyAttribute)));
Find all custom attributes on a given property
va...
The android:process field defines the name of the process where the service is to run. Normally, all components of an application run in the default process created for the application. However, a component can override the default with its own process attribute, allowing you to spread your applicat...
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 ...
Django default project layout creates a single settings.py. This is often useful to split it like this:
myprojectroot/
myproject/
__init__.py
settings/
__init__.py
base.py
dev.py
prod.py
tests.py
This enables...
Django manger is an interface through which the django model queries the database. The objects field used in most django queries is actually the default manager created for us by django (this is only created if we don't define custom managers).
Why would we define a custom manager/queryset?
To avo...
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...
tl;dr : Create a base class that defines two user objects (say user and another_user). Create your other models and define three Client instances.
self.client : Representing user logged in browser
self.another_client : Representing another_user 's client
self.unlogged_client : Representing unlo...
Filters are a special type of function that can modify how something is printed out to the page, or can be used to filter an array, or a ng-repeat action. You can create a filter by calling the app.filter() method, passing it a name and a function. See the examples below for details on syntax.
Fo...
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.
package main
import (
"log"
"text/template"
"os"
)
type Person struct{
MyName string
MyAge int
}
var myTempContents string= `
This person's name is : {{.MyName}}
And he is {{.MyAge}} years old.
`
func main() {
t,err := temp...
To assign variables from the command-line, -v can be used:
$ awk -v myvar="hello" 'BEGIN {print myvar}'
hello
Note that there are no spaces around the equal sign.
This allows to use shell variables:
$ shell_var="hello"
$ awk -v myvar="$shell_var" 'BEGIN {print m...
You can nest quotes simply by including multiple > characters, like so:
> Often makes no sense.
> > Commenting above your quote…
Often makes no sense.
Commenting above your quote…
Node Version Manager, otherwise known as nvm, is a bash script that simplifies the management of multiple Node.js versions.
To install nvm, use the provided install script:
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.3/install.sh | bash
For windows there is a nvm-windows p...
Rcpp features two functions that enable code compilation inline and exportation directly into R: cppFunction() and evalCpp(). A third function called sourceCpp() exists to read in C++ code in a separate file though can be used akin to cppFunction().
Below is an example of compiling a C++ function w...
Rcpp Attributes makes the process of working with R and C++ straightforward. The form of attributes take:
// [[Rcpp::attribute]]
The use of attributes is typically associated with:
// [[Rcpp::export]]
that is placed directly above a declared function header when reading in a C++ file via sou...
Within C++, one can set different compilation flags using:
// [[Rcpp::plugins(name)]]
List of the built-in plugins:
// built-in C++11 plugin
// [[Rcpp::plugins(cpp11)]]
// built-in C++11 plugin for older g++ compiler
// [[Rcpp::plugins(cpp0x)]]
// built-in C++14 plugin for C++14 standa...
In some cases you may want to wrap a synchronous operation inside a promise to prevent repetition in code branches. Take this example:
if (result) { // if we already have a result
processResult(result); // process it
} else {
fetchResult().then(processResult);
}
The synchronous and async...
Cloning a huge repository (like a project with multiple years of history) might take a long time, or fail because of the amount of data to be transferred. In cases where you don't need to have the full history available, you can do a shallow clone:
git clone [repo_url] --depth 1
The above comman...