Skip to content

Instantly share code, notes, and snippets.

View kriscooke's full-sized avatar

kriscooke

  • British Columbia, Canada
View GitHub Profile

On the road to being a Power User

Take control of your development environment by using more of the keyboard and less of the mouse/trackpad. As you write your code, use (Mac and Sublime) keyboard commands/shortcuts to, well... kill it!

Mastering your text editor and Operating System (OS) will make you a more efficient and impressive developer.

Power User Commands

Don't just read about these. If any of these are foreign / unfamiliar to you, be sure to practice them and make a mental note to use them when possible.

@kriscooke
kriscooke / ruby_webserver.rb
Last active August 29, 2015 14:07
Simplest Possible Ruby Web Server
# The Simplest Possible Ruby Web Server. It serves up all the files in the current directory;
# use when developing static HTML/JS pages locally without a backend framework like Rails or
# Sinatra and their associated servers. This was useful for me in avoiding XMLHTTPRequest errors
# in Chrome, triggered by running a page on the local file protocol and trying to AJAX request
# an API resource via HTTP. The browser will believe you are making a cross-origin request unless
# the request is coming from both the same domain as the requested resource AND via the same
# protocol (file/HTTP/etc).
ruby -run -e httpd . -p 3000

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@kriscooke
kriscooke / gist:8863c0aaf0f2fce1a957
Last active August 29, 2015 14:18
JS: Validate/Coerce arguments object to an array
function needsArray(a){
var args = Array.isArray(a)? a : Array.prototype.slice.call(arguments);
// Now, use args as an array
}
@kriscooke
kriscooke / gist:d410500df32a6e2ed6f6
Created April 4, 2015 22:42
Manufacture a string of specified length with a preset repeat value
String.prototype.repeat = function(count) {
return new Array(count+1).join(this);
};
@kriscooke
kriscooke / gist:574ac5f3c218c3b0c1ce
Created April 6, 2015 16:26
Reversing an array (replace Array.prototype.reverse())
Array.prototype.reverse = function() {
// .splice(0) Empties out the entire array and returns the removed elements to arr.
// (Uses deleteCount = Array.length)
var arr = this.splice(0);
// While arr.length is not falsy (arr.length > 0)
// Pop off the end of arr, and push it back into the empty "this" array:
while(arr.length) {
this.push(arr.pop());
}
@kriscooke
kriscooke / 0_reuse_code.js
Last active August 29, 2015 14:19
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@kriscooke
kriscooke / $_data.js
Created April 20, 2015 23:01
Updating data-attributes using jQuery plugins or $.data(): If updating a DOM element's data-attributes directly, do NOT expect the jQuery .data() method to reference the updated data-attribute. Instead, it stores an object in memory based on the initial value of the data-attribute (a string) and references that SAME object with every $item.data(…
// Original DOM element:
// <div id="item" data-tags="popcorn,chickens"></div>
// SET (for eg: based on an ajax response):
// The first call (with .attr) updates the DOM element only:
$item.attr('data-tags',response.tag); // "popcorn,chickens"
$item.attr('data-tags'); // "popcorn,chickens,dandelions"
// <div id="item" data-tag="popcorn,chickens,dandelions"></div>
$item.data('tags',response.tag); // [popcorn,chickens]
@kriscooke
kriscooke / descriptor.json
Created April 22, 2016 02:14
Example hydrolysis descriptor of a paper-dialog element
"{"type":"element","desc":"\nMaterial design: [Dialogs](https://www.google.com/design/spec/components/dialogs.html)\n\n`<paper-dialog>` is a dialog with Material Design styling and optional animations when it is\nopened or closed. It provides styles for a header, content area, and an action area for buttons.\nYou can use the `<paper-dialog-scrollable>` element (in its own repository) if you need a scrolling\ncontent area. See `Polymer.PaperDialogBehavior` for specifics.\n\nFor example, the following code implements a dialog with a header, scrolling content area and\nbuttons.\n\n <paper-dialog>\n <h2>Header</h2>\n <paper-dialog-scrollable>\n Lorem ipsum...\n </paper-dialog-scrollable>\n <div class=\"buttons\">\n <paper-button dialog-dismiss>Cancel</paper-button>\n <paper-button dialog-confirm>Accept</paper-button>\n </div>\n </paper-dialog>\n\n### Styling\n\nSee the docs for `Polymer.PaperDialogBehavior` for the custom properties available for styling\nthis e
@kriscooke
kriscooke / git-mv-with-history
Created May 6, 2016 01:10 — forked from emiller/git-mv-with-history
git utility to move/rename file or folder and retain history with it.
#!/bin/bash
#
# git-mv-with-history -- move/rename file or folder, with history.
#
# Moving a file in git doesn't track history, so the purpose of this
# utility is best explained from the kernel wiki:
#
# Git has a rename command git mv, but that is just for convenience.
# The effect is indistinguishable from removing the file and adding another
# with different name and the same content.