Skip to content

Instantly share code, notes, and snippets.

@TvL2386
TvL2386 / gist:8577594
Created January 23, 2014 12:11
example json put request with optional SSL
require 'net/https'
require 'json'
host = 'localhost'
port = 3000
path = '/controller/upload.json?key=bla'
json = {}.to_json
http = Net::HTTP.new host, port
#http.use_ssl = true
@TvL2386
TvL2386 / gist:6447834
Created September 5, 2013 09:15
Net::SCP keeps failing...
require 'net/scp'
# using:
#* net-scp (1.1.2)
#* net-ssh (2.6.8)
# Both fail
Net::SCP.download!('localhost', 'me','/tmp/bla.rb','/tmp/bla2.rb', password: 'mypass')
Net::SCP.download!('localhost', 'me','/tmp/bla.rb','/tmp/bla2.rb', password: 'mypass', ssh: {auth_methods: %w(password)})
@TvL2386
TvL2386 / app_models_foo_bar_bar.rb
Last active December 20, 2015 09:59
In rails 3.2 development, running Foo::Bar.say_hi in the console gives: NoMethodError: undefined method `say_hi' for Foo::Bar:Module
module Foo
module Bar
def self.say_hi
puts "hi"
end
end
end
@TvL2386
TvL2386 / gist:5501113
Created May 2, 2013 09:13
Testing icontrol-0.3.9 VirtualServer creation and destroy. The F5 has firmware version: BIG-IP 11.3.0 Build 2968.0 Hotfix HF1
require 'icontrol'
require 'awesome_print'
require 'yaml'
IControl.config = { user: 'admin', password: 'secret', base_url: 'https://192.168.0.60' }
ap IControl::LocalLB::VirtualServer.find(:all)
puts
manifest = {
:definition => {
@TvL2386
TvL2386 / gist:5195772
Last active December 15, 2015 03:39
using popen4
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
source 'http://rubygems.org'
gem 'octokit' , :git => 'https://github.com/ajonas04/octokit.git'
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
@TvL2386
TvL2386 / dcell test.rb
Created June 3, 2012 18:01
DCell: Communication with <node> interrupted
### 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
}
@TvL2386
TvL2386 / my_rvm_install.sh
Created November 4, 2011 21:26
rvm issue: Cannot select ruby-1.9.2-head-shay (patched ruby-1.9.2-head)
# 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/]
@TvL2386
TvL2386 / keepalived-notifier.rb
Created October 27, 2011 05:25
A Keepalived script
#!/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'