Custom filters in Vue.js can be created easily in a single function call to Vue.filter.
//JS
Vue.filter('reverse', function(value) {
return value.split('').reverse().join('');
});
//HTML
<span>{{ msg | reverse }}</span> //'This is fun!' => '!nuf si sihT'
It is good prac...
from pandas_datareader import data
# Only get the adjusted close.
aapl = data.DataReader("AAPL",
start='2015-1-1',
end='2015-12-31',
data_source='yahoo')['Adj Close']
>>> aapl.plot(title='AAPL Adj. C...
While Value Converters can be comprised of either a toView or fromView method, in the below example we will be creating a basic Value Converter which just uses the toView method which accepts the value being sent to the view as the first argument.
to-uppercase.js
export class ToUppercaseValueConve...
AlertDialog.Builder builder = new AlertDialog.Builder(context);
//Set Title
builder.setTitle("Reset...")
//Set Message
.setMessage("Are you sure?")
//Set the icon of the dialog
.setIcon(drawable)
//Set...
Records are an extension of sum algebraic data type that allow fields to be named:
data StandardType = StandardType String Int Bool --standard way to create a sum type
data RecordType = RecordType { -- the same sum type with record syntax
aString :: String
, aNumber :: Int
, isTrue :...
Model
using System.ComponentModel.DataAnnotations;
public class ViewModel
{
[Required(ErrorMessage="Name is required")]
public string Name { get; set; }
[StringLength(14, MinimumLength = 14, ErrorMessage = "Invalid Phone Number")]
[Required(ErrorMessag...
A list can be rendered using the v-for directive. The syntax requires that you specify the source array to iterate on, and an alias that will be used to reference each item in the iteration. In the following example we use items as the source array, and item as the alias for each item.
HTML
<di...
The main methods that are useful with this class are popleft and appendleft
from collections import deque
d = deque([1, 2, 3])
p = d.popleft() # p = 1, d = deque([2, 3])
d.appendleft(5) # d = deque([5, 2, 3])
In C, a string is a sequence of characters that is terminated by a null character ('\0').
We can create strings using string literals, which are sequences of characters surrounded by double quotation marks; for example, take the string literal "hello world". String literals are automatica...
Layout
Unity basic editor will look like below. Basic functionalities of some default windows/tabs are described in the image.
Linux Layout
There is a little difference in menu layout of linux version, like the screenshot below,
Basic Usage
Create an empty GameObject by right clicking in th...
The @Html.AntiForgeryToken() helper method protects against cross-site request forgery (or CSRF) attacks.
It can be used by simply using the Html.AntiForgeryToken() helper within one of your existing forms and decorating its corresponding Controller Action with the [ValidateAntiForgeryToken] attri...
Java ThreadLocal is used to create thread local variables. It is known that threads of an Object share it’s variables, so the variable is not thread safe. We can use synchronization for thread safety but if we want to avoid synchronization,ThreadLocal allows us to create variables which are local to...
With the shape-outside CSS property one can define shape values for the float area so that the inline content wraps around the shape instead of the float's box.
CSS
img:nth-of-type(1) {
shape-outside: circle(80px at 50% 50%);
float: left;
width: 200px;
}
img:nth-of-type(2) {
shape-ou...
Import the numpy module to use any part of it.
import numpy as np
Most examples will use np as shorthand for numpy. Assume "np" means "numpy" in code examples.
x = np.array([1,2,3,4])
Running the command:
grep sam someFile.txt
When someFile.txt contains:
fred 14 m foo
sam 68 m bar
christina 83 f baz
bob 22 m qux
Sam 41 m quux
Will produce this output:
sam 68 m bar
sqldf() from the package sqldf allows the use of SQLite queries to select and manipulate data in R. SQL queries are entered as character strings.
To select the first 10 rows of the "diamonds" dataset from the package ggplot2, for example:
data("diamonds")
head(diamonds)
#...
class PostsController < ApplicationController
before_action :set_post, only: [:show, :edit, :update, :destroy]
def index
@posts = Post.all
end
def show
end
def new
@post = Post.new
end
def edit
end
def create
@post = Post.new(post_par...
Python lists are 0-based i.e. the first element in the list can be accessed by the index 0
arr = ['a', 'b', 'c', 'd']
print(arr[0])
>> 'a'
You can access the second element in the list by index 1, third element by index 2 and so on:
print(arr[1])
>> 'b'
print(arr[2])
>> '...