Skip to content

Instantly share code, notes, and snippets.

@atree
atree / redis-hash-loop.js
Created January 17, 2013 16:30
Node JS - Iterating over redis keys, grabbing value from hash for view.
exports.list = function(req, res) {
var return_dataset = [];
client.keys('*', function(err, log_list) {
var multi = client.multi();
var keys = Object.keys(log_list);
var i = 0;
keys.forEach(function (l) {
client.hget(log_list[l], "modified_at", function(e, o) {
@atree
atree / gist:4356960
Last active December 10, 2015 01:18
Trim video via ffmpeg and command line
# This command takes LongVide.m4v and extracts 10 minutes of video starting from 21 minutes in.
ffmpeg -i LongVideo.m4v -vcodec copy -acodec copy -ss 00:21:00 -t 00:10:00 ShortVideo.m4v
@atree
atree / apiproxy.php
Created December 18, 2012 08:41
PHP API proxy with caching build in.
<?php
// apiproxy [atree 12/18/2012]
// In order for the cache to work properly,
// there needs to be a folder under this script's folder
// named temp with the 777 permissions set.
// Don't fret if you don't have this, it will just continue on
//
// this cache will write to here every 12 hours (default)
//
@atree
atree / javascript-singleton.js
Created December 15, 2012 08:17
I always forget how to create javascript singleton objects.
var obj_ea = new function() {
this.url = 'some_ajax_url.php';
this.submit_actions = function() {
var data = {
'id': 'e04b7291',
'email': $('#email1').val(),
'status': $('#status1').val(),
'email_pre_cust': $('#email4').attr('checked'),
'email_pre_fire': $('#email5').attr('checked'),
'email_approved': $('#email3').attr('checked'),
@atree
atree / gist:4284006
Created December 14, 2012 09:25
Image resizing script
#!/bin/bash
# remove spaces from filename
IFS=$'\n';for f in `find .`; do file=$(echo $f | tr [:blank:] '_'); [ -e $f ] && [ ! -e $file ] && mv "$f" $file;done;unset IFS
# resize jpg
for i in *.{jpg,JPG}; do echo $i; convert $i -resize 800x600 $i; mogrify -quality 80% $i; done
@atree
atree / gist:4283993
Created December 14, 2012 09:23
Current VIM Settings
set guifont=Andale\ Mono:h11
colorscheme Elflord
nmap "+gP
imap a
vmap "+y
set guioptions-=T "remove toolbar
set guioptions-=r "remove right-hand scroll bar
filetype indent on
set expandtab
set tabstop=4
@atree
atree / gist:4283939
Created December 14, 2012 09:15
Quick javascript to validate credit cards (MC, VISA, AMEX, DISCOVER)
cards = ['5555555555554444', '4222222222222', '4111111111111111', '4012888888881881', '378282246310005', '371449635398431', '378734493671000', '6011111111111117']
regex = /^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9][0-9])[0-9]{12})|(3[47][0-9]{13}))$/
for (c in cards) { console.log(regex.test(cards[c])) }
@atree
atree / gist:4283900
Created December 14, 2012 09:09
Quick python script to truncate CSV data elements.
#/usr/bin/python
import csv
fout = open('ptype_out.csv', 'w')
with open('ptype_in.csv', 'rb') as fin:
fin_reader = csv.reader(fin, delimiter='|')
for row in fin_reader:
new_row = ', '.join(row)