Skip to content

Instantly share code, notes, and snippets.

View byrichardpowell's full-sized avatar

Richard Powell byrichardpowell

View GitHub Profile
@byrichardpowell
byrichardpowell / gist:3012468
Created June 28, 2012 16:53
is Credit Card
// taken from http://www.dreamincode.net/code/snippet154.htm
//
// Find the weaknesses, and clean up the code.
// Find at least 3 things you can make better!
//
// Test numbers (return true):
// 4111111111111111
// 378282246310005
// 5555555555554444
@byrichardpowell
byrichardpowell / gist:3012503
Created June 28, 2012 16:58
is Credit Card
function isCreditCard(CC) {
var sum = 0,
mul = 1,
l = CC.length,
i;
if ( l > 19 ) {
return false;
// Exercise 2 - Closures
//
// Wrap the following code in a closure and export only the "countdown" function.
//
// You're NOT ALLOWED TO CHANGE the existing code; you may only add code
// on top and/or below it!
myClosure = (function() {
var index;
// 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.
var logCar = function( car ) {
console.log( "I'm a " + car.color + " " + car.make );
// Part 1.
// Implement a function prototype extension that caches function results for
// the same input arguments of a function with one parameter.
//
// For example:
// Make sin(1) have the result of Math.sin(1), but use a cached value
// for future calls.
//
// Part 2.
// 1. Write a class to support the following code:
var Person = function( name ) {
this.name = name;
}
var thomas = new Person('Thomas');
var amy = new Person('Amy');
thomas.name // --> "Thomas"
// 1. Write a class to support the following code:
var Person = function( name ) {
this.name = name;
}
var thomas = new Person('Thomas');
var amy = new Person('Amy');
thomas.name // --> "Thomas"
( function($, undefined) {
// Truncates a wrapper & provides a more link to show the content in full
$.fn.truncate = function( c ) {
return this.each( function() {
// Trucate, add class, add more link
var $wrapper = $(this).css( { 'height' : c.height, 'overflow' : 'hidden'} ).addClass('truncated').after('<span class="truncate-more">more</span>');
@byrichardpowell
byrichardpowell / gist:3170027
Created July 24, 2012 13:56
jQuery matchHeight
// Adds a matchHeight method to jQuery/zepto.
// Takes a jquery/zepto collection and makes them all as tall as the tallest elements
// Ideal for equal column layouts
// ## Paramaters
// * None (run on a zepto collection instead)
// ## Returns
// The collection which it was run on
// ## Example
// $('#myDiv1, #myDiv2').matchHeight();
// #test
@byrichardpowell
byrichardpowell / gist:3181928
Created July 26, 2012 13:04
Ruby workshop ISBN
#!/usr/bin/env ruby
isbn_array = []
def to_isbn string
if ( string.gsub("\n", "") )
string.gsub!("\n", "")
end
if ( string.gsub!(" ", "") )
string.gsub!(" ", "")