Skip to content

Instantly share code, notes, and snippets.

@joelcox
joelcox / Git cheat sheet
Created April 4, 2011 09:23
WIP git cheat sheet
#
# Various handy commands
#
# Change the author of the previous commit
git commit --amend --author="Name <name@domain.com>"
# Set a global .gitignore
git config --global core.excludesfile ~/.gitignore
@joelcox
joelcox / post-receive
Created May 11, 2011 08:12
Add commit hash constant
#!/bin/bash
# Append the latest commit hash to your PHP constants file after the Git repository received a push.
# Path to constants file
CONST_PATH = ../../application/config/constants.php
# Ask git for the last abbreviated commit hash
HASH = `git log -1 --pretty=format:"%h"`
@joelcox
joelcox / gist:1173336
Created August 26, 2011 12:47
Time ago
<?php
function time_ago($time)
{
$time = (is_numeric($time) ? $time : strtotime($time));
$delta = time() - $time;
switch (TRUE)
{
case ($delta < 0):
@joelcox
joelcox / gist:1271085
Created October 7, 2011 18:57
Vim cheatsheet

EasyMotion

\w get into target mode.

Surround

viws<strong> wrap the word under the cursor in tags.

@joelcox
joelcox / gist:2621608
Created May 6, 2012 10:49
KMeans plot
import os
import sys
import csv
sys.path.insert(0, os.path.abspath('../miner/'))
import miner.utils
import miner.clustering
def render_to_file(space, clusters):
@joelcox
joelcox / gist:6641424
Last active December 23, 2015 13:19
Bind to multimedia keys

Bind to multimedia keys

Web applications are increasingly taking over the functions of native applications. This year has seen an increase of (streaming) audio web applications, such as Rdio, Spotify, Pandora, etc. These applications are long-running applications and provide multimedia to the user, often while the user is doing something else.

Interaction with this type of application works the same as with other applications: the user brings the tab/window in focus and manipulates the application through mouse, keyboard or other input device. Bringing the application into focus is required in order to interact with the application and thus requires the user to get out of the current workflow.

In native applications this problem is fixed by letting applications bind to specific multimedia buttons situated on the keyboard. These buttons serve as a way to interact with the media player without bringing the application into focus. This is currently impossible for web applications for t

Keybase proof

I hereby claim:

  • I am joelcox on github.
  • I am joelcox (https://keybase.io/joelcox) on keybase.
  • I have a public key whose fingerprint is 95EE 753A 4045 B7C9 510C 12BF 126D 73CE D1E8 5215

To claim this, I am signing this object:

@joelcox
joelcox / promise.js
Created February 19, 2015 09:33
Dealing with basic promises
var promise = new Ember.RSVP.Promise(function(resolve, reject) {
console.log('Promise is pending');
setTimeout(function() {
if (Math.random() < 0.7) {
resolve({'status': 'ok'});
}
reject('Whoops, something went wrong');
}, 1000);
@joelcox
joelcox / promise-chained.js
Last active August 29, 2015 14:15
Chained promises
promise.then(function(response) {
console.log(response);
return promise;
}).then(function(anotherResponse) {
console.log(anotherResponse);
}).catch(function(error) {
console.error(error);
});
@joelcox
joelcox / promise-parallel.js
Last active August 29, 2015 14:15
Parallel promises
actions: {
submitForm: function() {
var model = this.store.createRecord('post');
this.resolveKeywords(controller.get('postKeywords')).then(function(keywords) {
model.get('keywords').pushObjects(keywords);
return model.save();
}).then(function() {
controller.transitionToRoute('post', model);
});