Skip to content

Instantly share code, notes, and snippets.

Bringing BEM to inuit.css

BEM is a methodology for naming and classifying CSS selectors in a way to make them a lot more strict, transparent and informative.

The naming convention follows this pattern:

.block{}
.block__element{}
.block--modifier{}
class CarPart
# does the method name end in _price ?
def ghost_method_condition(name)
!!name.to_s[/_price$/]
end
# rewrite method missing if the method matches ghost_method_condition
def method_missing(name, *args, &block)
super unless ghost_method_condition(name)
<!DOCTYPE html>
<html>
<head>
<style type="text/css" media="screen">
div{
height: 50em;
}
div.column{
width: 7em;
}
class Crypto
# encrypts data with the given key. returns a binary data with the
# unhashed random iv in the first 16 bytes
def self.encrypt(data, key)
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
cipher.encrypt
cipher.key = key = Digest::SHA256.digest(key)
random_iv = cipher.random_iv
cipher.iv = Digest::SHA256.digest(random_iv + key)[0..15]
encrypted = cipher.update(data)
#!/usr/bin/env ruby
# twitdiff.rb
# Quickie script for unfollowing users who aren't following you,
# or following users who are following you...or both
# Requires Grackle (http://github.com/hayesdavis/grackle/tree/master):
# sudo gem sources -a http://gems.github.com
# sudo gem install hayesdavis-grackle
# mysql-style output for an array of ActiveRecord objects
#
# Usage:
# report(records) # displays report with all fields
# report(records, :field1, :field2, ...) # displays report with given fields
#
# Example:
# >> report(records, :id, :amount, :created_at)
# +------+-----------+--------------------------------+
# | id | amount | created_at |
require 'open-uri'
content = nil
puts "Valid cert:"
open("https://www.wesabe.com") { |s| content = s.read }
puts " got #{content.length} bytes"
puts "Invalid cert: "
open("https://google.com") { |s| content = s.read }
puts " got #{content.length} bytes"
# reminder to do pushups every hour while at work
45 9-17 * * 1-5 /usr/local/bin/growlnotify -m "pushups"
# Taking on the Binary Search challenge
# http://reprog.wordpress.com/2010/04/19/are-you-one-of-the-10-percent/
class Array
# Binary search; assumes array is sorted
# If value is found in the array, it returns an index where it can be found.
# If the value occurs multiple times in the array, it will just return the
# first place it is found (not necessarily the first occurrence in the array).
# If the value is not found, it returns nil.
def bsearch(value)