Skip to content

Instantly share code, notes, and snippets.

View Burgestrand's full-sized avatar
🙃
(:

Kim Burgestrand Burgestrand

🙃
(:
View GitHub Profile
@Burgestrand
Burgestrand / download-progress.rb
Created June 27, 2010 13:55
Ruby HTTP file download with progress measurement
require 'net/http'
require 'uri'
def download(url)
Thread.new do
thread = Thread.current
body = thread[:body] = []
url = URI.parse url
Net::HTTP.new(url.host, url.port).request_get(url.path) do |response|
@Burgestrand
Burgestrand / DefaultKeyBinding.dict
Created July 29, 2010 15:21
Mac OS X Key Bindings
/* ~/Library/KeyBindings/DefaultKeyBinding.dict */
{
/**
* Key modifiers
* =============
* - ^ : Ctrl
* - $ : Shift
* - ~ : Option (Alt)
* - @ : Command (Apple)
* - # : Numeric Keypad
@Burgestrand
Burgestrand / render.rake
Created September 23, 2010 00:27
How to render Rails 3.0 views within rake tasks (with url helpers!)
# How to render rails 3.0 views within rake tasks.
#
# Description: An example of how to render a view within a rake task,
# complete with instance variables, application & url helpers and I18n.
#
# License: X11 license
#
# Copyright (c) 2010 Kim Burgestrand <http://burgestrand.se/>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
@Burgestrand
Burgestrand / remove-all-but-file.git
Created September 25, 2010 16:05
Recipe for removing everything form history except one file
git filter-branch --index-filter 'git ls-files -i -x '"'"'*'"'"' -x '"'"'*.*'"'"' -x '"'"'!file'"'"' -z | xargs -0 git rm -f --cached' --prune-empty
# -> git rebase *root-SHA1* to remove merge commits
@Burgestrand
Burgestrand / child.rb
Created September 25, 2010 17:47
A ruby client example that can reload code without closing socket connection
class Child
attr_reader :socket
def initialize(socket)
@socket = socket
main_loop
end
def main_loop
Signal.trap("HUP") do
@Burgestrand
Burgestrand / select-server.php
Created October 2, 2010 13:40
Naive server using socket_select() in PHP
<?php
// Config
$host = '127.0.0.1';
$port = 0; // Random port
// Setup
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$clients = array();
// Bind, listen and disable blocking
###
#
# NOTE: Development moved to http://github.com/Burgestrand/vlad-nginx
#
###
#
# Vlad the Deployer recipe for NGiNX.
#
# Author: Kim Burgestrand <http://github.com/Burgestrand>
# Date: 24th September 2010
@Burgestrand
Burgestrand / assets.rake
Created October 6, 2010 10:02
Asset packaging rake task
# Rake task for compiling CoffeeScript and SASS (Compass).
#
# Author: Kim Burgestrand <http://burgestrand.se/>
# Date: 6th October 2010
# License: X11 License (MIT License)
# URL: http://gist.github.com/gists/613114
desc "Compiles CoffeeScript using Barrista (but only if they changed)"
task 'coffee:compile' => :environment do
require 'barista'
abort "'#{Barista::Compiler.bin_path}' is unavailable." unless Barista::Compiler.available?
@Burgestrand
Burgestrand / webapp.rb
Created January 25, 2011 03:06 — forked from igrigorik/webapp.rb
Turn any ruby Object into a web application!
require 'rack'
class Object
def to_webapp
def self.call(env)
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?)
[200, {}, send(func || :inspect, *attrs)]
end
self
end
@Burgestrand
Burgestrand / client.rb
Created March 2, 2011 02:44
A file upload using RestClient (and a hacky way at that)
require 'rest-client'
require 'tempfile'
require 'stringio'
img = StringIO.new(RestClient.get 'http://localhost:9393/img')
def img.path
'http://localhost:9393/img.png'
end