Skip to content

Instantly share code, notes, and snippets.

@codeincontext
codeincontext / gist:1285806
Last active January 25, 2023 17:05
Javascript function to show how long ago a timestamp was as a pretty string
function timeAgo(time){
var units = [
{ name: "second", limit: 60, in_seconds: 1 },
{ name: "minute", limit: 3600, in_seconds: 60 },
{ name: "hour", limit: 86400, in_seconds: 3600 },
{ name: "day", limit: 604800, in_seconds: 86400 },
{ name: "week", limit: 2629743, in_seconds: 604800 },
{ name: "month", limit: 31556926, in_seconds: 2629743 },
{ name: "year", limit: null, in_seconds: 31556926 }
];
@codeincontext
codeincontext / .bash_profile
Created October 27, 2011 11:38
.bash_profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
alias ping='ping -c 5'
alias ..='cd ..'
export CLICOLOR=1
function mkcd() {
[ -n "$1" ] && mkdir -p "$@" && cd "$1";
}
@codeincontext
codeincontext / gist:1353299
Created November 9, 2011 22:18
Function to repeatedly rotate between frames in an animation
function startAnimation() {
var i = 0;
var frameId = 0;
frames = $('.animation').find('li');
setInterval(function(){
if (frames.length) {
$(frames[frameId]).css('opacity', '0');
frameId = i++ % frames.length;
$(frames[frameId]).css('opacity', '1');
@codeincontext
codeincontext / gist:1365709
Created November 15, 2011 00:38
How many people are you following that aren't following you back on twitter
require 'twitter'
require 'redis'
Twitter.configure do |config|
config.consumer_key = CONSUMER_KEY
config.consumer_secret = CONSUMER_SECRET
config.oauth_token = TOKEN
config.oauth_token_secret = SECRET
end
@codeincontext
codeincontext / encoded.rb
Created November 23, 2011 22:49
This Ruby script will decrypt itself, execute a payload, and re-encrypt itself with a new key
require 'OpenSSL';require 'Base64';c = 'A9owhIxrZX3kHFGKqn0dOoybYZWBQxGygOviG1ane9/aDwezVW/AzDDoD6ZZTdLkjd3RAxbkHD9rHSa+Z7js6QzylYBnMsPjZYVzEE//g4/2anuBI9aWwKjqj45T1UkO4cxKtziUzwPB5rXt5Rx1AnwzUeI0brlqcqNctzLp4aVZbfbW4p0gHUTAej3wk4uD3+ioqMe4hDGUQWiUp9p7IDHancMhhQg60O9990TFev54YUBokJxj09Wo8SsMbw7M/Xy/xJ3gbc9tx9fBGGASJcTkCdHqYYU4kOieogC9AtHM54xsfhKu5s5okyFPHaN9ylboEmB0IlZnwf7GhG6IOuOAC9o7jI31mrRbjTiyYglcNPf5yrVepPpZOlJ+sjNKIf6meDdrmIdv2iyMAvIVfoVEOmnzyFAE6r7sCQ3nyAHHtdDKErSWkhWsPgLg5Gl5b3pEazHVrafB2aeqYKeTzNGejxjVXMId2K2v1I0MqUgTLlJ2gyAWHtUcV63yX6DplqCph4vylwap0JH+dp8kltUimeC/qKYSFZL45lhFlNoMDF4O89ekizZmljCMtVgll1Amzt5/xDAcHMXoEz7iZ3xTArDbt0FbX6HjABPvcCJTAhl8kDV0BqILXfJycJ8rKvlXJ5pqoryYZJoNqTOvaiRiRHokX5xM07ej8japZeYZq2F20ejJL1oB13Q11LuGS2YnjlcDtxbdDcHJikUj28GmI19/lZenj1IiktoO1zPlPyFXO8GZXTM5y8RbVM/WyUBNPh3Peae7PcAfD6SPZLJAbOd6Xe46H4yNv2kuxV3HJVQc37+Sp5ALWxEIdDA+GLNbLvTdLo9T1mUJbO/vHn0iHHIrwccfaY6IyFVQQW/9TSVUka7ulL7QuSu8gsD1/5BYhZJAX4Un6ZOl35UR4onoTGnP1DTrOa7yp9RLAfvrd0iaSXNF3aZkLO8n7X6LmqUr2krCtEb2uVANeUfr3+wU
@codeincontext
codeincontext / linkify.js
Created December 20, 2011 12:17
Linkify urls in a JS string
// I didn't do this. This guy did: http://stackoverflow.com/a/7123542/288660
if(!String.linkify) {
String.prototype.linkify = function() {
// http://, https://, ftp://
var urlPattern = /\b(?:https?|ftp):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*[a-z0-9-+&@#\/%=~_|]/gim;
// www. sans http:// or https://
var pseudoUrlPattern = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
Handlebars.registerHelper('numberWithCommas', function(x) {
return x.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
});
@codeincontext
codeincontext / gist:1831643
Created February 14, 2012 23:32
Upload a random twitter avatar from a directory
#!/usr/bin/env ruby
# Heavily based on https://github.com/ip2k/twitter-avatar-update
# ==== Gems ====
require 'twitter_oauth'
require 'oauth'
require 'nokogiri'
require 'open-uri'
require 'yaml'
@codeincontext
codeincontext / SKUserData.m
Created March 13, 2012 01:10
SKUserData singleton save-on-write dictionary subclass
#import <Foundation/Foundation.h>
@interface SKUserData : NSMutableDictionary
+ (id)sharedInstance;
@end
@codeincontext
codeincontext / gist:2109123
Created March 19, 2012 11:55
log BB events
console.log("triggered: "+eventName+" for "+(this.get('name')||this.get('description')||'collection'))