Skip to content

Instantly share code, notes, and snippets.

@janx
janx / slanger_nginx_lb.conf
Created May 5, 2014 05:09
Use nginx as load balancer for Slanger
upstream slanger_ws {
server 127.0.0.1:8001;
server 127.0.0.1:8002;
server 127.0.0.1:8003;
server 127.0.0.1:8004;
server 127.0.0.1:8005;
server 127.0.0.1:8006;
server 127.0.0.1:8007;
server 127.0.0.1:8008;
}
#!/usr/bin/env ruby
require 'json'
require 'openssl'
require 'eventmachine'
require 'websocket-eventmachine-client'
access_key = 'your access key'
secret_key = 'your secret key'
@janx
janx / how-to-benchmark.markdown
Last active August 29, 2015 14:00
Integration benchmark

All below stuff run in PRODUCTION rails environment, make sure production settings in your database.yml points to a test database!!!

###Reset database

RAILS_ENV=production rake db:reset

###Start matching engine

# modify config/amqp.yml first if rabbitmq server is running on node other than 127.0.0.1
RAILS_ENV=production rake daemon:matching:start
@janx
janx / centos-bitcoind-guide.markdown
Last active May 8, 2019 05:27
Install bitcoind on CentOS 6.5

##RPM Packages##

sudo yum install qt-devel protobuff-devel qrencode-devel

##Switch to user bitcoind##

sudo useradd bitcoind
sudo su - bitcoind
mkdir bitcoind

mkdir bitcoind/deps

@janx
janx / gist:9756153
Created March 25, 2014 06:23
Bitcoin client bootstrap before 0.6.x

https://en.bitcoin.it/wiki/Network

#IRC#

As-of version 0.6.x of the Bitcoin client, IRC bootstrapping is no longer enabled by default. The information below is accurate for most versions prior.

Bitcoin joins a random channel between #bitcoin00 and #bitcoin99 on irc.lfnet.org. Your nick is set to an encoded form of your IP address. By decoding all the nicks of all users on the channel, you get a list of all IP addresses currently connected to Bitcoin.

For hosts that cannot make outbound connections on port 6667, the lfnet servers are also listening on port 7777.

#!/usr/bin/env ruby
require 'base64'
require 'openssl'
require 'pp'
if ARGV.size != 1
puts "Usage: #{$0} <pem file>"
exit 1
end
/home/jan/.rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/riak-client-1.0.5/lib/riak/client/net_http_backend.rb:58:in `block (2 levels) in perform': Expected 200 from Riak but received 500. <html><head><title>500 Internal Server Error</title></head><body><h1>Internal Server Error</h1>The server encountered an error while processing this request:<br><pre>{error,{error,badarg, (Riak::HTTPFailedRequest)
[{lists,split,
[-500,
[{<<"apartmentguide_development_search">>,
<<"1373995701">>,
[{p,[0,0]},{score,0.03162748954634035}]},
{<<"apartmentguide_development_search">>,
<<"1373997031">>,
[{p,[0,0]},{score,0.03162748954634035}]},
{<<"apartmentguide_development_search">>,
@janx
janx / _virtus_vs_plain_method.markdown
Last active December 18, 2015 03:48
Some thoughts on Virtus use in our project.

The more Virtus code I wrote, the more awkward I feel it is. It's not because Virtus is inherently bad, I just don't think it fits our case.

  1. So many attributes need to be marked reader: :private. It's not ruby's way. Ruby has its own private keyword.

  2. NilToDefault is bad. How do I decide whether a model need to include it? Or we simply include it everywhere?

  3. The difference between writer_class and default is subtle. Why does the implementer add a new writer_class here? Why does he use default value there? We're using different ways to do the same thing (compute values) here.

  4. writer_class is awkward. Why do I need to create a class just for its coerce method? I feel like writing Java.

@janx
janx / object_space_middleware.rb
Last active December 17, 2015 18:59
ObjectSpace.count_objects graph middleware
class ObjectSpaceMiddleware
GRANULITY = 50
@@files = {}
@@count = 0
def self.file(type)
unless @@files[type]
@@files[type] = File.open File.expand_path("../../../tmp/count_#{type}", __FILE__), 'a'
@janx
janx / About.markdown
Last active January 28, 2023 15:36
Memory leak research on OpenStruct and #define_method.

OpenStruct and #define_method

#define_method will create a closure, without careful use it could cause memory leak, as pointed out here.

OpenStruct use #define_method to create accessors dynamically, we suspect that will cause memory leak.

So I create two scripts to prove it, however the result shows the opposite: OpenStruct doesn't leak memory.

open_struct_leak.rb