Skip to content

Instantly share code, notes, and snippets.

View jamischarles's full-sized avatar

Jamis Charles jamischarles

View GitHub Profile
@jamischarles
jamischarles / .npm_install_autocomplete
Last active May 27, 2016 15:46
Make these changes to augment your local npm autocompletion to include autocomplete for `npm install`
#!/usr/bin/env bash #adding this to force silly gist highlighting
# If you are already using npm autocompletion via (https://docs.npmjs.com/cli/completion), I assume that you have some code in
# your .bashrc/.zshrc file. Follow the instruction below to avoid clobbering the npm autocomplete script.
#####################
#### FOR BASH change THIS (in your .bashrc file)
#####################
IFS=$'\n' COMPREPLY=($(COMP_CWORD="$cword" \
@jamischarles
jamischarles / es6_functions.js
Created October 13, 2015 16:51
es6 functions explained...
// method shorthand. ES6 version.
{
initialize() {},
doSomething() {}
}
// replaces (ES5)
{
@jamischarles
jamischarles / clearfix.css
Created October 10, 2012 20:01
Modern clearfix
/* (taken from bootstrap github conversation) */
/* Utility classes */
/* Clearfix */
/* Clearfix for modern browsers */
.cf:before,
.cf:after {
content: "";
display: table;
@jamischarles
jamischarles / sublime_shortcuts.markdown
Created October 10, 2012 19:17
Most useful Sublime Shortcuts

Usefulness is indicated by amount of stars.

All are currently Mac only

Expand selection to tag **

Shift + Cmd + A

Wrap selection with tag **

Ctrl + Shift + W

@jamischarles
jamischarles / anonymous_function.js
Created June 19, 2011 12:20
Self invoking anonymous function
//of this will execute privately without exposing the variables to the global object and without polluting the global namespace.
(function(){
console.log("runs");
function test(){
//console
console.log("test");
}
@jamischarles
jamischarles / inject_script_node.js
Created June 19, 2011 12:12
Non blockin JS script node insertion with a callback
var headID = document.getElementsByTagName("head")[0];
//create new script
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
//add callback
newScript.onload = function(){ alert("loaded");};
newScript.src = 'http://yui.yahooapis.com/3.2.0/build/yui/yui-min.js';
@jamischarles
jamischarles / YIU_3_getNode.js
Created February 14, 2011 17:39
YUI: pass in raw node OR id in YUI 3
var getNode = function(el) {
//fetch the node by selector, or wrap it in a new YUI Node instance
return Y.one('#' + el) || new Y.Node(el);
};
//from http://stackoverflow.com/questions/4892051/how-can-i-normalise-a-javascript-object-to-a-dom-element-with-yui3
@jamischarles
jamischarles / YUI_new_module.js
Created February 8, 2011 13:36
This is a great way to define modules for the YUI loader and ensuring the dependencies get pulled in
YUI.add('breeze-nav', function(Y) {
Y.namespace('bb.session.Nav');
bb.session.Nav = function() {
// expose an API
// this in here will execute when it's pulled in through YUI().use()
};
@jamischarles
jamischarles / curry.js
Last active September 24, 2015 05:19
A simple example of currying in JS
// This is a 'curried' function. If it receives less params than it expects, it returns a function which expects the rest of the params.
function add(a, b) {
// if 2nd param wasn't passed, return a function that holds the 1st param via closure, but expects another param.
if (typeof b === "undefined") {
return function(c) {
a + c;
}
}
// if 2 params are passed return the result
@jamischarles
jamischarles / gitmove_several.sh
Last active August 29, 2015 14:18
Move Several git files over to a new repo with history. Very optimistic about errors
#!/bin/bash
# $ ./gitmove [destGitRepo] [src_file]
DEST_FOLDER=$1
# this will take all parameters AFTER the first. So you can give a list, or a glob (which is expanded into separate params)
SOURCE_FILES="${@:2}"
# SOURCE_FILE=$2
STARTING_FOLDER=$(pwd)