Skip to content

Instantly share code, notes, and snippets.

@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

<ul class="main-navigation">
<li class="main-navigation__menu-item main-navigation__menu-item--active">
<span class="main-navigation__menu-item-title">Want this</span>
</li>
<li class="main-navigation__menu-item main-navigation__menu-item--active">
<span class="main-navigation__menu-item-title main-navigation__menu-item--active-title">Not this</span>
</li>
</ul>
@joelcox
joelcox / index.html
Created April 9, 2019 13:24
RobinHQ Ember
index.
@joelcox
joelcox / controllers.application.js
Last active January 23, 2020 19:27
setInterval DOM
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
init() {
this._super();
this.set('model', [1, 2, 3]);
setInterval(() => {
console.log(Math.random());
@joelcox
joelcox / highlight.swift
Created September 23, 2015 18:41
Swift implementation to highlight Cocoa UI elements (http://stackoverflow.com/a/25984748/316803)
NSColor.selectedMenuItemColor().set()
NSRectFillUsingOperation(dirtyRect, .CompositeSourceOver);
if (dirtyRect.size.height > 1) {
let heightMinus1 = dirtyRect.size.height - 1
let currentControlTint = NSColor.currentControlTint()
var startingOpacity: CGFloat = 0.09
if currentControlTint == .BlueControlTint {
startingOpacity = 0.16