Skip to content

Instantly share code, notes, and snippets.

@paddor
paddor / zmq_curve_encryption.rb
Created October 1, 2014 02:38
ZMQ Dealer<-->Router: asynchronous communication with CURVE encryption
require 'rbnacl'
require 'celluloid/zmq'
Celluloid::ZMQ.init
# Monkey patching
module Celluloid
module ZMQ
module ReadableSocket
# Reads a multipart message, stores it into the given buffer and returns
# the buffer.
require 'ffi-rzmq'
class ZMQTest
def initialize(addr)
@ctx = ::ZMQ::Context.create
@socket = @ctx.socket(::ZMQ::ROUTER)
warn "setting option ::ZMQ::ROUTER_MANDATORY (#{::ZMQ::ROUTER_MANDATORY}) to 1"
@socket.setsockopt(::ZMQ::ROUTER_MANDATORY, 1)
@socket.bind(addr)
end

Keybase proof

I hereby claim:

  • I am paddor on github.
  • I am paddor (https://keybase.io/paddor) on keybase.
  • I have a public key whose fingerprint is 150A 811C 4B01 DA76 EBB3 57D3 9E19 CE30 326F 8815

To claim this, I am signing this object:

#! /usr/bin/env ruby
# File : to_num.rb
# Author : Patrik Wenger <paddor@gmail.com>
# Date : 26th September 2008
# Version : 0.2
#
# It would be nice if there were fancy strings like %i, %f and %n for integers,
# floats and numbers, respectively. This library attempts to solve this problem.
#
#! /usr/bin/env ruby
nummern = [
"+41 ( 0 ) 79-123 4567",
"+41-79-123 4567",
"079 123 45 67",
"+41 ( 079 ) 123 67 90",
]
# fuer jede nummer ...
See https://github.com/paddor/em-simple_telnet
#! /usr/local/bin/ruby
class Car
# excetion raised when not enough fuel left to drive given distance
class NotEnoughFuel < RuntimeError
end
# constructor with one parameter
def initialize vendor
warn "Opening database connection ..."
DB = Sequel.postgres(:host=>'localhost', :user=>'logs', :database=>'logs')
warn "Running COPY command with data ..."
DB.run copy_command
DB.synchronize do |conn|
ret = conn.put_copy_data(copy_data) # or raise "could not send COPY data"
warn "Sent COPY data: #{ret}"
ret = conn.put_copy_end # or raise "could not send COPY end"
warn "Sent COPY end: #{ret}"
end
require 'bigdecimal'
require 'bigdecimal/math'
class Integer
def fact
return self * (self-1).fact if self > 1
return 1
end
end
@paddor
paddor / rubygems_mirror.sh
Created December 23, 2011 15:21
Creates Rubygems mirror in the current directory using Bash, some ruby and wget
#!/bin/bash
DEFAULT_URI='http://production.cf.rubygems.org/'
GEM_MARSHAL_VERSION=`ruby -e 'puts Gem.marshal_version'`
SPECS_FILE_Z="specs.$GEM_MARSHAL_VERSION.gz"
AVAILABLE_GEMS=`mktemp /tmp/available_gems.XXX`
GEMS_ALREADY_DOWNLOADED=`mktemp /tmp/gems_already_downloaded.XXX`
GEMS_TO_DOWNLOAD=`mktemp /tmp/gems_to_download.XXX`
GEMS_TO_REMOVE=`mktemp /tmp/gems_to_remove.XXX`
PARALLEl_DOWNLOAD=15