Skip to content

Instantly share code, notes, and snippets.

View rafbm's full-sized avatar

Rafael Masson rafbm

View GitHub Profile
/**
* ♫ A Little Reminder About JavaScript Boolean Evaluations ♫
*/
!!0 // false
!!NaN // false
!![] // true
!!new Array // true
/**
* ♫ Firefox-Proof Focus Styles ♫
*
* Define your focus styles this way: a.focus { outline: 2px solid hotpink; }
* Only mini-tiny-pico quirk is a slight delay before the focus style appears.
*
* https://gist.github.com/536465
*/
$('a').bind({
@rafbm
rafbm / jquery.in-groups-of.js
Created December 15, 2010 14:21
Returns an array of jQuery objects, grouped by specified number of elements.
/*
* Returns an array of jQuery objects, grouped by specified number of elements.
*
* Say you have 17 <frameset> tags on your page...
*
* $('frameset').inGroupsOf(7); // => [ jQuery[0..6], jQuery[7..13], jQuery[14..16] ]
*
*/
$.fn.inGroupsOf = function( countPerGroup ) {
@rafbm
rafbm / clean-markup-line-numbers.html
Created March 27, 2011 22:23
<table>-free way to display <pre> line numbers that don’t mess up the clipboard.
<html>
<head>
<meta charset="utf-8">
<title>Clean-Markup Line Numbers™</title>
<style>
body {
width: 800px;
margin: 0 auto;
}
@rafbm
rafbm / wtf.js
Created August 20, 2011 20:49 — forked from jtaby/wtf.js
this.$().animate({
scale: 1,
translateX: 0,
translateY: 0,
top: document.body.scrollTop,
left: 0,
width: window.innerWidth,
height: window.innerHeight
@rafbm
rafbm / css-compressor.js
Created August 27, 2011 19:26
CSS compressor
var compressCSS = function(css) {
return css.trim()
.replace(/\s*([{}:;,>+~])\s*/g, '$1') // whitespace
.replace(/;}/g, '}') // trailing semicolons
.replace(/#(\w)\1(\w)\2(\w)\3\b/g, '#$1$2$3') // hex colors
.replace(/(\[[^=]+=)("|')([^"'\s]+)(\2)(\])/g, '$1$3$5') // useless attribute selector quotes
.replace(/\(('|")([^"'\s]+)(\1)\)/g, '($2)') // useless function quotes
}
@rafbm
rafbm / gsub_array.rb
Created September 16, 2011 16:42
String#gsub version that takes two arrays: one as searches and one as replacements
class String
def gsub_array! find, replace
find.each_index do |i|
self.gsub! find[i], replace[i]
end
self
end
def gsub_array find, replace
str = self.clone
@rafbm
rafbm / gist:1334218
Created November 2, 2011 17:02 — forked from angus-c/gist:1334100
Arguments default value (allow empty args)
function func(a, f) {
return function(args) {
args = args || {};
args.__proto__ = a;
f.call(this, args);
};
};
var f = func({ foo: 10, bar: 20 }, function(args) {
@rafbm
rafbm / git_aliases.sh
Created December 9, 2011 13:09
Git Aliases for the Minimalist
alias glog="git log --oneline --decorate"
alias gstatus="git status -sbu"
alias gdiff="git diff"
alias gadd="git add -p"
alias gcommit="git commit -v"
alias grebase="git rebase -i"
alias gpull="git pull --rebase origin"
alias gpush="git push origin"
alias gstash="git stash save"
alias gpop="git stash pop"
@rafbm
rafbm / config.ru
Created January 28, 2012 23:29
Example Sinatra app using the Namespace extension from Sinatra::Contrib
require 'sinatra/base'
require 'sinatra/namespace'
class MyApp < Sinatra::Base
register Sinatra::Namespace
get '/' do
'Home'
end