Skip to content

Instantly share code, notes, and snippets.

View yuki24's full-sized avatar
🔢
NaN :trollface:

Yuki Nishijima yuki24

🔢
NaN :trollface:
View GitHub Profile
@yuki24
yuki24 / moped_examples.rb
Created July 24, 2012 10:54
moped examples
session = Moped::Session.new(["127.0.0.1:27017"], database: "mongodb")
session[:collection].find.one
# => {
# "_id"=>"500b7c0d1d41c81647000016",
# "name"=>"a photo",
# "updated_at"=>2012-07-22 04:05:33 UTC,
# "created_at"=>2012-07-22 04:05:33 UTC
# }
session[:collection].find.select(name: false).one
@yuki24
yuki24 / duplex.rb
Created July 20, 2012 05:37
a snipept for something
require 'em-proxy'
Proxy.start(host: "127.0.0.1", port: 8000, debug: false) do |conn|
conn.server :server1, host: "127.0.0.1", port: 3000
conn.server :server2, host: "127.0.0.1", port: 3001
conn.on_data do |data|
data
end
@yuki24
yuki24 / foo.rb
Created July 9, 2012 19:59
Which is wrong, me or Hashie?
require 'rubygems'
require 'hashie'
class Foo < Hashie::Mash
def initialize(arg, options = {})
options[:key]
super(options)
end
end
@yuki24
yuki24 / trace.txt
Created June 25, 2012 13:50
Ruby bug?
/home/yuki/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:761: [BUG] Segmentation fault
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0066 p:0015 s:0266 b:0264 l:000263 d:000263 METHOD /home/yuki/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:761
c:0065 p:0011 s:0256 b:0256 l:000255 d:000255 METHOD /home/yuki/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:755
c:0064 p:0048 s:0253 b:0253 l:000252 d:000252 METHOD /home/yuki/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:744
c:0063 p:0182 s:0250 b:0250 l:000249 d:000249 METHOD /home/yuki/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:557
c:0062 p:0031 s:0237 b:0237 l:000ac0 d:000ac0 METHOD /home/yuki/.rvm/gems/ruby-1.9.3-p194@potter/gems/capybara-1.1.2/lib/capybara/server.rb:47
c:0061 p:0011 s:0233 b:0233 l:001538 d:000232 BLOCK /home/yuki/.rvm/gems/ruby-1.9.3-p194@potter/gems/capybara-1.1.2/lib/capybara/server.rb:69
@yuki24
yuki24 / rack.rb
Created April 5, 2012 05:37
simplest rack app
require 'rack'
Rack::Server.start(app: Proc.new{|env| [200, {'Content-Type' => 'text/html'}, env]}, Port: 8080)
@yuki24
yuki24 / robospecs-0.2-SNAPSHOT.sh
Created March 27, 2012 01:40
publish robospecs 0.2-SNAPSHOT locally
git clone git://github.com/jbrechtel/robospecs.git
cd robospecs
sbt publish-local
@yuki24
yuki24 / mass_assignment.rb
Created March 6, 2012 02:09
Mongoid's Mass assignment
> require 'rubygems'
=> false
> require 'mongoid'
=> true
> class Person
> include Mongoid::Document
> end
=> Person
> Person
=> Person
@yuki24
yuki24 / fried_tofu.txt
Created February 24, 2012 18:01
comparison of FriedTofu and Kodachi
$ ab -n 100 -c 10 http://friedtofu-demo-yuki24.herokuapp.com/rfit/100/100......
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking friedtofu-demo-yuki24.herokuapp.com (be patient).....done
Server Software: Jetty(7.5.4.v20111024)
Server Hostname: friedtofu-demo-yuki24.herokuapp.com
@yuki24
yuki24 / client.c
Created February 3, 2012 19:04
sever client exercise
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
void error(const char *msg){
@yuki24
yuki24 / set_iptables.sh
Created January 3, 2012 10:08
iptables sample
#!/bin/bash
LAN=eth0
LOCALNET_MASK=`ifconfig $LAN|sed -e 's/^.*Mask:\([^ ]*\)$/\1/p' -e d`
LOCALNET_ADDR=`netstat -rn|grep $LAN|grep $LOCALNET_MASK|cut -f1 -d' '`
LOCALNET=$LOCALNET_ADDR/$LOCALNET_MASK
#/etc/init.d/iptables stop