This file contains hidden or 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
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 |
This file contains hidden or 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
$ 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 |
This file contains hidden or 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 'active_support/callbacks' | |
class Job | |
include ActiveSupport::Callbacks | |
define_callbacks :perform | |
set_callback :perform, :after, :save_omg | |
def perform |
This file contains hidden or 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
# 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() |
This file contains hidden or 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 'bundler/setup' | |
require 'active_support/all' | |
module Feature | |
extend ActiveSupport::Concern | |
included do |base| | |
puts "#{base} included Feature" | |
end | |
end |
This file contains hidden or 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 "net/http" | |
require "uri" | |
trap("TERM") do | |
puts 'terminating...' | |
end | |
loop do | |
begin | |
http = Net::HTTP.new("www.google.com", 81) |
Mixing posix threads and signal handling usually is a bit of a nightmare.
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
This file contains hidden or 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
class Runner | |
def initialize | |
@count = 0 | |
end | |
EXIT_AFTER = 5 | |
def perform | |
loop do | |
puts "Running #{@count}, shutdown: #{@shutdown.inspect}" | |
@count += 1 |