Skip to content

Instantly share code, notes, and snippets.

<!--[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
@jcsrb
jcsrb / document_series.rb
Created July 7, 2011 11:11
find the gap
class DocumentSeries < ActiveRecord::Base
#...
#
# this returns an array of the free counter numbers in the series
#
def empty_series_counter_slots
(self.counter_start .. self.counter_current).to_a - self.documents.collect{|d| d.document_series_counter}
end
@jcsrb
jcsrb / gist:1081548
Created July 13, 2011 23:05
get avatar from google profiles, facebook, gravatar, twitter, tumblr
function get_avatar_from_service(service, userid, size) {
// this return the url that redirects to the according user image/avatar/profile picture
// implemented services: google profiles, facebook, gravatar, twitter, tumblr, default fallback
// for google use get_avatar_from_service('google', profile-name or user-id , size-in-px )
// for facebook use get_avatar_from_service('facebook', vanity url or user-id , size-in-px or size-as-word )
// for gravatar use get_avatar_from_service('gravatar', md5 hash email@adress, size-in-px )
// for twitter use get_avatar_from_service('twitter', username, size-in-px or size-as-word )
// for tumblr use get_avatar_from_service('tumblr', blog-url, size-in-px )
// everything else will go to the fallback
// google and gravatar scale the avatar to any site, others will guided to the next best version
- if @content_for_banner
= yield(:banner)
@jcsrb
jcsrb / .htaccess
Created December 1, 2011 13:03
A Generic .htaccess File
#taken from http://www.vipan.com/htdocs/htaccess.shtml
# Place a .htaccess file in each directory you want to protect.
########################################################################
# SECURITY / ACCESS CONTROL #
# If the web server's AllowOverride allows AUTHCONFIG to be overridden #
########################################################################
#
# Save both .htpasswd and .htgroup files in a directory above "documentroot" directory
# (e.g. not in or below /apache/htdocs) but could be below "serverroot" directory
@jcsrb
jcsrb / scopes.rb
Created December 10, 2011 12:33
usefull scopes for Rails3
#include in your model
#include Scopes
module Scopes
def self.included(base)
#scope for NOT IN
#usage:
# Model.not_in(1)
# Model.not_in(1,2,4)
# Model.not_in([1,2,4])
# Model.not_in(1,2,3,[4,5,6])
@jcsrb
jcsrb / Gemfile
Created December 15, 2011 15:21
Getting ruby-debug working on ruby 1.9.3
#...
group :development do
gem 'mongrel', '>= 1.2.0.pre2'
gem 'linecache19', :git => 'git://github.com/mark-moseley/linecache'
gem 'ruby-debug-base19x', '~> 0.11.30.pre4'
gem 'ruby-debug19'
end
#...