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/env ruby | |
require 'async' | |
require 'async/io/unix_endpoint' | |
endpoint = Async::IO::Endpoint.unix("foo.ipc") | |
fork do | |
Async do | |
endpoint.accept do |peer| |
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/local' | |
class Searchable | |
extend Thread::Local | |
def initialize | |
@index = "rubygems" | |
end | |
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
Sync do | |
query = subject.call(<<~SQL * 10) | |
SELECT PG_SLEEP(0.1) AS LIFE; | |
SQL | |
query.results do |result| | |
Console.logger.info(query) {"#{result.count} #{result.field_names}"} | |
result.each do |row| | |
Console.logger.info(result, row) | |
end |
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
# gem install async-container | |
gem "async-container" | |
require 'async/clock' | |
require 'async/container' | |
def fibonacci(n) | |
if n < 2 | |
return 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
require_relative 'lib/async/websocket/version' | |
Gem::Specification.new do |spec| | |
spec.name = "async-websocket" | |
spec.version = Async::WebSocket::VERSION | |
spec.authors = ["Samuel Williams"] | |
spec.email = ["samuel.williams@oriontransfer.co.nz"] | |
spec.summary = %q{An async websocket library on top of websocket-driver.} | |
spec.homepage = "" |
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 'benchmark/ips' | |
require 'dry/monads/result' | |
extend Dry::Monads::Result::Mixin | |
def pure_square(x) | |
value = x ** 2 | |
if value > 50 |
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/env ruby | |
require 'async' | |
require 'async/http/internet' | |
Async do |task| | |
internet = Async::HTTP::Internet.new | |
# Effectively a connection timeout: | |
response = task.with_timeout(10) do |
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/env ruby | |
require 'process/pipeline' | |
def process_group_pids(pids) | |
pids.flat_map do |pid| | |
buffer = Process::Pipeline.("pstree -p #{pid}").read | |
buffer.scan(/(?<=\()\d+(?=\))/) | |
end.sort.uniq |
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/env RBENV_VERSION=2.7.0 ruby | |
gem 'async' | |
require 'async' | |
Async do |task| | |
Async.logger.info("Incoming request...") | |
Async(logger: task.logger.with(name: "request-id-1234")) do | |
Async.logger.info("Database Query") |
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
.text | |
.global main | |
main: | |
# Save the non-volatile registers: | |
pushq %r15 | |
pushq %r14 | |
pushq %r13 | |
pushq %r12 | |
pushq %rbx | |