Skip to content

Instantly share code, notes, and snippets.

@ryanb
ryanb / issues_with_modules.md
Created November 29, 2012 22:38
Points on how modules can make code difficult to read.

My issues with Modules

In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.

A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval.

You can find instance_eval used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.

class Article < ActiveRecord::Base
@tomdale
tomdale / gist:3981133
Last active November 26, 2019 21:19
Ember.js Router API v2

WARNING

This gist is outdated! For the most up-to-date information, please see http://emberjs.com/guides/routing/!

It All Starts With Templates

An Ember application starts with its main template. Put your header, footer, and any other decorative content in application.handlebars.

<header>
@kaznum
kaznum / gist:3810258
Created October 1, 2012 08:16
sanitize HTML with jQuery
/*
* sanitize HTML with jQuery based on whitelist
* example:
* sanitizer.sanitize('<a href="foo" class="bar">aaa</a><script>alert("...")</script>', {'a': ['href'], 'strong': []})
* returns '<a href="foo">aaa</a>'
*/
var sanitizer = {};
(function($) {
function trimAttributes(node, allowedAttrs) {
@jboner
jboner / latency.txt
Last active May 4, 2024 21:16
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@karmi
karmi / .gitignore
Created March 16, 2012 16:09
Bootstrap, install and configure ElasticSearch with Chef Solo
.DS_Store
Gemfile.lock
*.pem
node.json
tmp/*
!tmp/.gitignore
@krisleech
krisleech / README.md
Created February 23, 2012 15:50
A Micro Gem for commenting out lines of Ruby/Erb
hide do          
          _     _     _            
    /\  /(_) __| | __| | ___ _ __  
   / /_/ / |/ _` |/ _` |/ _ \ '_ \ 
  / __  /| | (_| | (_| |  __/ | | |
  \/ /_/ |_|\__,_|\__,_|\___|_| |_|
end
@benjchristensen
benjchristensen / index.html
Created August 16, 2011 03:21
Animated Line Graphs / Sparklines using SVG Path and d3.js
<html>
<head>
<title>Animated Sparkline using SVG Path and d3.js</title>
<script src="http://mbostock.github.com/d3/d3.v2.js"></script>
<style>
/* tell the SVG path to be a thin blue line without any area fill */
path {
stroke: steelblue;
stroke-width: 1;
fill: none;
@karmi
karmi / collection.rb
Created March 8, 2011 11:59
Module which allows to use a proxy class for wrapping collections of all sorts.
# = Collection
#
# Module which allows to use a proxy class for wrapping collections of all sorts.
#
# Let's take a collection of articles, for example (see also the test suite below).
#
# The collection item class could look like this:
#
# class Article
# attr_reader :title
@karmi
karmi / slingshot.rb
Created February 6, 2011 14:17
Sketch of a Ruby API for ElasticSearch [http://elasticsearch.com]
# Sketch of a Ruby API for ElasticSearch [http://elasticsearch.com]
require 'rubygems'
require 'curb'
require 'rest_client'
require 'yajl/json_gem'
module Slingshot
def http
@karmi
karmi / mac_os_setup.sh
Created December 19, 2010 13:43
Installation Instructions For Setting Up A Clean Mac OS X System
# =====================================================
# Installation instructions for a clean Mac OS X system
# =====================================================
#
# <https://gist.github.com/747336>
#
# Keep only `.ssh` and `.profile.local` files from backup
# + Clean up Apple Ruby