Skip to content

Instantly share code, notes, and snippets.

View codearmorygists's full-sized avatar

codearmorygists

View GitHub Profile
// Simple JavaScript Templating
// John Resig - http://ejohn.org/ - MIT Licensed
(function(){
var cache = {};
this.tmpl = function tmpl(str, data){
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
/* Simple JavaScript Inheritance
* By John Resig http://ejohn.org/
* MIT Licensed.
*/
// Inspired by base2 and Prototype
(function(){
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
// The base Class implementation (does nothing)
this.Class = function(){};
@codearmorygists
codearmorygists / ajaxappend.js
Created September 19, 2012 22:28
AjaxAppend: Autoappend JSON returned from an AJAX call, formatted by Underscore Templating Engine http://tybenz.com/ajaxAppend
/*!
* ajaxAppend v1.0 - a jQuery Plugin by Tyler Benziger
* http://tylerbenziger.github.com/ajaxAppend
*
* Copyright 2012, Tyler Benziger
*
* Date: Tuesday June 26, 2012 09:47AM
*/
(function( $, undefined ){
@codearmorygists
codearmorygists / rng.js
Created September 19, 2012 22:42
Random Name Generator
gLastNames = [
"Wood",
"May",
"Gallagher",
"Steele",
"Solomon",
"Monroe",
"Bender",
"Hamilton",
"Chung",
@codearmorygists
codearmorygists / curl.php
Created September 19, 2012 22:44
PHP curl
function curl_download($Url){
// is cURL installed yet?
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
// OK cool - then let's create a new cURL resource handle
$ch = curl_init();
@codearmorygists
codearmorygists / rpg.php
Created September 19, 2012 22:45
Random Readable Password
function random_readable_pwd($length=10){
// the wordlist from which the password gets generated
// (change them as you like)
$words = 'dog,cat,sheep,sun,sky,red,ball,happy,ice,';
$words .= 'green,blue,music,movies,radio,green,turbo,';
$words .= 'mouse,computer,paper,water,fire,storm,chicken,';
$words .= 'boot,freedom,white,nice,player,small,eyes,';
@codearmorygists
codearmorygists / checkall.js
Created September 19, 2012 22:46
Check/uncheck all checkboxes in a form
function checkAll() {
var theForm, z = 0;
theForm = form_1;
for(z=0; z<theForm.length;z++){
if(theForm[z].type == 'checkbox'){
theForm[z].checked = true;
}
}
}
@codearmorygists
codearmorygists / geolocate.rb
Created September 19, 2012 22:50
Find City and State from Zipcode
require 'net/http'
require 'uri'
require "rexml/document"
# Retrieves US Location data based on a passed in Zipcode. Uses
# Google Maps geocoding service to retrieve a Hash of city, state, and zip
# For more info on the service see: <a href="http://code.google.com/apis/maps/documentation/geocoding/" >http://code.google.com/apis/maps/documentation/geocoding/</a>
#
# example:
# puts get_location_data(97030).inspect
@codearmorygists
codearmorygists / page_count.rb
Created September 19, 2012 23:05
Recurse directory and count all pages in pdf files
require 'rubygems'
require 'pdf/reader'
class TotalPages
def count(dir)
@conv_directory = dir
## I output the directory argument as a test with the below line -
## mostly to make sure that passing '.' gets current dir
# puts @conv_directory
@codearmorygists
codearmorygists / resize.sh
Created September 19, 2012 23:09
Resize images in directory
find SOURCE_DIR -print -name "*.jpg" -execdir convert -resize 800x800 -quality 80 '{}' 'TARGET_DIR/{}' ;
find Pictures/ -print -name "*.jpg" -execdir convert -resize 800x800 -quality 80 '{}' '/tmp/test/{}' ;