This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'socket' | |
require 'thread' | |
class Client | |
def initialize server_name, server_port | |
@server_name, @server_port = server_name, server_port | |
end | |
def connect | |
@socket = TCPSocket.new(@server_name, @server_port) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def print_message | |
Thread.new do | |
loop do | |
# monitor socket and print data if there is any | |
result = IO.select([@socket], nil, nil, nil) | |
if not result.nil? | |
socket = result[0].first # result[0] is the socket array. In this example there can only be one | |
data = socket.readpartial 4096 | |
# use print here, because puts automatically appends a newline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def respond_to_command data | |
if data =~ /^([^\s]+):\s(?:[^\s]+):\s([^\s]+):\s(.*)$/ | |
sender = $1 | |
command = $3.rstrip | |
# directed to me? | |
return nil if not $2.split(',').include?(@my_name) | |
# if I'm still here, I guess so ;-) | |
# lets see if uptime is in the allowed commands array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
socket = TCPSocket.new server_name, server_port | |
socket.write "hello? someone there?\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# This is in my keepalived.conf | |
# ... | |
# notify_master "/usr/tools/keepalived/notify.sh primary" | |
# notify_backup "/usr/tools/keepalived/notify.sh backup" | |
# notify_fault "/usr/tools/keepalived/notify.sh fault" | |
# ... | |
require 'socket' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reproduction path: | |
# This was done on 2011-07-17 | |
# Ubuntu 10.04 LTS x64 | |
bash < <( curl https://rvm.beginrescueend.com/releases/rvm-install-head ) | |
apt-get install build-essential bison openssl libreadline5 libreadline-dev curl git-core zlib1g zlib1g-dev libssl-dev vim libsqlite3-0 libsqlite3-dev sqlite3 libreadline-dev libxml2-dev git-core subversion autoconf | |
rvm version | |
# rvm 1.6.23 by Wayne E. Seguin ([email protected]) [https://rvm.beginrescueend.com/] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### node42.rb | |
require 'dcell' | |
DCell.start :id => "node42", :addr => "tcp://127.0.0.1:2042", | |
:registry => { | |
:adapter => 'redis', | |
:host => '127.0.0.1', | |
:port => 6379 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'thread' | |
require 'ffi-rzmq' | |
def broker | |
ctx = ZMQ::Context.new | |
socket = ctx.socket(ZMQ::ROUTER) | |
socket.setsockopt ZMQ::LINGER, 0 | |
socket.bind 'tcp://*:55555' | |
poller = ZMQ::Poller.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'http://rubygems.org' | |
gem 'octokit' , :git => 'https://github.com/ajonas04/octokit.git' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'popen4' | |
cmd = "ls /tmp" | |
status = POpen4::popen4(cmd) do |stdout,stderr,stdin,pid| | |
stdin.close | |
# get the stdout | |
puts "stdout: #{stdout.read.inspect}" | |
# get the stdin |
OlderNewer