Skip to content

Instantly share code, notes, and snippets.

@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.

@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
#!/usr/bin/env ruby
require 'json'
require 'openssl'
require 'eventmachine'
require 'websocket-eventmachine-client'
access_key = 'your access key'
secret_key = 'your secret key'
m = Member.find_by_email 'foo@peatio.dev'
market = Market.find :btccny
ask = OrderAsk.new(
source: 'debug',
state: Order::WAIT,
member_id: m.id,
ask: market.target_unit,
bid: market.price_unit,
currency: market.id,
m = Member.find_by_email 'foo@peatio.dev'
market = Market.find :btccny
puts "Ready ..."
a = m.get_account(:cny)
puts "balance: #{a.balance.to_s('F')}"
puts "locked: #{a.locked.to_s('F')}"
gets
puts "Started."
@janx
janx / gist:d8dc98870373d06c9e8d
Last active August 29, 2015 14:04
Description of ActiveRecord pattern from <Patterns of Enterprise Application Architecture>
In simple applications the Domain Model (116) is an uncomplicated structure that actually corresponds pretty
closely to the database structure, with one domain class per database table. Such domain objects often have
only moderately complex business logic. In this case it makes sense to have each domain object be
responsible for loading and saving from the database, which is Active Record (160) (see Figure 3.3). Another
way to think of the Active Record (160) is that you start with a Row Data Gateway (152) and then add domain
logic to the class, particularly when you see repetitive code in multiple Transaction Scripts (110).
...
As the domain logic gets more complicated and you begin moving toward a rich Domain Model (116), the simple
Verifying myself: My Bitcoin username is +janx. https://onename.io/janx
@janx
janx / dmenu_goto_window.rb
Last active August 29, 2015 14:19
Jump to specified window (archlinux + bspwm + dmenu)
#!/usr/bin/env ruby
# get a list of all windows
window_list = `wmctrl -l`.split("\n").map {|l| l.strip.split(' ', 4)}
# write window names to a tmp file
File.open('/tmp/dmenu_goto_windows', 'w') do |f|
window_list.each {|w| f.puts w[3] }
end
#!/usr/bin/env ruby
if ARGV.size < 1
puts "usage: ruby_tags [version]"
exit 1
end
version = ARGV[0]
d = Dir["/home/jan/.rbenv/versions/#{version}/lib/ruby/gems/*/gems"]
raise "gems dir not found" if d.size < 1
@janx
janx / react_spotlight.js
Created July 2, 2015 04:15
A script to show which parts rendered by React
setInterval(function() { Array.prototype.slice.call(document.querySelectorAll('[data-reactid]')).forEach(function(element) { element.style.background = 'rgba(255,0,0,0.1)'; }) }, 500)