Skip to content

Instantly share code, notes, and snippets.

View danguilherme's full-sized avatar
👨‍💻
npx danguilherme

Guilherme Ventura danguilherme

👨‍💻
npx danguilherme
View GitHub Profile
@danguilherme
danguilherme / loadScript.js
Last active August 29, 2015 14:07
Useful Scripts
function loadScript(url,callback) {
var element = document.createElement("script");
element.src = url;
document.body.appendChild(element);
element.onload = callback;
return element;
}
@danguilherme
danguilherme / Enum.js
Last active August 29, 2015 14:14
JavaScript Enum
function Enum(items, startingValue) {
var count = startingValue || 0,
item;
for (var i = 0; i < items.length && (item = items[i]) ; i++) {
var splitted = item.split(':');
if (splitted.length == 2) {
count = Number(splitted[0]);
item = splitted[1];
}
this[this[item] = count++] = item;
@danguilherme
danguilherme / example_output.sql
Created March 23, 2015 13:13
SQL Server - Truncate all tables
-- COMING SOON
@danguilherme
danguilherme / useful_scripts.user.js
Last active August 29, 2015 14:19
All my public user scripts
// ==UserScript==
// @name Useful Scripts
// @version 1.3.0
// @description Useful scripts for developers, to be loaded and used in every page
// @match http://**/*
// @author Guilherme Ventura
// @downloadURL https://rawgit.com/danguilherme/2e6e913ebdd491b06225/raw/useful_scripts.user.js
// @grant unsafeWindow
// ==/UserScript==
@danguilherme
danguilherme / git_commands.sh
Created April 26, 2015 04:34
Git commands cheat sheet
# BRANCHES
git branch # list all local branches
git branch -a # list all branches (local and remote)
# Clone remote branches - http://stackoverflow.com/a/72156/1574059
git checkout -b branch-name origin/branch-name # create local branch and set it to track origin/branch-name
@danguilherme
danguilherme / aliases
Last active August 29, 2015 14:24
Alias file for Cmder
e.=explorer .
gl=git log --oneline --all --graph --decorate $*
ls=ls --color $*
pwd=cd
clear=cls
subl="C:\Program Files\Sublime Text 3\subl.exe" $*
atom="C:\Users\Guilherme\AppData\Local\atom\app-1.0.0\atom.exe" $*
eval=node -p $*
@danguilherme
danguilherme / git_configs.sh
Last active July 25, 2018 18:27 — forked from tacsio/Git Configs
My git config
git config --global user.name "Guilherme Ventura"
git config --global user.email "[email protected]"
git config --global push.default simple
git config --global color.ui true
git config --global alias.s status
git config --global alias.c checkout
git config --global alias.co checkout
@danguilherme
danguilherme / snippets.sh
Created February 29, 2016 00:54
Command Line Magic
# Create a symbolic link to conveniently run $app from the terminal:
sudo ln -s /path/to/$app /usr/local/bin/$app
@danguilherme
danguilherme / symlink.bat
Last active November 14, 2017 00:42
Windows symlink

And the famous answer is: it depends. Depends on the use case.

Use case #1: Optional parameters

If the parameters are optional, you may use a single parameter (generally named options) to receive and conditionally Object.assign the default values (mostly used in pre-ES6 code, but still has its use).

jQuery uses this approach in lots of functions. Here's an example from Angular's $http.get:

// No params
$http.get('https://httpbin.org/get');

// Optional params