Skip to content

Instantly share code, notes, and snippets.

/*
A Goroutine safe pattern using channels that abstracts away the channels
This is a concept of creating a goroutine safe object that uses channels under the covers to communicate
with the internal map[string]string structure. I know that typically this kind of solution may done
with mutexes but the excercise was in using channels on purpose although they are heavier.
Note a couple of points:
- When using channels, you can still build a public-facing api that nicely abstracts them away, therefore
@axgle
axgle / pkg-gonfig.go
Created May 14, 2012 02:13 — forked from mattn/pkg-gonfig.go
go implementation of pkg-config
package main
import (
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strings"
)
@axgle
axgle / fbr.rb
Created November 20, 2009 00:42 — forked from tmm1/fbr.rb
# Poor Man's Fiber (API compatible Thread based Fiber implementation for Ruby 1.8)
# (c) 2008 Aman Gupta (tmm1)
unless defined? Fiber
require 'thread'
class FiberError < StandardError; end
class Fiber
def initialize
@axgle
axgle / go4.go
Created November 18, 2009 04:37 — forked from Arachnid/go4.go
package main
import "fmt"
type state struct {
board [7][6]int;
heights [7]int;
}
type move struct {
def run_solr
defs = {
'jetty.home' => @path,
'solr.data.dir' => @path/'solr'/'data'
}.map { |k, v| "-D#{k}=#{v}" }.join(' ')
cmd = "java -jar #{@path}/start.jar #{@path/'etc'/'jetty.xml'} -classpath #{@path/'lib'} #{defs}"
# IO.popen is more portable than fork/exec (i.e. to JRuby)
pid = IO.popen(cmd, 'r').pid
# This is actually available as a gem: gem install rack-rewrite
# Full source code including tests is on github: http://github.com/jtrupiano/rack-rewrite
module Rack
# A rack middleware for defining and applying rewrite rules. In many cases you
# can get away with rack-rewrite instead of writing Apache mod_rewrite rules.
class Rewrite
def initialize(app, &rule_block)
@app = app
@rule_set = RuleSet.new
module Rack
class ChromeFrame
def initialize(app, options={})
@app = app
end
def call(env)
status, headers, response = @app.call(env)
if env['HTTP_USER_AGENT'] =~ /MSIE/ && response.content_type == 'text/html'
#http://www.infoq.com/cn/news/2009/10/21-ruby-web-middlewares
module Rack
class NoIE
def initialize(app, options = {})
@app = app
@options = options
@options[:redirect] ||= 'http://www.microsoft.com/windows/internet-explorer/default.aspx'
@options[:minimum] ||= 7.0
end
rd, wr = IO.pipe
if fork
wr.close
puts "Parent got: <#{rd.read}>"
rd.close
Process.wait
else
rd.close
puts "Sending message to parent"