Skip to content

Instantly share code, notes, and snippets.

iter = Enumerator.new do |yielder|
yielder.yield "start"
3.times { |n| yielder.yield(n) }
yielder.yield "end"
end
# iter.each do |n|
# puts n
# end
$ curl -v https://js.pusher.com/4.0/pusher.min.js
* Trying 23.111.9.14...
* TCP_NODELAY set
* Connected to js.pusher.com (23.111.9.14) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: /etc/ssl/cert.pem
CApath: none
@kirs
kirs / sigint.rb
Created September 19, 2017 13:22
require 'active_support/callbacks'
class Job
include ActiveSupport::Callbacks
define_callbacks :perform
set_callback :perform, :after, :save_omg
def perform
@kirs
kirs / gdb_ruby_backtrace.py
Created September 3, 2017 16:22 — forked from csfrancis/gdb_ruby_backtrace.py
Dump an MRI call stack from gdb
# Updated for Ruby 2.3
string_t = None
def get_rstring(addr):
s = addr.cast(string_t.pointer())
if s['basic']['flags'] & (1 << 13):
return s['as']['heap']['ptr'].string()
else:
return s['as']['ary'].string()
require 'bundler/setup'
require 'active_support/all'
module Feature
extend ActiveSupport::Concern
included do |base|
puts "#{base} included Feature"
end
end
require "net/http"
require "uri"
trap("TERM") do
puts 'terminating...'
end
loop do
begin
http = Net::HTTP.new("www.google.com", 81)
@kirs
kirs / gist:2a0025466944def92b3be3e0d04266cd
Created April 9, 2017 15:20 — forked from tonyc/gist:1384523
Using strace and lsof

Using strace and lsof to debug blocked processes

You can use strace on a specific pid to figure out what a specific process is doing, e.g.:

strace -fp <pid>

You might see something like:

select(9, [3 5 8], [], [], {0, 999999}) = 0 (Timeout)

Mixing posix threads and signal handling usually is a bit of a nightmare.

Ceri Storey, 2013

In what context is the signal handler executed?

Ruby executes the signal handler in the same thread as the parent. It can be proven by:

$stdout.sync = true
class Runner
def initialize
@count = 0
end
EXIT_AFTER = 5
def perform
loop do
puts "Running #{@count}, shutdown: #{@shutdown.inspect}"
@count += 1