Skip to content

Instantly share code, notes, and snippets.

View rafbm's full-sized avatar

Rafael Masson rafbm

View GitHub Profile
@rafbm
rafbm / markers.coffee
Created December 10, 2012 23:41
Little hack for using readable MM:SS time values in CoffeeScript
Number::m = (seconds = 0) ->
this * 60 + seconds
markers = [
0.m 36
1.m 14
1.m 48
2.m 23
2.m 56
3.m 30
@rafbm
rafbm / envy.rb
Created November 7, 2012 00:35
Language/framework agnostic support for per-project environment variables
#!/usr/bin/env ruby
command = ARGV.join(' ')
begin
env = File.read("#{Dir.pwd}/.env")
lines = env.strip.split("\n").reject{ |line| !line.match(/^\w+=/) }
variables = lines.join(' ')
exec "#{variables} #{command}"
@rafbm
rafbm / browsers.md
Last active October 11, 2015 08:48
My current browser testing arsenal

OS X

  • Latest Safari (6.0), Chrome and Firefox

Windows 7 VM

  • IE9
  • Chrome (latest)
  • Firefox (latest)
  • Safari 5.1

Windows XP VM #1

@rafbm
rafbm / meta-debug.css
Created August 27, 2012 01:04
CSS snippet for debugging meta descriptions and Open Graph tags with class
head, meta[name="description"], meta[property^="og:"] { display: block }
head {
position: relative;
z-index: 9999;
font: 21px/1.4 Didot;
color: #444;
-webkit-hyphens: auto;
padding: 2em;
background: #fff;
-webkit-font-smoothing: subpixel-antialiased;
@rafbm
rafbm / event.md
Created August 25, 2012 11:34
In most browsers, `event` is an ever-existing JavaScript variable which value changes depending on context

In most browsers, event is an ever-existing JavaScript variable which value changes depending on context.

Safari, Chrome and Opera:

<script>
  window.onload = function() {
    console.log(event) // Event (type: "load")
  }
  console.log(event) // undefined
@rafbm
rafbm / command.rb
Created August 22, 2012 03:45
Compile CoffeeScript to JavaScript TextMate command
#!/usr/bin/env ruby
# encoding: utf-8
error = `coffee -c #{ENV['TM_FILEPATH']} 2>&1`
if error == ''
puts "✔ compiled #{ENV['TM_FILEPATH'].sub(/\.coffee$/, '.js')}"
else
puts "❗#{error}"
end
@rafbm
rafbm / css-triangles.html
Created August 3, 2012 12:54
CSS Triangles
<style>
div {
width: 0; height: 0;
border-style: solid;
margin: 20px;
}
div:nth-child(odd) { border-width: 32px } /* edges */
div:nth-child(even) { border-width: 24px } /* corners */
.top { border-color: red transparent transparent transparent }
@rafbm
rafbm / ruby-setters-goodness.rb
Created July 16, 2012 21:49
Methods ending in “=” that accept a single argument will treat multiple arguments as an array.
# Methods ending in “=” that accept a single argument will treat multiple arguments as an array.
class Foo
def types=(array)
p array
end
end
foo = Foo.new
foo.types = [:bar, :baz, :quux] # => [:bar, :baz, :quux]
@rafbm
rafbm / onclickortouch.md
Created July 9, 2012 15:01
This is how I handle snappy taps on iOS.

This is how I handle snappy taps on iOS.

I create a little jQuery/Zepto “plugin” function:

$.fn.onClickOrTouch = (callback) ->
  if window.ontouchend != undefined # insanely clever touch detection
    this.each -> this._touchMoveCount = 0
@rafbm
rafbm / file.md
Created June 24, 2012 18:07
Would any Rails developer consider this bad practice?

Would any Rails developer consider this bad practice?

If so, why?

I am overriding the external_url= setter to ensure URLs start with http://. I’m doing this before any validation because I don’t want to bother the user who enters example.com/foo/bar without http://. I don’t plan on validating the URL at all anyway.

def external_url=(url)
  if !url.match /^https?:\/\//i
 url = "http://#{url}"