Skip to content

Instantly share code, notes, and snippets.

View rafbm's full-sized avatar

Rafael Masson rafbm

View GitHub Profile
@rafbm
rafbm / .gitconfig
Created February 6, 2012 16:16
Sane aliases for `git reset`
[alias]
unstage = reset HEAD # unstage
clear = reset --hard HEAD # erase uncommited file edits (destructive!)
uncommit = reset HEAD~1 # erase last commit but keeps related file edits
rollback = reset --hard HEAD~1 # erase last commit and related file edits (destructive!)
@rafbm
rafbm / copy-ip.sh
Created April 15, 2012 02:17
Copy your local IP address from the command line (OS X)
# I often need this IP for testing local websites in VirtualBox
echo -n `ifconfig | grep -Po "(?<=inet )\d*\.\d*\.\d*\.\d*(?=.*broadcast)"` | pbcopy
# Less Unix-y, somewhat more readable version
ifconfig | ruby -e "print STDIN.read.match(/inet (\d*\.\d*\.\d*\.\d*).*broadcast/)[1]" | pbcopy
# I use it like this in my .zshrc
alias ip='echo -n `ifconfig | grep -Po "(?<=inet )\d*\.\d*\.\d*\.\d*(?=.*broadcast)"` | pbcopy'
@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}"
@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 / 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 / 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 / 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 / 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 / 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 / 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