Vectors can be map'd and fold'd,filter'd andzip`'d:
Prelude Data.Vector> Data.Vector.map (^2) y
fromList [0,1,4,9,16,25,36,49,64,81,100,121] :: Data.Vector.Vector
Reduce to a single value:
Prelude Data.Vector> Data.Vector.foldl (+) 0 y
66
Zip two arrays into an array of pairs:
Prelude Data.Vector> Data.Vector.zip y y
fromList [(0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10),(11,11)] :: Data.Vector.Vector
Most of the magic of destructuring uses the splat (*) operator.
ExampleResult / commenta, b = [0,1]a=0, b=1a, *rest = [0,1,2,3]a=0, rest=[1,2,3]a, * = [0,1,2,3]a=0 Equivalent to .first*, z = [0,1,2,3]z=3 Equivalent to .last
By default Code First includes in model
Types defined as a DbSet property in context class.
Reference types included in entity types even if they are defined in
different assembly.
Derived classes even if only the base class is defined as DbSet
property
Here is an example, that we are only...
select returns a new hash with key-value pairs for which the block evaluates to true.
{ :a => 1, :b => 2, :c => 3 }.select { |k, v| k != :a && v.even? } # => { :b => 2 }
When you will not need the key or value in a filter block, the convention is to use an _ in that place:...
Intersection of Hashes
To get the intersection of two hashes, return the shared keys the values of which are equal:
hash1 = { :a => 1, :b => 2 }
hash2 = { :b => 2, :c => 3 }
hash1.select { |k, v| (hash2.include?(k) && hash2[k] == v) } # => { :b => 2 }
Union (...
Vim knows The Answer:
:help 42
Vim will open the usr_42.txt document from the manual and show the following text:
What is the meaning of life, the universe and everything? 42
Douglas Adams, the only person who knew what this question really was about is
now dead, unfortunately. So now you m...
Selectors are used as method identifiers in Objective-C.
In the example below, there are two selectors. new and setName:
Person* customer = [Person new];
[customer setName:@"John Doe"];
Each pair of brackets corresponds to a message send. On the first line we send a message containin...
These rules apply only if you use manual reference counting!
You own any object you create
By calling a method whose name begins with alloc, new, copy or mutableCopy.
For example:
NSObject *object1 = [[NSObject alloc] init];
NSObject *object2 = [NSObject new];
NSObject *object3 = [object2 ...
Here is a quick example of using multiple forms in one Django view.
from django.contrib import messages
from django.views.generic import TemplateView
from .forms import AddPostForm, AddCommentForm
from .models import Comment
class AddCommentView(TemplateView):
post_form_class = AddPo...
A Haskell project can either use the system wide packages or use a sandbox. A sandbox is an isolated package database and can prevent dependency conflicts, e. g. if multiple Haskell projects use different versions of a package.
To initialize a sandbox for a Haskell package go to its directory and r...
After you have opened a split window in vim (as demonstrated by many examples under this tag) then you will likely want to control windows quickly. Here is how to control split windows using keyboard shortcuts.
Move to split Above/Below:
Ctrl + w and k
Ctrl + w and j
Move to split Left/Right...
The Window Object contains the following properties.
PropertyDescriptionwindow.closedWhether the window has been closedwindow.lengthNumber of <iframe> elements in windowwindow.nameGets or sets the name of the windowwindow.innerHeightHeight of windowwindow.innerWidthWidth of windowwindow.scree...
<?php
$to = 'recipent@example.com';
$subject = 'Sending an HTML email using mail() in PHP';
$message = '<html><body><p><b>This paragraph is bold.</b></p><p><i>This text is italic.</i></p></body></html>';
$headers =...
Many unbound generic parameters, like those used in a static method, cannot be recovered at runtime (see Other Threads on Erasure). However there is a common strategy employed for accessing the type satisfying a generic parameter on a class at runtime. This allows for generic code that depends on ac...
# Deny access to a directory from the IP 255.0.0.0
<Directory /path/to/directory>
order allow,deny
deny from 255.0.0.0
allow from all
</Directory>
# Deny access to a file from the IP 255.0.0.0
<FilesMatch "^\.ht">
order allow,deny
deny fro...
python-social-auth is a framework that simplifies the social authentication and authorization mechanism. It contains many social backends (Facebook, Twitter, Github, LinkedIn, etc.)
INSTALL
First we need to install the python-social-auth package with
pip install python-social-auth
or download ...