Skip to content

Instantly share code, notes, and snippets.

View shenzhaoyan's full-sized avatar
🙂

Charles Shen shenzhaoyan

🙂
View GitHub Profile
@hgfischer
hgfischer / benchmark+go+nginx.md
Last active April 11, 2024 22:09
Benchmarking Nginx with Go

Benchmarking Nginx with Go

There are a lot of ways to serve a Go HTTP application. The best choices depend on each use case. Currently nginx looks to be the standard web server for every new project even though there are other great web servers as well. However, how much is the overhead of serving a Go application behind an nginx server? Do we need some nginx features (vhosts, load balancing, cache, etc) or can you serve directly from Go? If you need nginx, what is the fastest connection mechanism? This are the kind of questions I'm intended to answer here. The purpose of this benchmark is not to tell that Go is faster or slower than nginx. That would be stupid.

So, these are the different settings we are going to compare:

  • Go HTTP standalone (as the control group)
  • Nginx proxy to Go HTTP
  • Nginx fastcgi to Go TCP FastCGI
  • Nginx fastcgi to Go Unix Socket FastCGI
@mimosz
mimosz / smser.rb
Created August 23, 2012 16:00
短信宝
# -*- encoding: utf-8 -*-
require 'digest/md5'
require 'nestful'
class Smsbao
def initialize(login, passwd)
@login = login
@passwd = Digest::MD5.hexdigest(passwd.to_s)
end
@shenzhaoyan
shenzhaoyan / gist:824583
Created February 13, 2011 10:48
MongoDB & MySQL
MySQL: SELECT * FROM user WHERE name = "foobar"
Mongo: db.user.find({"name" : "foobar"})
MySQL: INSERT INOT user (`name`, `age`) values ("foobar", 25)
Mongo: db.user.insert({"name" : "foobar", "age" : 25})
MySQL: DELETE * FROM user
Mongo: db.user.remove({})
MySQL: DELETE FROM user WHERE age < 30
Mongo: db.user.remove({"age" : {$lt : 30}}) $gt : > ; $gte : >= ; $lt : < ; $lte : <= ; $ne : !=
MySQL: UPDATE user SET `age` = 36 WHERE `name` = "foobar"
Mongo: db.user.update({"name" : "foobar"}, {$set : {"age" : 36}})
@paneq
paneq / capc.rb
Created January 27, 2011 18:50
Creating an object with Capybara api and jumping into it.
#!/usr/bin/env ruby
require 'bundler'
Bundler.setup(:default, :test) if defined?(Bundler)
require "selenium-webdriver"
require 'capybara/dsl'
Capybara.default_driver = :selenium
Capybara.default_selector = :css
Capybara.default_wait_time = 5
@shenzhaoyan
shenzhaoyan / sample.rb
Created January 7, 2011 02:58 — forked from mtodd/sample.rb
Sinatra helpers
helpers do
def format
(params[:format] || :json).to_sym
end
def render_to(format, results)
case format
when :json
results.to_json
when :xml
@erikeldridge
erikeldridge / example.rb
Created April 29, 2010 04:50
A utility for signing an url using OAuth in a way that's convenient for debugging
require 'oauth_util.rb'
require 'net/http'
o = OauthUtil.new
o.consumer_key = 'examplek9SGJUTUpocjZ5QjBJmQ9WVdrOVVFNHdSR2x1TkhFbWNHbzlNQS0tJnM9Y29uc3VtkZXJzZWNyZXQmeD0yYg--';
o.consumer_secret = 'exampled88d4109c63e778dsadcdd5c1875814977';
url = 'http://query.yahooapis.com/v1/yql?q=select%20*%20from%20social.updates.search%20where%20query%3D%22search%20terms%22&diagnostics=true';
@defunkt
defunkt / installing-mustache.vim.md
Created March 6, 2010 10:21
Installing mustache.vim

mustache.vim

In your shell:

cd ~/.vim
git clone git://github.com/juvenn/mustache.vim.git
mv mustache.vim/syntax/* syntax/
mv mustache.vim/indent/* indent/
mv mustache.vim/ftdetect/* ftdetect/

rm -rf mustache.vim

require 'rubygems'
require 'sinatra'
require 'datamapper'
require 'dm-paperclip'
require 'haml'
require 'fileutils'
APP_ROOT = File.expand_path(File.dirname(__FILE__))
DataMapper::setup(:default, "sqlite3://#{APP_ROOT}/db.sqlite3")
@mudge
mudge / gist:263139
Created December 24, 2009 10:43
Polymorphic has_many :through in Rails 2.3
# A polymorphic has_many :through relationship in Rails 2.3
# based on Josh Susser's "The other side of polymorphic :through associations"
# http://blog.hasmanythrough.com/2006/4/3/polymorphic-through
class Authorship < ActiveRecord::Base
belongs_to :author
belongs_to :publication, :polymorphic => true
end
class Author < ActiveRecord::Base
has_many :authorships
@nakajima
nakajima / mini-irb.rb
Created February 22, 2009 20:37
Can you make a smaller one?
loop do
print '>> '
output = eval($stdin.gets)
print '=> '
puts output.inspect
end