Skip to content

Instantly share code, notes, and snippets.

var cp = require('child_process');
function *doKill(process, initial_delay)
{
yield process.kill('SIGTERM');
yield process.kill('SIGKILL');
}
function niceKill(process, onExit, initial_delay)
{
@astroza
astroza / dj_inspector.rb
Created January 22, 2016 15:47
bin/dj_inspector.rb
#!/usr/bin/env ruby
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
Thread.start(TCPServer.new(51313)) do |server|
loop do
puts "listening"
client = server.accept
puts "new client"
while line = client.gets
@astroza
astroza / inspector.rb
Created January 22, 2016 15:47
lib/inspector.rb
class Inspector
def inspect_objects_space
count = Hash.new(0)
ObjectSpace.each_object(Object) {|o| count[o.class] += 1 }
server = TCPSocket.new 'localhost', 51313
max = count.reduce do |a, v| a[1] > v[1] ? a : v end
server.puts max.to_s
server.close
end
end
@astroza
astroza / singleton.rb
Last active October 3, 2018 19:55
Nicer Ruby Singleton
class SingletonTest
def data
@data
end
def data=(n)
@data = n
end
@old_new_method = self.method(:new)
require 'git'
require 'fileutils'
require 'yaml'
class Key < ActiveRecord::Base
def self.authorized_keys_content
Key.all.each.reduce('') do |ac, key|
ac << "#{key.public_key}\n"
end
end
@astroza
astroza / sniffer
Created March 20, 2015 20:44
FOTM sniffer
require 'packetfu'
include PacketFu
iface = ARGV[0] || "en1"
def sniff(iface)
cap = Capture.new(:iface => iface, :start => true)
cap.stream.each do |p|
pkt = Packet.parse p
if pkt.is_tcp?