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" | |
int = 0 | |
[1, 12, 1234, 12345678, 1234567812345678].each do |number| | |
puts "Parsing #{number}..." | |
io = IO::Memory.new | |
io << ":#{number}\r\n" # Redis integer format | |
io.rewind | |
Benchmark.ips do |x| |
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 "socket" | |
module Redis | |
alias Type = String | Int64 | Nil | Array(Type) | |
class Future | |
property! value : Type | |
end | |
module Commands |
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
class Redis | |
module Commands | |
def xadd(stream, id, params : Hash) | |
params = params.each_with_object(Array(String).new(params.size * 2)) do |(key, value), array| | |
array << key << value.to_s | |
end | |
string_command(["XADD", stream, id] + params) | |
end | |
def xrange(stream, start, finish) |
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
/* Data structure to hold our event handlers. It's important that when you | |
remove an element from the DOM that you delete its associated event | |
handler id to avoid memory leaks. | |
{ | |
12345: { // DOM element's event handler id | |
click: [ | |
function(event) { ... }, | |
] | |
}, |
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
// The $url is passed in as the only parameter to this query. The query | |
// handles everything else. | |
CALL apoc.load.jsonParams($url, {Accept: 'application/json'}, null, null, {}) YIELD value AS data | |
// Upsert the person into the DB, using the :Person label in case they aren't | |
// a fully-fledged account yet | |
MERGE (person:Person { id: data.id }) | |
ON CREATE SET | |
person.created_at = datetime() |
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
module SetOperations | |
def union_scope(*scopes) | |
apply_operation :UNION, scopes | |
end | |
def intersect_scope(*scopes) | |
apply_operation :INTERSECT, scopes | |
end | |
def except_scope(*scopes) |
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
--- | |
kind: Service | |
apiVersion: v1 | |
metadata: | |
name: main-app | |
annotations: | |
service.beta.kubernetes.io/do-loadbalancer-protocol: "http" | |
service.beta.kubernetes.io/do-loadbalancer-algorithm: "least_connections" | |
service.beta.kubernetes.io/do-loadbalancer-tls-ports: "443" | |
service.beta.kubernetes.io/do-loadbalancer-certificate-id: "YOUR_CERT_ID_GOES_HERE" |
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 "http" | |
require "uuid" | |
require "uuid/json" | |
class App | |
include HTTP::Handler | |
def call(context) | |
Fiber.yield # Simulate getting data from the DB | |
response_payload.to_json context.response |
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 'ostruct' | |
Post = Comment = User = OpenStruct | |
class PostsWithComments | |
def call | |
results = Model.connection.execute <<~SQL | |
SELECT | |
posts.id, | |
posts.title, |
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
class App | |
# Provides the `call(context : HTTP::Server::Context)` interface | |
include HTTP::Handler | |
# Provides the `route` method that we pass the context to to be | |
# able to use routing and response data | |
include Route | |
def call(context : HTTP::Server::Context) | |
route context do |r, response, session| |