Skip to content

Instantly share code, notes, and snippets.

var validateAgeOlderOrExactly = function(date_string, age_limit_year, age_limit_month) {
var ageLimitDate, birthDate, today;
if (age_limit_month == null) {
age_limit_month = 0;
}
today = new Date();
birthDate = new Date(date_string);
ageLimitDate = new Date(today.getFullYear() - age_limit_year, today.getMonth() - age_limit_month, today.getDate());
return birthDate <= ageLimitDate;
};
switch dots.html().length
when 3 then dots.html("")
when 2 then dots.html("...")
when 1 then dots.html("..")
when 0 then dots.html(".")
else dots.html("...")
require 'net/http'
module Net
class HTTP
def self.enable_debug!
raise "You don't want to do this in anything but development mode!" unless Rails.env == 'development'
class << self
alias_method :__new__, :new
def new(*args, &blk)
instance = __new__(*args, &blk)
instance.set_debug_output($stderr)
(function (){
var ua = navigator.userAgent.toLowerCase();
var android = /Android/gi.test(ua);
var iOS = /(iPad|iPhone|iPod)/gi.test(ua);
if(android) { $("body").addClass("device-running-android"); }
if(iOS) { $("body").addClass("device-running-ios"); }
if(!iOS && !android) { $("body").addClass("device-not-running-ios-or-android"); }
})();
@jcsrb
jcsrb / style.js
Last active August 29, 2015 14:12 — forked from potch/style.js
// Bad
"Your Framework Sucks."
// Bad
"Browserify? Have you heard about WebPack?"
// Bad
"Ember vs Angular: 10 Things You Should Know"
#/bin/bash
#-- Script to automate https://help.github.com/articles/why-is-git-always-asking-for-my-password
REPO_URL=`git remote -v | grep -m1 '^origin' | sed -Ene's#.*(https://[^[:space:]]*).*#\1#p'`
if [ -z "$REPO_URL" ]; then
echo "-- ERROR: Could not identify Repo url."
echo " It is possible this repo is already using SSH instead of HTTPS."
exit
fi
<!--[if lte IE 6]>
<style type="text/css">
#ie6msg{border:3px solid #090; margin:8px 0; background:#cfc; color:#000;}
#ie6msg h4{margin:8px; padding:0;}
#ie6msg p{margin:8px; padding:0;}
#ie6msg p a.getie8{font-weight:bold; color:#006;}
#ie6msg p a.ie6expl{font-weight:normal; color:#006;}
</style>
<div id="ie6msg">
<h4>Did you know that your browser is out of date?</h4>
@jcsrb
jcsrb / gist:658004
Created November 1, 2010 11:14
jQuery based script to prepand imagelinks in Apache Directory Listing
jQuery('a').filter(function() {
return jQuery(this).attr('href').match(/\.(jpg|png|gif|JPG)/);
}).prepend(function(index,html){return '<img src="'+html+'" />'});
// jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
// http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
jQuery.Event.prototype = {
preventDefault: function() {
this.isDefaultPrevented = returnTrue;
var e = this.originalEvent;
if ( !e ) {
return;
}
@jcsrb
jcsrb / core_extensions.rb
Created July 7, 2011 11:08
turn a Array of Fixnums into Array of Ranges
class Array
# Array#to_ranges
# Converts an array of values to an array of ranges. For example,
# [2, 3, 33, 34, 110, 1, 111, 112, 4].to_ranges => [1..4, 33..34, 110..112]
def to_ranges
return nil unless self.all?{|item| item.is_a?Fixnum}
self.sort.uniq.inject([]) do |spans, n|
if spans.empty? || spans.last.last != n - 1
spans + [n..n]
else