Skip to content

Instantly share code, notes, and snippets.

View sdogruyol's full-sized avatar
Building

Serdar Dogruyol - Sedo セド sdogruyol

Building
View GitHub Profile

Backend Developer

We are looking for team mates which are comfortable with technologies below:

  • Strong OOP principles with a keen eye to clean code
  • You know Ruby, not just Rails.
  • You know how HTTP work and can bend REST to your will.
  • You use *NIX based operating systems. (OS X, Linux derivatives)
  • Git <3
require "http/server"
server = HTTP::Server.new "0.0.0.0", 8080 do |context|
context.response.headers["Content-Type"] = "text/event-stream"
stream_channel = Channel(String).new
spawn do
loop do
sleep 0.1
stream_channel.send "Hello World"
end
require "kemal"
post "/json_params" do |env|
json = env.params.json["likes"].as Array
# You can learn the type like this
puts json.first.class
first = json.first.as Hash(String, JSON::Type)
puts first["id"]
end
require "kemal"
post "/json_params" do |env|
like_objects = env.params.json["_json"].as Array
like_objects.each do |likes|
likes_hash = (likes as Hash(String, JSON::Type))["likes"]
end
end
Kemal.run
require "benchmark"
Benchmark.bm do |x|
$status_code = "200"
$method = "GET"
$path = "api/v1/users"
x.report "Normal String" do
10000000.times do
"|#{$status_code}| #{$method} #{$path}"
# Context is the environment which holds request/response specific
# information such as params, content_type e.g
class HTTP::Server
class Context
STORE = {} of String => Box
def set(key, value)
STORE[key] = {"object": Box.box(value), "type": typeof(value)}
end
lock '3.5.0'
set :application, 'your-app'
set :repo_url, 'https://github.com/your/app'
set :deploy_to, '/home/deploy/apps/your-app/'
namespace :deploy do
after :updated, :build do
on roles(:web) do
execute "cd '#{release_path}' && shards install"
struct Upload
field : String
data : IO::Delimited
meta : HTTP::FormData::FileMetadata
headers : HTTP::Headers
end
def parse_multipart(env)
HTTP::FormData.parse(env.request) do |field, data, meta, headers|
yield Upload.new field, data, meta, headers
sysctl -w fs.file-max=12000500
sysctl -w fs.nr_open=20000500
ulimit -n 20000000
sysctl -w net.ipv4.tcp_mem='10000000 10000000 10000000'
sysctl -w net.ipv4.tcp_rmem='1024 4096 16384'
sysctl -w net.ipv4.tcp_wmem='1024 4096 16384'
sysctl -w net.core.rmem_max=16384
sysctl -w net.core.wmem_max=16384
require "benchmark"
require "colorize"
require "http"
require "spec/dsl"
class String
private PRIME_RK = 2097169u32
def index_old(search : String, offset = 0)
offset += size if offset < 0