Skip to content

Instantly share code, notes, and snippets.

View kaid's full-sized avatar
🎯
Focusing

Kaid Wong kaid

🎯
Focusing
  • Beijing, PRC
  • 20:21 (UTC +08:00)
View GitHub Profile
@tmm1
tmm1 / gist:329682
Created March 11, 2010 21:31
EM Chat Server Demo
require 'rubygems'
require 'eventmachine'
require 'em-http' # gem install em-http-request
require 'yajl' # gem install yajl-ruby
class String
def bold
"\033[1m#{self}\033[0m"
end
end
@seancribbs
seancribbs / application.rb
Created August 5, 2010 20:14
Code from the "Riak with Rails" webinar
# Add this line to your config/application.rb to enable
# initialization of Ripple, after the other framework railties
require 'ripple/railtie'
# To use the Riak cache store, place this line inside the
# Application class
config.cache_store = :riak_store
@mislav
mislav / pagination.md
Created October 12, 2010 17:20
"Pagination 101" by Faruk Ateş

Pagination 101

Article by Faruk Ateş, [originally on KuraFire.net][original] which is currently down

One of the most commonly overlooked and under-refined elements of a website is its pagination controls. In many cases, these are treated as an afterthought. I rarely come across a website that has decent pagination, and it always makes me wonder why so few manage to get it right. After all, I'd say that pagination is pretty easy to get right. Alas, that doesn't seem the case, so after encouragement from Chris Messina on Flickr I decided to write my Pagination 101, hopefully it'll give you some clues as to what makes good pagination.

Before going into analyzing good and bad pagination, I want to explain just what I consider to be pagination: Pagination is any kind of control system that lets the user browse through pages of search results, archives, or any other kind of continued content. Search results are the o

@kamui
kamui / annotate_image.rb
Created March 22, 2011 16:42
Annotate text that auto fits within an image and benchmark on both graphicsmagick and imagemagick. Uses mini_magick
#!/usr/bin/env ruby
# Convert command line
#
#gm convert -font helvetica -fill white -pointsize 20 -draw "text 500,600 'WALLPAPERZ ARE GOOD'" test.jpg output.jpg
#
#convert -background transparent -fill white -gravity center -size 1024x200 -font Helvetica -pointsize 20 #caption:"I'm a wallpaper, you know what to do" test.jpg +swap -gravity south -composite output.jpg
#
# Mogrify command line
#
@chetan
chetan / yardoc_cheatsheet.md
Last active November 11, 2024 08:27
YARD cheatsheet
@technoweenie
technoweenie / .gitignore
Created February 20, 2012 04:55
quick kestrel zeromq port attempt
node_modules
@SteveSongMIT
SteveSongMIT / captainflint.dtl
Created March 20, 2012 22:50
Simple Cowboy web server + ErlyDTL
<html>
<body>
GET squawk:<br />
{{ squawk_get }}<br /><br />
POST squawk:<br />
{{ squawk_post }}<br /><br />
@jamiehodge
jamiehodge / mount.rb
Created April 10, 2012 14:31
sinatra/mount
module Sinatra
module Mount
def mount(app, route="/#{app.name.downcase}")
%w{get post put delete patch options}.each do |method|
self.send method.to_sym, "#{route}*" do
app.call(
env.merge!(
'SCRIPT_NAME' => route.split('/').last,
'PATH_INFO' => params.delete('splat').join('/')
@jch
jch / rack_boot.rb
Created April 30, 2012 05:16
Programmatically start a rack app
require 'rack'
class RackApp
def self.call(env)
[200, {'Content-Type' => 'text/html'}, ['derp']]
end
end
# For a full list of options, see
# http://www.ruby-doc.org/stdlib-1.9.3/libdoc/webrick/rdoc/WEBrick.html
@hellerbarde
hellerbarde / latency.markdown
Created May 31, 2012 13:16 — forked from jboner/latency.txt
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs