Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

#! /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
require 'bigdecimal'
n = 5_000
sum = BigDecimal.new('0')
dx = BigDecimal.new('1') / n
1.upto(n) { |i| sum += dx * (dx * i) ** 2 }
puts sum
puts sum.to_s
puts sum.to_f
* root servers
- no hassle with finding a good location with clean, cool air and stable electicity
- broken hard disk? we exchange it within 1 hour
* virtualization
- choose what you need, no less and no more
- super fast deployment
* special linux distribution
- compatible to everything
- super efficient
- rock stable
@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.