Skip to content

Instantly share code, notes, and snippets.

@jrickerd
jrickerd / gist:1468507
Created December 12, 2011 18:40
credit card check
String.prototype.isCreditCard() {
if (this.length > 19)
return (false);
return (parseInt(this) % 10 === 0)
}
@jrickerd
jrickerd / gist:1468774
Created December 12, 2011 19:47
closure
// Exercise 2 - Closures
// Wrap the following code in a closure and export only the "countdown" function.
// Code
(function(){
var index;
function log(){
console.log(index);
}
@jrickerd
jrickerd / gist:1469042
Created December 12, 2011 20:52
oo v func
// Exercise 1 - OO || !OO
// Define a data structure for cars (make and color), and a function
// that logs a string like "I'm a red Mercedes" to the console.
// Make two versions: a functional version, and a object-oriented version.
// Example call for functional version:
var Car = function(make, color) {
this.log = function() {
@jrickerd
jrickerd / gist:1469518
Created December 12, 2011 22:50
class
// 1. Write a class to support the following code:
// var thomas = new Person('Thomas');
// var amy = new Person('Amy');
// thomas.name // --> "Thomas"
// 2. Add a getName() method to all Person objects, that outputs
// the persons name.
@jrickerd
jrickerd / gist:1469761
Created December 13, 2011 00:07
memoize
Function.prototype.memoized = function(key) {
var originalFunction = this;
if (!('cache' in originalFunction))
originalFunction.cache = {};
if (key in originalFunction.cache) {
console.log('returning cached value ' + originalFunction.cache[key] + ' for ' + key);
return originalFunction.cache[key];
} else {
console.log('adding value to cache for ' + key);
return originalFunction.cache[key] = originalFunction(key);
@jrickerd
jrickerd / gist:1595522
Created January 11, 2012 16:38
SSH tunnel
ssh -f user@remote.com -L localport:local:remoteport -N
@jrickerd
jrickerd / gist:1595768
Created January 11, 2012 17:34
Max Packet Size
mysql --max_allowed_packet=100M -u root -p database < dump.sql
set global net_buffer_length=1000000;
set global max_allowed_packet=1000000000;
@jrickerd
jrickerd / gist:1623436
Created January 16, 2012 22:45
Rename Files
for f in *.jpeg; do mv $f ${f%.*}.jpg; done
@jrickerd
jrickerd / list_foreign_keys
Created January 18, 2012 20:18
List Foreign Keys by Database
select
TABLE_SCHEMA as 'database',
concat(table_name, '.', column_name) as 'foreign key',
concat(referenced_table_name, '.', referenced_column_name) as 'references'
from
information_schema.key_column_usage
where
referenced_table_name is not null;
@jrickerd
jrickerd / gist:1636726
Created January 19, 2012 00:26
Powershell set encoding
gc <file> | out-file -enc utf8 <file>