Skip to content

Instantly share code, notes, and snippets.

View icodejs's full-sized avatar

Tahir Joseph icodejs

View GitHub Profile
@icodejs
icodejs / delay.js
Created April 20, 2012 09:08
Delay the manipulation of a input value for predefined length of time
var delay = (function(){
var timer = 0;
return function(callback, ms){
clearTimeout (timer);
timer = setTimeout(callback, ms);
};
}());
$('.basket-quantity').keyup(function() {
var $that = $(this);
@icodejs
icodejs / price_format.js
Created April 20, 2012 10:03
Thousands comma separator
var price_format = (function () {
var rgx = /(\d+)(\d{3})/;
return function (nStr) {
var x = String(nStr).split('.'),
x1 = x[0],
x2 = x.length > 1 ? '.' + x[1] : '';
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
@icodejs
icodejs / jquery.seminar-enquiry.js
Created April 23, 2012 08:18
Calculate price based on no. of places entered
$(function () {
var $places = $('#secondaryContent #places'),
$payment_amount = $('#secondaryContent #payment_amount'),
singular_amount = 145.00;
var delay = (function () {
var timer = 0;
return function (callback, ms) {
clearTimeout(timer);
timer = setTimeout(callback, ms);
@icodejs
icodejs / delivery_date.js
Created April 23, 2012 08:23
JQ UI Date picker - Force users to choose a delivery date in the future and take into account weekends
function days_between(date1, date2) {
var one_day = 1000 * 60 * 60 * 24,
date1_ms = date1.getTime(),
date2_ms = date2.getTime(),
difference_ms = Math.abs(date1_ms - date2_ms);
return Math.round(difference_ms / one_day);
}
@icodejs
icodejs / Batchelor.js
Created April 23, 2012 08:36
Run DD Analytics ajax reports in batches
/*
* March 2012 - TSJ
* -----------------------------------------------------------------
* Loads charts in batches using Batchelor due to the maximum number
* of http request in most browsers being limited to 6.
*
*/
var reportsPerBatch = 6;
@icodejs
icodejs / jquery.background.js
Created April 23, 2012 14:49
Multimedia background
/**
*
* Demo URL: http://seo-stats-demo.datadial.net/test/tj/background/
*
* This plugin will take a media type (colour, img, video).
* - Images: collection of URLs
* - Colour: hex values
* - Video: object with video type (youtube, vimeo) and url
*
* The plugin will allow the user to pass in a REST url so that media can be
# Define a method to convert Cartesian (x,y) coordinates to Polar
def polar(x,y)
theta = Math.atan2(y,x) # Compute the angle
r = Math.hypot(x,y) # Compute the distance
[r, theta] # The last expression is the return value
end
# Here's how we use this method with parallel assignment
distance, angle = polar(2,2)
# Determine US generation name based on birth year
# Case expression tests ranges with ===
generation = case birthyear
when 1946..1963: "Baby Boomer"
when 1964..1976: "Generation X"
when 1978..2000: "Generation Y"
else nil
end
#
# This class represents a sequence of numbers characterized by the three
# parameters from, to, and by. The numbers x in the sequence obey the
# following two constraints:
#
# from <= x <= to
# x = from + n*by, where n is an integer
#
class Sequence
Useful gem sub commands:
gem list # List installed gems
gem enviroment # Display RubyGems configuration information
gem update rails # Update a named gem
gem update # Update all installed gems
gem update --system # Update RubyGems itself
gem uninstall rails # Remove an installed gem