Skip to content

Instantly share code, notes, and snippets.

Jamie Gaskins jgaskins

Block or report user

Report or block jgaskins

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
jgaskins / fetch.cypher
Created Nov 17, 2019
Fetching a remote user
View fetch.cypher
// 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: })
person.created_at = datetime()
jgaskins / set_operations.rb
Created Oct 13, 2019
SQL result set operations for ActiveRecord
View set_operations.rb
module SetOperations
def union_scope(*scopes)
apply_operation :UNION, scopes
def intersect_scope(*scopes)
apply_operation :INTERSECT, scopes
def except_scope(*scopes)
View cluster.yaml
kind: Service
apiVersion: v1
name: main-app
annotations: "http" "least_connections" "443" "YOUR_CERT_ID_GOES_HERE"
jgaskins /
Last active Sep 4, 2019
Serve a sample JSON payload in Crystal
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
jgaskins / stream_each.rb
Last active Aug 22, 2019
Stream results from the database into Ruby objects
View stream_each.rb
require 'ostruct'
Post = Comment = User = OpenStruct
class PostsWithComments
def call
results = Model.connection.execute <<~SQL
jgaskins /
Created Aug 10, 2019
Roda-like web framework in Crystal
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|
jgaskins /
Last active Jun 23, 2019
Neo4j::Bolt::Connection#exec_cast with a block
def exec_cast(query : String, parameters : Map, types : Tuple(*TYPES), &block) forall TYPES
send Commands::Run, query, parameters
send Commands::PullAll
result = read_raw_result
until result[1] != 0x71
# First 3 bytes are Structure, Record, and List
# TODO: If the RETURN clause in the query has more than 16 items,
# this will break because the List byte marker and its size won't be
# in a single byte. We'll need to detect this here.
jgaskins / call_metrics.rb
Last active Mar 24, 2019
Trace metrics for methods defined in Ruby code
View call_metrics.rb
require 'pp'
require 'set'
module CountThings
COUNTS = { |h, k| h[k] = { |h, k| h[k] = 0 } }
TIMINGS = { |h, k| h[k] = { |h, k| h[k] = [] } }
TRACED_METHODS = { |h, k| h[k] = }
jgaskins / hooks.rb
Last active Feb 16, 2019
Hooks implementation for Clearwater
View hooks.rb
module Hooks
def self.component *attrs, &render do
attr_reader *attrs
define_method :initialize do |**props|
attrs.each { |attr| `self[#{attr}] = #{props[attr]}` }
jgaskins / sort-videos.js
Created Dec 11, 2018
Sort Confreaks event videos by number of views
View sort-videos.js
.sort((a, b) => (
a.querySelector('.video-views strong').innerText|0) >= (b.querySelector('.video-views strong').textContent|0)
? -1
: 1
).map(v => v.querySelector('.video-title').innerText + ' by ' + v.querySelector('.video-presenters').innerText)
You can’t perform that action at this time.