There is currently a proposal (not yet part of the ECMAScript standard) to add a finally callback to promises that will be executed regardless of whether the promise is fulfilled or rejected. Semantically, this is similar to the finally clause of the try block.
You would usually use this functional...
Protocols enable polymorphism in Elixir. Define protocols with defprotocol:
defprotocol Log do
def log(value, opts)
end
Implement a protocol with defimpl:
require Logger
# User and Post are custom structs
defimpl Log, for: User do
def log(user, _opts) do
Logger.info "User: ...
Use & to capture functions from other modules. You can use the captured functions directly as function parameters or within anonymous functions.
Enum.map(list, fn(x) -> String.capitalize(x) end)
Can be made more concise using &:
Enum.map(list, &String.capitalize(&1))
Captu...
We often encounter a situation where a property we're trying to extract doesn't exist in the object/array, resulting in a TypeError (while destructuring nested objects) or being set to undefined. While destructuring we can set a default value, which it will fallback to, in case of it not being found...
We are not limited to destructuring an object/array, we can destructure a nested object/array.
Nested Object Destructuring
var obj = {
a: {
c: 1,
d: 3
},
b: 2
};
var {
a: {
c: x,
d: y
},
b: z
} = obj;
console.log(x, y, z); // 1,3,2
Nested Array ...
\documentclass{article}% or book, report, ...
\begin{document}
See \cite{citeA} or \cite{citeB} or \cite{citeA, citeB}.
\begin{thebibliography}{x}
% \bibitem{<biblabel>} <citation>
\bibitem{citeA}
{\scshape Author, A}, {\itshape A title}, Journal of So-and-So, 2000....
round() tie breaking
In Python 2, using round() on a number equally close to two integers will return the one furthest from 0. For example:
Python 2.x2.7
round(1.5) # Out: 2.0
round(0.5) # Out: 1.0
round(-0.5) # Out: -1.0
round(-1.5) # Out: -2.0
In Python 3 however, round() will retur...
adduser command adds a user to the system. In order to add a new user type:
sudo adduser <user_name>
example:
sudo adduser tom
After typing the above command, you will be prompted to enter details about the new user, such as new password, user Full name, etc.
Below is the information ...
Dictionary<TKey, TValue> is a map. For a given key there can be one value in the dictionary.
using System.Collections.Generic;
var people = new Dictionary<string, int>
{
{ "John", 30 }, {"Mary", 35}, {"Jack", 40}
};
// Reading data
Console.Wri...
To register your device for push notifications, add the following code to your AppDelegate file in didFinishLaunchingWithOptions method:
Swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for c...
Note: Before upgrading your Rails app, always make sure to save your code on a version control system, such as Git.
To upgrade from Rails 4.2 to Rails 5.0, you must be using Ruby 2.2.2 or newer. After upgrading your Ruby version if required, go to your Gemfile and change the line:
gem 'rails', '...
Everything you need to get started with Django admin is already setup in Django's default project layout. This includes:
# settings.py
# `django.contrib.admin` and its dependancies.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',...
The following are the steps to start an Eclipse remote debugger. This is useful when the application is not started from a server instance within Eclipse. This feature is really powerful and can also help debugging code which resides in the test or production environment. Let's have a look at the se...
Setup your view controller to manage editing of text for the text field.
class MyViewController: UITextFieldDelegate {
override viewDidLoad() {
super.viewDidLoad()
textField.delegate = self
}
}
textFieldShouldReturn is called every time the return butto...
Instructs the engine to use hash method to join tables in the argument.
Usage : use_hash(TableA [TableB] ... [TableN])
As explained in many places, "in a HASH join, Oracle accesses one table (usually the smaller of the joined results) and builds a hash table on the join key in memory. It the...
SUBSTR retrieves part of a string by indicating the starting position and the number of characters to extract
SELECT SUBSTR('abcdefg',2,3) FROM DUAL;
returns:
bcd
To count from the end of the string, SUBSTR accepts a negative number as the second parameter, e.g.
SELECT SUBSTR('abcdefg',-4,2...