Set a value to a variable if one doesn't exist, like this:
name = name || 'joe';
This is quite common and very helpful. Another option is to do:
name || (name = 'joe');
filetype off " required | |
" set the runtime path to include Vundle and initialize | |
set rtp+=~/.vim/bundle/Vundle.vim | |
call vundle#begin() | |
Plugin 'VundleVim/Vundle.vim' | |
Plugin 'tpope/vim-vinegar' | |
Plugin 'scrooloose/nerdtree' | |
Plugin 'ctrlpvim/ctrlp.vim' |
try { | |
client.doWork() | |
} catch (e) { | |
report(e) | |
return 'foo' | |
} |
/** | |
* Get a temporary URL for the file at a given path. | |
* | |
* @param {string} path | |
* @param {Date} expiration | |
* @return {string} | |
*/ | |
export function temporaryUrl(path, expiration) |
alias weather='curl -s wttr.in | sed -n "1,7p"' |
[ | |
"United States" => "us", | |
"Afghanistan" => "af", | |
"Albania" => "al", | |
"Algeria" => "dz", | |
"American Samoa" => "as", | |
"Andorra" => "ad", | |
"Angola" => "ad", | |
"Anguilla" => "ai", | |
"Antarctica" => "aq", |
Set a value to a variable if one doesn't exist, like this:
name = name || 'joe';
This is quite common and very helpful. Another option is to do:
name || (name = 'joe');
/** | |
* Consider using date fields instead of booleans. | |
* It works the same way, and now you know when the TRUE state happened. | |
*/ | |
order.shipped = true | |
order.shipped = '2017-01-01 00:00:00' | |
subscription.cancelled = true | |
subscription.cancelled = '2017-01-01 00:00:00' |
post.update(request().all()) | |
// Ability to detect if a certain attribute was changed after a model was updated | |
if (post.wasChanged('is_published') && post.is_published) { | |
Notification.send($subscriber, new NewPostNotification) | |
} |
/** | |
* Use a simple immediately-executing function to wrap the underlying "worker" function | |
* and return an object with properties for getting, setting, and checking existence | |
*/ | |
const Objectifier = (function() { | |
// Utility method to get and set objects that may or may not exist | |
const objectifier = function(splits, create, context) { | |
let result = context || window; | |
for(let i = 0, s; result && (s = splits[i]); i++) { |
/** | |
* Fires the web notification api. | |
*/ | |
if(window.Notification && Notification.permission !== "denied") { | |
// status is "granted", if accepted by user | |
Notification.requestPermission(function(status) { | |
let notify = new Notification('Title', { | |
body: 'I am the body text!', | |
// optional |