Skip to content

Instantly share code, notes, and snippets.

View chendo's full-sized avatar

chendo chendo

View GitHub Profile
### Keybase proof
I hereby claim:
* I am chendo on github.
* I am chendo (https://keybase.io/chendo) on keybase.
* I have a public key whose fingerprint is A4DE F0C8 847D 31DB 8B81 5264 EB16 FAE3 D887 BCDF
To claim this, I am signing this object:
@chendo
chendo / required_keyword_arguments.rb
Created March 28, 2014 03:19
My take on required keyword arguments in Ruby 2.0. This solution throws a nice backtrace, but still requires a name to be passed in.
module RequiredKeywordArguments
def required!(name)
backtrace = caller_locations(1).map { |c| c.to_s }
ex = ArgumentError.new("Missing required keyword argument '#{name}'")
ex.set_backtrace(backtrace)
raise ex
end
end
class Foo
require 'celluloid/io'
require 'socket'
class Server
include Celluloid::IO
def run
@tcp = TCPServer.new('0.0.0.0', 31337)
loop do
Connection.new_link(@tcp.accept).async.run
package main
import (
"fmt"
"github.com/apcera/nats"
"runtime"
"sync/atomic"
"time"
)
@chendo
chendo / gist:10335
Created September 11, 2008 23:07
or maybe not. ignore this
/* Adding icon to status bar in 1.x */
NSString *pathToDefault = [NSString stringWithFormat:@"%@/Default.png", [[NSBundle mainBundle] bundlePath]];
NSURL *urlToDefault = [NSURL fileURLWithPath:pathToDefault];
CGImageDestinationRef dest = CGImageDestinationCreateWithURL((CFURLRef)urlToDefault, CFSTR("public.png")/*kUTTypePNG*/, 1, NULL);
CGImageDestinationAddImage(dest, defaultPNG, NULL);
CGImageDestinationFinalize(dest);
CFRelease(defaultPNG);
# http://www.slate.com/id/2101150/sidebar/2101387/ent/2101353/
poem = <<-EOF.downcase.gsub(/[^a-z]/, '')
Dammit I'm mad.
Evil is a deed as I live.
God, am I reviled? I rise, my bed on a sun, I melt.
To be not one man emanating is sad. I piss.
Alas, it is so late. Who stops to help?
Man, it is hot. I'm in it. I tell.
I am not a devil. I level "Mad Dog".
# http://mozy.com/contest
# Question 4
# chendo's solution
require 'benchmark'
year = 0
fibs = [2, 0, 0, 0, 0] # age 0, 1, 2, 3, 4
adults = 0 # age > 5
Benchmark.bm do |bm|
# Genetic algorithm playaround
# chendo 2009
require 'rubygems'
require 'levenshtein'
class GA
def initialize
@pop = Array.new(100).map { random_string }
end
# put this inside spec_helper.rb
def p(*objs)
puts objs.map { |o| inspect.gsub('<', '&lt;').gsub('>', '&gt;') }.join("\n")
end
# SMS Rickroll script
# Word by word.
# Total messages to be sent: 450
# By @chendo
# Requires sendsms and a jailbroken iPhone
song = "We're no strangers to love
You know the rules ... and so do I
A full commitment's what I'm ... thinkin' of
You wouldn't get this from any other guy