Skip to content

Instantly share code, notes, and snippets.

View rafbm's full-sized avatar

Rafael Masson rafbm

View GitHub Profile
if Array < Object
puts 'Cool, “<” can be used to test class inheritance.'
end
if Object > Array
puts 'Cool, works the other way too.'
end
@rafbm
rafbm / net_http_debug.rb
Created May 22, 2014 15:52
Net::HTTP provides instance-level debugging. Here’s how to toggle it globally with `Net::HTTP.debug=`.
# config/initializers/net_http_debug.rb
if Rails.env.development?
require 'net/http'
Net::HTTP.class_eval do
class << self
attr_accessor :debug
end
<!DOCTYPE html>
<head>
<style>
body { text-align: center }
h1 { font-size: 56px }
</style>
<link href="http://fonts.googleapis.com/css?family=Ruge+Boogie" rel="stylesheet">
<script>
WebFontConfig = { google: { families: [ 'Butterfly+Kids::latin' ] } }
;(function() {
raise FucktardError, 'You nuts?!?'
codeMirror.setOption('onDragEvent', function(cm, e) {
// Move the cursor as they drag.
var pos = codeMirror.coordsChar({left: e.x, top: e.y });
codeMirror.setCursor(pos);
codeMirror.focus();
var isImageDrop = e.type == 'drop' && e.dataTransfer.files && e.dataTransfer.files.length > 0 && e.dataTransfer.files[0].type && e.dataTransfer.files[0].type.indexOf('image/') > -1;
if (!isImageDrop) return;
event.preventDefault();
/**
* ♫ 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 / 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