source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | madeintandem/hstore_accessor | https://github.com/madeintandem/hstore_accessor | hstore_accessor.gemspec | Ruby | mit | 243 | master | 1,655 | # coding: utf-8
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "hstore_accessor/version"
Gem::Specification.new do |spec|
spec.name = "hstore_accessor"
spec.version = HstoreAccessor::VERSION
spec.authors = ["Joe Hirn", "Cory Stephen... |
github | madeintandem/hstore_accessor | https://github.com/madeintandem/hstore_accessor | Appraisals | Ruby | mit | 243 | master | 344 | appraise "activerecord-5.1" do
gem "activerecord", "~> 5.1.0"
end
appraise "activerecord-5.0" do
gem "activerecord", "~> 5.0.0"
end
appraise "activerecord-4.2" do
gem "activerecord", "~> 4.2.0"
end
appraise "activerecord-4.1" do
gem "activerecord", "~> 4.1.0"
end
appraise "activerecord-4.0" do
gem "active... |
github | madeintandem/hstore_accessor | https://github.com/madeintandem/hstore_accessor | Rakefile | Ruby | mit | 243 | master | 213 | require "rubygems"
require "bundler/setup"
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "rubocop/rake_task"
RSpec::Core::RakeTask.new
RuboCop::RakeTask.new
task(default: [:rubocop, :spec]) |
github | madeintandem/hstore_accessor | https://github.com/madeintandem/hstore_accessor | lib/hstore_accessor.rb | Ruby | mit | 243 | master | 770 | require "active_support"
require "active_record"
require "hstore_accessor/version"
if ::ActiveRecord::VERSION::STRING.to_f >= 5.0
require "hstore_accessor/active_record_5.0/type_helpers"
elsif ::ActiveRecord::VERSION::STRING.to_f >= 4.2 && ::ActiveRecord::VERSION::STRING.to_f < 5.0
require "hstore_accessor/active_... |
github | madeintandem/hstore_accessor | https://github.com/madeintandem/hstore_accessor | lib/hstore_accessor/macro.rb | Ruby | mit | 243 | master | 6,340 | module HstoreAccessor
module Macro
module ClassMethods
def hstore_accessor(hstore_attribute, fields)
@@hstore_keys_and_types ||= {}
"hstore_metadata_for_#{hstore_attribute}".tap do |method_name|
singleton_class.send(:define_method, method_name) do
fields
end
... |
github | madeintandem/hstore_accessor | https://github.com/madeintandem/hstore_accessor | lib/hstore_accessor/serialization.rb | Ruby | mit | 243 | master | 1,330 | module HstoreAccessor
module Serialization
InvalidDataTypeError = Class.new(StandardError)
VALID_TYPES = [
:boolean,
:date,
:datetime,
:decimal,
:float,
:integer,
:string
]
DEFAULT_SERIALIZER = ->(value) { value.to_s }
DEFAULT_DESERIALIZER = DEFAULT_SERI... |
github | madeintandem/hstore_accessor | https://github.com/madeintandem/hstore_accessor | lib/hstore_accessor/active_record_4.2/type_helpers.rb | Ruby | mit | 243 | master | 899 | module HstoreAccessor
module TypeHelpers
TYPES = {
boolean: ActiveRecord::Type::Boolean,
date: ActiveRecord::Type::Date,
datetime: ActiveRecord::Type::DateTime,
decimal: ActiveRecord::Type::Decimal,
float: ActiveRecord::Type::Float,
integer: ActiveRecord::Type::Integer,
s... |
github | madeintandem/hstore_accessor | https://github.com/madeintandem/hstore_accessor | lib/hstore_accessor/active_record_pre_4.2/time_helper.rb | Ruby | mit | 243 | master | 1,168 | module HstoreAccessor
module TimeHelper
# There is a bug in ActiveRecord::ConnectionAdapters::Column#string_to_time
# which drops the timezone. This has been fixed, but not released.
# This method includes the fix. See: https://github.com/rails/rails/pull/12290
def self.string_to_time(string)
r... |
github | madeintandem/hstore_accessor | https://github.com/madeintandem/hstore_accessor | lib/hstore_accessor/active_record_pre_4.2/type_helpers.rb | Ruby | mit | 243 | master | 978 | module HstoreAccessor
module TypeHelpers
TYPES = {
string: "char",
datetime: "datetime",
date: "date",
float: "float",
boolean: "boolean",
decimal: "decimal",
integer: "int"
}
class << self
def column_type_for(attribute, data_type)
ActiveRecord::Con... |
github | madeintandem/hstore_accessor | https://github.com/madeintandem/hstore_accessor | lib/hstore_accessor/active_record_5.0/type_helpers.rb | Ruby | mit | 243 | master | 884 | module HstoreAccessor
module TypeHelpers
TYPES = {
boolean: ActiveRecord::Type::Boolean,
date: ActiveRecord::Type::Date,
datetime: ActiveRecord::Type::DateTime,
decimal: ActiveRecord::Type::Decimal,
float: ActiveRecord::Type::Float,
integer: ActiveRecord::Type::Integer,
s... |
github | madeintandem/hstore_accessor | https://github.com/madeintandem/hstore_accessor | spec/hstore_accessor_spec.rb | Ruby | mit | 243 | master | 23,211 | require "spec_helper"
require "active_support/all"
FIELDS = {
name: :string,
color: :string,
price: :integer,
published: { data_type: :boolean, store_key: "p" },
weight: { data_type: :float, store_key: "w" },
popular: :boolean,
build_timestamp: :datetime,
released_at: :date,
likes: :integer,
miles:... |
github | madeintandem/hstore_accessor | https://github.com/madeintandem/hstore_accessor | spec/spec_helper.rb | Ruby | mit | 243 | master | 1,331 | require "hstore_accessor"
require "database_cleaner"
require "shoulda-matchers"
DatabaseCleaner.strategy = :truncation
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :active_record
end
end
RSpec.configure do |config|
config.mock_with :rspec
... |
github | sosedoff/goodreads | https://github.com/sosedoff/goodreads | goodreads.gemspec | Ruby | mit | 244 | master | 1,274 | require File.expand_path("../lib/goodreads/version", __FILE__)
Gem::Specification.new do |spec|
spec.name = "goodreads"
spec.version = Goodreads::VERSION.dup
spec.summary = "Goodreads API wrapper"
spec.description = "Simple wrapper for the Goodreads API"
spec.homepage = "http://github.com/s... |
github | sosedoff/goodreads | https://github.com/sosedoff/goodreads | spec/spec_helper.rb | Ruby | mit | 244 | master | 788 | $LOAD_PATH.unshift(File.expand_path("../..", __FILE__))
require "simplecov"
SimpleCov.start do
add_filter "spec/"
add_filter ".bundle"
end
require "goodreads"
require "webmock"
require "webmock/rspec"
def stub_get(path, params, fixture_name)
params[:format] = "xml"
stub_request(:get, api_url(path))
.wit... |
github | sosedoff/goodreads | https://github.com/sosedoff/goodreads | spec/client_spec.rb | Ruby | mit | 244 | master | 18,015 | require "spec_helper"
require "oauth"
describe Goodreads::Client do
let(:client) { Goodreads::Client.new(api_key: "SECRET_KEY") }
before(:each) { Goodreads.reset_configuration }
describe "#new" do
it "requires an argument" do
expect { Goodreads::Client.new(nil) }
.to raise_error(ArgumentError... |
github | sosedoff/goodreads | https://github.com/sosedoff/goodreads | spec/authentication_spec.rb | Ruby | mit | 244 | master | 965 | require "spec_helper"
describe Goodreads::Client do
before :each do
Goodreads.reset_configuration
end
let(:client) do
described_class.new(api_key: api_key)
end
context "API key is missing" do
let(:api_key) {}
it "throws an error" do
expect { client.book_by_isbn("0307463745") }
... |
github | sosedoff/goodreads | https://github.com/sosedoff/goodreads | spec/goodreads_spec.rb | Ruby | mit | 244 | master | 1,554 | require "spec_helper"
describe Goodreads do
describe ".new" do
it "returns a new client instance" do
expect(Goodreads.new).to be_a(Goodreads::Client)
end
end
describe ".configure" do
it "sets a global configuration options" do
config = Goodreads.configure(api_key: "FOO", api_secret: "BAR... |
github | sosedoff/goodreads | https://github.com/sosedoff/goodreads | lib/goodreads.rb | Ruby | mit | 244 | master | 856 | require "goodreads/version"
require "goodreads/errors"
require "goodreads/request"
require "goodreads/client"
module Goodreads
class << self
attr_accessor :options
end
self.options = {}
# Create a new Goodreads::Client instance
#
def self.new(params = {})
Goodreads::Client.new(params)
end
# D... |
github | sosedoff/goodreads | https://github.com/sosedoff/goodreads | lib/goodreads/errors.rb | Ruby | mit | 244 | master | 258 | module Goodreads
class Error < StandardError; end
class ConfigurationError < Error; end
class Forbidden < Error; end
class Unauthorized < Error; end
class NotFound < Error; end
class ServerError < Error; end
class UnknownError < Error; end
end |
github | sosedoff/goodreads | https://github.com/sosedoff/goodreads | lib/goodreads/request.rb | Ruby | mit | 244 | master | 2,920 | require "active_support/core_ext/hash"
require "rest-client"
require "hashie"
module Goodreads
module Request
API_URL = "https://www.goodreads.com"
API_FORMAT = "xml"
protected
# Perform an API request using API key or OAuth token
#
# path - Request path
# params - Parameters hash
... |
github | sosedoff/goodreads | https://github.com/sosedoff/goodreads | lib/goodreads/client.rb | Ruby | mit | 244 | master | 1,520 | require "goodreads/client"
require "goodreads/client/books"
require "goodreads/client/reviews"
require "goodreads/client/authors"
require "goodreads/client/users"
require "goodreads/client/shelves"
require "goodreads/client/authorized"
require "goodreads/client/groups"
require "goodreads/client/friends"
module Goodrea... |
github | sosedoff/goodreads | https://github.com/sosedoff/goodreads | lib/goodreads/client/authors.rb | Ruby | mit | 244 | master | 668 | module Goodreads
module Authors
# Get author details
#
def author(id, params = {})
params[:id] = id
data = request("/author/show", params)
Hashie::Mash.new(data["author"])
end
# Get an author's books
#
def author_books(id, params = {})
params[:id] = id
data =... |
github | sosedoff/goodreads | https://github.com/sosedoff/goodreads | lib/goodreads/client/books.rb | Ruby | mit | 244 | master | 948 | module Goodreads
module Books
# Search for books
#
# query - Text to match against book title, author, and ISBN fields.
# options - Optional search parameters
#
# options[:page] - Which page to returns (default: 1)
# options[:field] - Search field. One of: title, author, or genre (defaul... |
github | sosedoff/goodreads | https://github.com/sosedoff/goodreads | lib/goodreads/client/friends.rb | Ruby | mit | 244 | master | 277 | module Goodreads
module Friends
# Get the specified user's friends
#
# user_id - integer or string
#
def friends(user_id, options={})
data = oauth_request("/friend/user/#{user_id}", options)
Hashie::Mash.new(data["friends"])
end
end
end |
github | sosedoff/goodreads | https://github.com/sosedoff/goodreads | lib/goodreads/client/groups.rb | Ruby | mit | 244 | master | 407 | module Goodreads
module Groups
# Get group details
def group(group_id)
data = request("/group/show", id: group_id)
Hashie::Mash.new(data["group"])
end
# Get list of groups a given user is a member of
def group_list(user_id, sort = "my_activity")
data = request("/group/list", id:... |
github | sosedoff/goodreads | https://github.com/sosedoff/goodreads | lib/goodreads/client/shelves.rb | Ruby | mit | 244 | master | 3,067 | module Goodreads
module Shelves
# Lists shelves for a user
def shelves(user_id, options = {})
options = options.merge(user_id: user_id, v: 2)
data = request("/shelf/list.xml", options)
shelves = data["shelves"]
shelves = data["shelves"]["user_shelf"].map do |s|
Hashie::Mash.ne... |
github | sosedoff/goodreads | https://github.com/sosedoff/goodreads | lib/goodreads/client/reviews.rb | Ruby | mit | 244 | master | 3,409 | module Goodreads
module Reviews
# Recent reviews from all members.
#
# params[:skip_cropped] - Select only non-cropped reviews
#
def recent_reviews(params = {})
skip_cropped = params.delete(:skip_cropped) || false
data = request("/review/recent_reviews", params)
return unless dat... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | tipi.gemspec | Ruby | mit | 244 | master | 2,206 | require_relative './lib/tipi/version'
Gem::Specification.new do |s|
s.name = 'tipi'
s.version = Tipi::VERSION
s.licenses = ['MIT']
s.summary = 'Tipi - the All-in-one Web Server for Ruby Apps'
s.author = 'Sharon Rosner'
s.email = 'sharon@noteflakes.com'
s.files = `git ls... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | benchmarks/bm_http1_parser.rb | Ruby | mit | 244 | master | 1,982 | # frozen_string_literal: true
require 'bundler/setup'
HTTP_REQUEST = "GET /foo HTTP/1.1\r\nHost: example.com\r\nAccept: */*\r\n\r\n"
def measure_time_and_allocs
4.times { GC.start }
GC.disable
t0 = Time.now
a0 = object_count
yield
t1 = Time.now
a1 = object_count
[t1 - t0, a1 - a0]
ensure
GC.enable... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/http_request_ws_server.rb | Ruby | mit | 244 | master | 651 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
require 'tipi/websocket'
def ws_handler(conn)
timer = spin_loop(interval: 1) do
conn << Time.now.to_s
end
while (msg = conn.recv)
conn << "you said: #{msg}"
end
ensure
timer.stop
end
opts = {
reuse_addr: true,
dont_linger: tr... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/websocket_demo.rb | Ruby | mit | 244 | master | 1,802 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
require 'tipi/websocket'
class WebsocketClient
def initialize(url, headers = {})
@socket = TCPSocket.new('127.0.0.1', 1234)
do_handshake(url, headers)
end
def do_handshake(url, headers)
handshake = WebSocket::Handshake::Client.new... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/routing_server.rb | Ruby | mit | 244 | master | 532 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
opts = {
reuse_addr: true,
dont_linger: true
}
puts "pid: #{Process.pid}"
puts 'Listening on port 4411...'
app = Tipi.route do |r|
r.on_root do
r.redirect '/hello'
end
r.on 'hello' do
r.on_get 'world' do
r.respond 'Hello ... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/servername_cb.rb | Ruby | mit | 244 | master | 905 | # frozen_string_literal: true
require 'openssl'
require 'fiber'
ctx = OpenSSL::SSL::SSLContext.new
f = Fiber.new { |peer| loop { p peer: peer; _name, peer = peer.transfer nil } }
ctx.servername_cb = proc { |_socket, name|
p servername_cb: name
f.transfer([name, Fiber.current]).tap { |r| p result: r }
}
socket =... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/zlib-bench.rb | Ruby | mit | 244 | master | 416 | # frozen_string_literal: true
FILE_SIZES = {
's.tmp' => 2**10,
'm.tmp' => 2**17,
'l.tmp' => 2**20,
'xl.tmp' => 2**24
}
def create_files
FILE_SIZES.each { |fn, size|
IO.write(File.join('/tmp', fn), '*' * size)
}
end
create_files
run { |req|
file_path = File.join('/tmp', req.path)
if File.file?... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/http1_parser.rb | Ruby | mit | 244 | master | 1,227 | # frozen_string_literal: true
require 'polyphony'
require_relative '../lib/tipi_ext'
i, o = IO.pipe
module ::Kernel
def trace(*args)
STDOUT.orig_write(format_trace(args))
end
def format_trace(args)
if args.first.is_a?(String)
if args.size > 1
format("%s: %p\n", args.shift, args)
el... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/http_server_graceful.rb | Ruby | mit | 244 | master | 414 | # frozen_string_literal: true
require 'bundler/setup'
require 'polyphony'
require 'tipi'
opts = {
reuse_addr: true,
dont_linger: true
}
server = spin do
Tipi.serve('0.0.0.0', 1234, opts) do |req|
req.respond("Hello world!\n")
end
end
trap('SIGHUP') do
puts 'got hup'
server.interrupt
end
puts "pid:... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/full_service.rb | Ruby | mit | 244 | master | 375 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
::Exception.__disable_sanitized_backtrace__ = true
certificate_db_path = File.expand_path('certificate_store.db', __dir__)
certificate_store = Tipi::ACME::SQLiteCertificateStore.new(certificate_db_path)
Tipi.full_service(
certificate_store: cert... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/rack_server.rb | Ruby | mit | 244 | master | 454 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
app_path = ARGV.first || File.expand_path('./config.ru', __dir__)
unless File.file?(app_path)
STDERR.puts "Please provide rack config file (there are some in the examples directory.)"
exit!
end
app = Tipi::RackAdapter.load(app_path)
opts = { re... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/hanami-api.ru | Ruby | mit | 244 | master | 255 | # frozen_string_literal: true
require 'hanami/api'
class ExampleApi < Hanami::API
get '/hello' do
'Hello world!'
end
get '/' do
redirect '/hello'
end
get '/404' do
404
end
get '/500' do
500
end
end
run ExampleApi.new |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/https_server.rb | Ruby | mit | 244 | master | 1,439 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
require 'localhost/authority'
::Exception.__disable_sanitized_backtrace__ = true
authority = Localhost::Authority.fetch
opts = {
reuse_addr: true,
dont_linger: true,
}
puts "pid: #{Process.pid}"
puts 'Listening on port 1234...'
ctx = a... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/http_server_throttled.rb | Ruby | mit | 244 | master | 362 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
$throttler = Polyphony::Throttler.new(1000)
opts = { reuse_addr: true, dont_linger: true }
server = spin do
Tipi.serve('0.0.0.0', 1234, opts) do |req|
$throttler.call { req.respond("Hello world!\n") }
end
end
puts "pid: #{Process.pid}"
puts... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/https_wss_server.rb | Ruby | mit | 244 | master | 819 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
require 'tipi/websocket'
require 'localhost/authority'
def ws_handler(conn)
timer = spin do
throttled_loop(1) do
conn << Time.now.to_s
rescue StandardError
nil
end
end
while (msg = conn.recv)
puts "msg: #{msg}"
... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/http_server_static.rb | Ruby | mit | 244 | master | 464 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
require 'fileutils'
opts = {
reuse_addr: true,
dont_linger: true
}
puts "pid: #{Process.pid}"
puts 'Listening on port 4411...'
root_path = FileUtils.pwd
trap('INT') { exit! }
Tipi.serve('0.0.0.0', 4411, opts) do |req|
path = File.join(roo... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/websocket_server.rb | Ruby | mit | 244 | master | 460 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
require 'tipi/websocket'
def ws_handler(conn)
while (msg = conn.recv)
conn << "you said: #{msg}"
end
end
opts = {
reuse_addr: true,
dont_linger: true,
upgrade: {
websocket: Tipi::Websocket.handler(&method(:ws_handler))
}
}
... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/websocket_client.rb | Ruby | mit | 244 | master | 1,394 | # frozen_string_literal: true
require 'bundler/setup'
require 'polyphony'
require 'websocket'
::Exception.__disable_sanitized_backtrace__ = true
class WebsocketClient
def initialize(url, headers = {})
@socket = TCPSocket.new('127.0.0.1', 1234)
do_handshake(url, headers)
end
def do_handshake(url, heade... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/http_server_throttled_accept.rb | Ruby | mit | 244 | master | 477 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
::Exception.__disable_sanitized_backtrace__ = true
opts = {
reuse_addr: true,
reuse_port: true,
dont_linger: true
}
server = Tipi.listen('0.0.0.0', 1234, opts)
puts 'Listening on port 1234'
throttler = Polyphony::Throttler.new(i... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/rack_server_forked.rb | Ruby | mit | 244 | master | 625 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
app_path = ARGV.first || File.expand_path('./config.ru', __dir__)
unless File.file?(app_path)
STDERR.puts "Please provide rack config file (there are some in the examples directory.)"
exit!
end
app = Tipi::RackAdapter.load(app_path)
opts = { re... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/http_server.rb | Ruby | mit | 244 | master | 801 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
opts = {
reuse_addr: true,
dont_linger: true
}
puts "pid: #{Process.pid}"
puts 'Listening on port 10080...'
# GC.disable
# Thread.current.backend.idle_gc_period = 60
spin_loop(interval: 10) { p Thread.backend.stats }
spin_loop(interval: 10)... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/rack_server_https_forked.rb | Ruby | mit | 244 | master | 641 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
require 'localhost/authority'
app_path = ARGV.first || File.expand_path('./config.ru', __dir__)
app = Tipi::RackAdapter.load(app_path)
authority = Localhost::Authority.fetch
opts = {
reuse_addr: true,
reuse_port: true,
dont_linger: ... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/http_unix_socket_server.rb | Ruby | mit | 244 | master | 314 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
path = '/tmp/tipi.sock'
puts "pid: #{Process.pid}"
puts "Listening on #{path}"
FileUtils.rm(path) rescue nil
socket = UNIXServer.new(path)
Tipi.accept_loop(socket, {}) do |req|
req.respond("Hello world!\n")
rescue Exception => e
p e
end |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/http_server_routes.rb | Ruby | mit | 244 | master | 494 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
opts = {
reuse_addr: true,
dont_linger: true
}
puts "pid: #{Process.pid}"
puts 'Listening on port 4411...'
app = Tipi.route do |req|
req.on 'stream' do
req.send_headers('Foo' => 'Bar')
sleep 1
req.send_chunk("foo\n")
sleep 1... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/cuba.ru | Ruby | mit | 244 | master | 377 | # frozen_string_literal: true
require 'cuba'
require 'cuba/safe'
require 'delegate' # See https://github.com/rack/rack/pull/1610
Cuba.use Rack::Session::Cookie, secret: '__a_very_long_string__'
Cuba.plugin Cuba::Safe
Cuba.define do
on get do
on 'hello' do
res.write 'Hello world!'
end
on root do... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/http_server_timeout.rb | Ruby | mit | 244 | master | 562 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
opts = {
reuse_addr: true,
dont_linger: true
}
def timeout_handler(timeout, &handler)
->(req) do
cancel_after(timeout) { handler.(req) }
rescue Polyphony::Cancel
req.respond("timeout\n", ':status' => 502)
end
end
sleep 0
spin d... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/http_ws_server.rb | Ruby | mit | 244 | master | 648 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
require 'tipi/websocket'
def ws_handler(conn)
timer = spin_loop(interval: 1) do
conn << Time.now.to_s
end
while (msg = conn.recv)
conn << "you said: #{msg}"
end
rescue Exception => e
p e
ensure
timer.stop
end
opts = {
reuse_ad... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/http_server_simple.rb | Ruby | mit | 244 | master | 205 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
puts "pid: #{Process.pid}"
puts 'Listening on port 1234...'
Tipi.serve('0.0.0.0', 1234) do |req|
req.respond("Hello world!\n")
end |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/rack_server_https.rb | Ruby | mit | 244 | master | 446 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
require 'localhost/authority'
app_path = ARGV.first || File.expand_path('./config.ru', __dir__)
app = Tipi::RackAdapter.load(app_path)
authority = Localhost::Authority.fetch
opts = {
reuse_addr: true,
dont_linger: true,
secure_context:... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/websocket_secure_server.rb | Ruby | mit | 244 | master | 562 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
require 'localhost/authority'
def ws_handler(conn)
while (msg = conn.recv)
conn << "you said: #{msg}"
end
end
authority = Localhost::Authority.fetch
opts = {
reuse_addr: true,
dont_linger: true,
upgrade: {
websocket:... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/https_server_forked.rb | Ruby | mit | 244 | master | 643 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
require 'localhost/authority'
::Exception.__disable_sanitized_backtrace__ = true
authority = Localhost::Authority.fetch
opts = {
reuse_addr: true,
dont_linger: true,
secure_context: authority.server_context
}
server = Tipi.listen('0.0... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/http_server_form.rb | Ruby | mit | 244 | master | 402 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
opts = {
reuse_addr: true,
dont_linger: true
}
puts "pid: #{Process.pid}"
puts 'Listening on port 4411...'
spin do
Tipi.serve('0.0.0.0', 4411, opts) do |req|
body = req.read
body2 = req.read
req.respond("body: #{body} (body2: #{... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | examples/http_server_forked.rb | Ruby | mit | 244 | master | 595 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
::Exception.__disable_sanitized_backtrace__ = true
opts = {
reuse_addr: true,
reuse_port: true,
dont_linger: true
}
server = Tipi.listen('0.0.0.0', 1234, opts)
child_pids = []
8.times do
pid = Polyphony.fork do
puts "forked pid: #{Pr... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | df/routing_benchmark.rb | Ruby | mit | 244 | master | 1,439 | # frozen_string_literal: true
require 'bundler/setup'
require 'polyphony'
require 'tipi/digital_fabric'
class FakeAgent
def initialize(idx)
@idx = idx
end
end
def setup_df_service_with_agents(agent_count)
server = DigitalFabric::Service.new
agent_count.times do |i|
server.mount({path: "/#{i}"}, FakeA... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | df/etc_benchmark.rb | Ruby | mit | 244 | master | 216 | # frozen_string_literal: true
require 'securerandom'
def generate
SecureRandom.uuid
end
count = 100000
GC.disable
t0 = Time.now
count.times { generate }
elapsed = Time.now - t0
puts "rate: #{count / elapsed}/s" |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | df/agent.rb | Ruby | mit | 244 | master | 1,715 | # frozen_string_literal: true
require 'bundler/setup'
require 'polyphony'
require 'json'
require 'tipi/digital_fabric/protocol'
require 'tipi/digital_fabric/agent'
Protocol = DigitalFabric::Protocol
class SampleAgent < DigitalFabric::Agent
def initialize(id, server_url)
@id = id
super(server_url, { host: "... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | df/server.rb | Ruby | mit | 244 | master | 547 | # frozen_string_literal: true
require_relative 'server_utils'
listeners = [
listen_http,
listen_https,
listen_unix
]
spin_loop(interval: 60) { GC.compact } if GC.respond_to?(:compact)
begin
log('Starting DF server')
Fiber.await(*listeners)
rescue Interrupt
log('Got SIGINT, shutting down gracefully')
@... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | df/multi_agent_supervisor.rb | Ruby | mit | 244 | master | 1,804 | # frozen_string_literal: true
require 'bundler/setup'
require 'polyphony'
require 'json'
require 'fileutils'
FileUtils.cd(__dir__)
require_relative 'agent'
class AgentManager
def initialize
@running_agents = {}
@pending_actions = Queue.new
@processor = spin_loop { process_pending_action }
end
def... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | df/stress.rb | Ruby | mit | 244 | master | 455 | # frozen_string_literal: true
require 'bundler/setup'
require 'polyphony'
require 'fileutils'
FileUtils.cd(__dir__)
def monitor_process(cmd)
while true
puts "Starting #{cmd}"
Polyphony::Process.watch(cmd)
sleep 5
end
end
puts "pid: #{Process.pid}"
puts 'Starting stress test'
spin { monitor_process(... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | df/sample_agent.rb | Ruby | mit | 244 | master | 1,904 | # frozen_string_literal: true
require 'bundler/setup'
require 'polyphony'
require 'json'
require 'tipi/digital_fabric/protocol'
require 'tipi/digital_fabric/agent'
Protocol = DigitalFabric::Protocol
class SampleAgent < DigitalFabric::Agent
HTML_WS = IO.read(File.join(__dir__, 'ws_page.html'))
HTML_SSE = IO.read(... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | df/server_utils.rb | Ruby | mit | 244 | master | 5,272 | # frozen_string_literal: true
require 'bundler/setup'
require 'tipi'
require 'tipi/digital_fabric'
require 'tipi/digital_fabric/executive'
require 'json'
require 'fileutils'
require 'time'
require 'polyphony/extensions/debug'
FileUtils.cd(__dir__)
@service = DigitalFabric::Service.new(token: 'foobar')
@executive = D... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | df/multi_client.rb | Ruby | mit | 244 | master | 1,808 | # frozen_string_literal: true
require 'bundler/setup'
require 'polyphony'
require 'http/parser'
class Client
def initialize(id, host, port, http_host, interval)
@id = id
@host = host
@port = port
@http_host = http_host
@interval = interval.to_f
@interval_delta = @interval / 2
end
def ru... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | test/eg.rb | Ruby | mit | 244 | master | 620 | # frozen_string_literal: true
module Kernel
RE_CONST = /^[A-Z]/.freeze
RE_ATTR = /^@(.+)$/.freeze
def eg(hash)
Module.new.tap do |m|
s = m.singleton_class
hash.each do |k, v|
case k
when RE_CONST
m.const_set(k, v)
when RE_ATTR
m.instance_variable_se... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | test/test_http_server.rb | Ruby | mit | 244 | master | 6,018 | # frozen_string_literal: true
require_relative 'helper'
require 'tipi'
class String
def crlf_lines
gsub "\n", "\r\n"
end
end
class HTTP1ServerTest < Minitest::Test
def teardown
@server&.interrupt if @server&.alive?
sleep 0.01
super
end
def spin_server(opts = {}, &handler)
server_connec... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | test/coverage.rb | Ruby | mit | 244 | master | 1,092 | # frozen_string_literal: true
require 'coverage'
require 'simplecov'
class << SimpleCov::LinesClassifier
alias_method :orig_whitespace_line?, :whitespace_line?
def whitespace_line?(line)
line.strip =~ /^(begin|end|ensure|else|\})|(\s*rescue\s.+)$/ || orig_whitespace_line?(line)
end
end
module Coverage
EX... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | test/helper.rb | Ruby | mit | 244 | master | 2,583 | # frozen_string_literal: true
require 'bundler/setup'
require 'fileutils'
require_relative './eg'
require_relative './coverage' if ENV['COVERAGE']
require 'minitest/autorun'
require 'polyphony'
::Exception.__disable_sanitized_backtrace__ = true
class Minitest::Test
def setup
# trace "* setup #{self.name}"
... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | test/test_request.rb | Ruby | mit | 244 | master | 1,976 | # frozen_string_literal: true
require_relative 'helper'
require 'tipi'
class String
def http_lines
gsub "\n", "\r\n"
end
end
class RequestHeadersTest < Minitest::Test
def teardown
@server&.interrupt if @server&.alive?
snooze
super
end
def spin_server(opts = {}, &handler)
server_connect... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi.rb | Ruby | mit | 244 | master | 1,754 | # frozen_string_literal: true
require 'polyphony'
require_relative './tipi/http1_adapter'
require_relative './tipi/http2_adapter'
require_relative './tipi/configuration'
require_relative './tipi/response_extensions'
require_relative './tipi/acme'
require 'qeweney/request'
class Qeweney::Request
include Tipi::Resp... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/handler.rb | Ruby | mit | 244 | master | 828 | # frozen_string_literal: true
require_relative './rack_adapter'
require_relative './http1_adapter'
require_relative './http2_adapter'
module Tipi
class DefaultHandler
def initialize(config)
@config = config
app_path = ARGV.first || './config.ru'
@app = Tipi::RackAdapter.load(app_path)
end... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/configuration.rb | Ruby | mit | 244 | master | 1,408 | # frozen_string_literal: true
require_relative './handler'
module Tipi
module Configuration
class << self
def supervise_config
current_runner = nil
while (config = receive)
old_runner, current_runner = current_runner, spin { run(config) }
old_runner&.stop
end
... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/http2_stream.rb | Ruby | mit | 244 | master | 5,555 | # frozen_string_literal: true
require 'http/2'
require 'qeweney/request'
module Tipi
# Manages an HTTP 2 stream
class HTTP2StreamHandler
attr_reader :conn
def initialize(adapter, stream, conn, first, &block)
@adapter = adapter
@stream = stream
@conn = conn
@first = first
@co... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/controller.rb | Ruby | mit | 244 | master | 275 | # frozen_string_literal: true
require 'bundler/setup'
require 'json'
# get opts from STDIN
opts = JSON.parse(ARGV[0]) rescue nil
mod_path = "./controller/#{opts['app_type']}_#{opts['mode']}"
require_relative mod_path
controller = Tipi::Controller.new(opts)
controller.run |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/websocket.rb | Ruby | mit | 244 | master | 1,297 | # frozen_string_literal: true
require 'digest/sha1'
require 'websocket'
module Tipi
# Websocket connection
class Websocket
def self.handler(&block)
proc do |adapter, headers|
req = Qeweney::Request.new(headers, adapter)
websocket = req.upgrade_to_websocket
block.(websocket)
... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/supervisor.rb | Ruby | mit | 244 | master | 1,975 | # frozen_string_literal: true
require 'polyphony'
require 'json'
module Tipi
module Supervisor
class << self
def run(opts)
puts "Start supervisor pid: #{Process.pid}"
@opts = opts
@controller_watcher = start_controller_watcher
supervise_loop
end
def start_contr... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/http1_adapter.rb | Ruby | mit | 244 | master | 9,079 | # frozen_string_literal: true
require 'h1p'
require 'qeweney/request'
require_relative './http2_adapter'
module Tipi
# HTTP1 protocol implementation
class HTTP1Adapter
attr_reader :conn
# Initializes a protocol adapter instance
def initialize(conn, opts)
@conn = conn
@opts = opts
@... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/cli.rb | Ruby | mit | 244 | master | 2,579 | # frozen_string_literal: true
require 'tipi'
require 'fileutils'
require 'tipi/supervisor'
require 'optparse'
module Tipi
DEFAULT_OPTS = {
app_type: :web,
mode: :polyphony,
workers: 1,
threads: 1,
listen: ['http', 'localhost', 1234],
path: '.',
}
def self.opts_from_argv(argv)
opts =... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/config_dsl.rb | Ruby | mit | 244 | master | 3,431 | # frozen_string_literal: true
module Tipi
module Configuration
class Interpreter
# make_blank_slate
def initialize(assembler)
@assembler = assembler
end
def gzip_response
@assembler.emit 'req = Tipi::GZip.wrap(req)'
end
def log(out)
@assembler.wrap_c... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/rack_adapter.rb | Ruby | mit | 244 | master | 696 | # frozen_string_literal: true
require 'rack'
module Tipi
module RackAdapter
class << self
def run(app)
->(req) { respond(req, app.(env(req))) }
end
def load(path)
src = IO.read(path)
instance_eval(src, path, 1)
end
def env(request)
Qeweney.rack_env... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/acme.rb | Ruby | mit | 244 | master | 8,565 | # frozen_string_literal: true
require 'openssl'
require 'acme-client'
require 'localhost/authority'
module Tipi
module ACME
class Error < StandardError
end
class CertificateManager
def initialize(master_ctx:, store:, challenge_handler:, valid_hosts:)
@master_ctx = master_ctx
@stor... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/response_extensions.rb | Ruby | mit | 244 | master | 414 | # frozen_string_literal: true
require 'qeweney/request'
module Tipi
module ResponseExtensions
SPLICE_CHUNKS_SIZE_THRESHOLD = 2**20
def serve_io(io, opts)
if !opts[:stat] || opts[:stat].size >= SPLICE_CHUNKS_SIZE_THRESHOLD
@adapter.respond_from_io(self, io, opts[:headers], opts[:chunk_size] ||... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/http2_adapter.rb | Ruby | mit | 244 | master | 2,904 | # frozen_string_literal: true
require 'http/2'
require_relative './http2_stream'
# patch to fix bug in HTTP2::Stream
class HTTP2::Stream
def end_stream?(frame)
case frame[:type]
when :data, :headers, :continuation
frame[:flags]&.include?(:end_stream)
else false
end
end
end
module Tipi
# H... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/controller/stock_http1_adapter.rb | Ruby | mit | 244 | master | 217 | # frozen_string_literal: true
require 'tipi/http1_adapter'
module Tipi
class StockHTTP1Adapter < HTTP1Adapter
def initialize(conn, opts)
super(conn, opts)
end
def each(&block)
end
end
end |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/controller/web_polyphony.rb | Ruby | mit | 244 | master | 9,965 | # frozen_string_literal: true
require 'tipi'
require 'localhost/authority'
require_relative './extensions'
module Tipi
class Controller
def initialize(opts)
@opts = opts
@path = File.expand_path(@opts['path'])
@service = prepare_service
end
WORKER_COUNT_RANGE = (1..32).freeze
def... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/controller/extensions.rb | Ruby | mit | 244 | master | 734 | # frozen_string_literal: true
require 'tipi'
module Kernel
def run(app = nil, &block)
Tipi.app = app || block
end
end
module Tipi
class << self
attr_writer :app
def app
return @app if @app
raise 'No app define. The app to run should be set using `Tipi.app = ...`'
end
def run_... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/controller/web_stock.rb | Ruby | mit | 244 | master | 17,647 | # frozen_string_literal: true
require 'ever'
require 'localhost/authority'
require 'http/parser'
require 'qeweney'
require 'tipi/rack_adapter'
require_relative './extensions'
module Tipi
class Listener
def initialize(server, &handler)
@server = server
@handler = handler
end
def accept
... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/digital_fabric/request_adapter.rb | Ruby | mit | 244 | master | 899 | # frozen_string_literal: true
require_relative './protocol'
module DigitalFabric
class RequestAdapter
def initialize(agent, msg)
@agent = agent
@id = msg[Protocol::Attribute::ID]
end
def protocol
'df'
end
def get_body_chunk(request)
@agent.get_http_request_body(@id, 1)
... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/digital_fabric/agent.rb | Ruby | mit | 244 | master | 6,403 | # frozen_string_literal: true
require_relative './protocol'
require_relative './request_adapter'
require 'msgpack'
require 'tipi/websocket'
require 'tipi/request'
module DigitalFabric
class Agent
def initialize(server_url, route, token)
@server_url = server_url
@route = route
@token = token
... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/digital_fabric/service.rb | Ruby | mit | 244 | master | 7,061 | # frozen_string_literal: true
require_relative './protocol'
require_relative './agent_proxy'
require 'securerandom'
module DigitalFabric
class Service
attr_reader :token
attr_reader :timer
def initialize(token: )
@token = token
@agents = {}
@routes = {}
@counters = {
con... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/digital_fabric/agent_proxy.rb | Ruby | mit | 244 | master | 9,301 | # frozen_string_literal: true
require_relative './protocol'
require 'msgpack'
require 'tipi/websocket'
module DigitalFabric
class AgentProxy
def initialize(service, req)
@service = service
@req = req
@conn = req.adapter.conn
@msgpack_reader = MessagePack::Unpacker.new
@requests = {... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/digital_fabric/executive.rb | Ruby | mit | 244 | master | 2,855 | # frozen_string_literal: true
require 'tipi/digital_fabric'
require 'json'
module DigitalFabric
# agent for managing DF service
class Executive
INDEX_HTML = IO.read(File.join(__dir__, 'executive/index.html'))
attr_reader :last_service_stats
def initialize(service, route = { path: '/executive' })
... |
github | digital-fabric/tipi | https://github.com/digital-fabric/tipi | lib/tipi/digital_fabric/protocol.rb | Ruby | mit | 244 | master | 3,104 | # frozen_string_literal: true
module DigitalFabric
module Protocol
PING = 'ping'
SHUTDOWN = 'shutdown'
UNMOUNT = 'unmount'
HTTP_REQUEST = 'http_request'
HTTP_RESPONSE = 'http_response'
HTTP_UPGRADE = 'http_upgrade'
HTTP_GET_REQUEST_BODY = 'http_get_request_body'
HTTP_REQUEST_BODY = '... |
github | nofxx/georuby | https://github.com/nofxx/georuby | georuby.gemspec | Ruby | mit | 243 | master | 755 | # -*- encoding: utf-8 -*-
lib = File.expand_path('../lib/', __FILE__)
$LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
require 'geo_ruby/version'
Gem::Specification.new do |s|
s.name = 'georuby'
s.version = GeoRuby::VERSION
s.authors = ['Guilhem Vellut', 'Marcos Piccinini', 'Marcus Mateus', 'Doug Cole... |
github | nofxx/georuby | https://github.com/nofxx/georuby | Guardfile | Ruby | mit | 243 | master | 429 | #
# GeoRuby Guardfile
#
ignore(/\/.#.+/)
# notification :off
guard :rubocop, all_on_start: false, keep_failed: false, notification: false, cli: ['--format', 'emacs', '-D'] do
watch(/^lib\/(.+)\.rb$/)
end
guard :rspec, cmd: 'bundle exec rspec', notification: true, title: 'GeoRuby' do
watch(/^spec\/.+_spec\.rb$/)
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.