Skip to content

Instantly share code, notes, and snippets.

Avatar

Adam Gotterer adamgotterer

  • CTO @ Common
  • New York, NY
View GitHub Profile
@adamgotterer
adamgotterer / Column References.sql
Created Apr 19, 2019
Experiments with storing typed attributes in Postgres
View Column References.sql
CREATE TABLE attribute_types (
attribute_type_id SERIAL PRIMARY KEY,
type TEXT NOT NULL,
value TEXT NOT NULL
);
INSERT INTO attribute_types(type, value) VALUES ('Kitchen', 'Deluxe');
INSERT INTO attribute_types(type, value) VALUES ('Kitchen', 'Small');
INSERT INTO attribute_types(type, value) VALUES ('Windows', 'Clean');
View elevator.py
# elevator.py
from random import randint
# from SimpleXMLRPCServer import SimpleXMLRPCServer # Python 2
from xmlrpc.server import SimpleXMLRPCServer # Python 3
MAX_FLOOR = 10
current_floor = 0
server = SimpleXMLRPCServer(("localhost", 8000), logRequests=False)
@adamgotterer
adamgotterer / websocker.cr
Last active Jul 23, 2018
Crystal WebSocket Client/Server Ping/Pong
View websocker.cr
# Client
require "http"
client = HTTP::WebSocket.new(URI.parse("ws://127.0.0.1:9333"))
client.send "ping"
client.on_message do |str|
puts str
client.send "ping"
sleep 1
@adamgotterer
adamgotterer / Dockerfile
Created Jun 20, 2018
Puppeteer headless chrome with chroxy
View Dockerfile
FROM node:8-slim
ARG DEBIAN_FRONTEND=noninteractive
ENV PUPPETEER_VERSION 1.5.0
ENV CHROXY_VERSION 0.3.2
RUN apt-get update -qqy \
&& apt-get -qqy install \
unzip gnupg curl wget ca-certificates apt-transport-https \
git ttf-wqy-zenhei g++ libzmq3-dev apt-utils vim \
@adamgotterer
adamgotterer / Elevator
Last active May 6, 2019
Ruby Elevator
View Elevator
#!/usr/bin/ruby
# elevator.rb
require 'drb/drb'
requests = []
DRb.start_service('druby://localhost:9999', requests)
tick = 0
loop do
View terraform-crash-log
2016/09/15 17:43:45 [INFO] Terraform version: 0.7.3 0dd7c657d6d60d2e7392b66ae6f74fb84582cab9
2016/09/15 17:43:45 [INFO] CLI args: []string{"/usr/local/Cellar/terraform/0.7.0/bin/terraform", "plan", "-var-file", "terraform.tfvars"}
2016/09/15 17:43:45 [DEBUG] Detected home directory from env var: /Users/adam
2016/09/15 17:43:45 [DEBUG] Detected home directory from env var: /Users/adam
2016/09/15 17:43:45 [DEBUG] Attempting to open CLI config file: /Users/adam/.terraformrc
2016/09/15 17:43:45 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2016/09/15 17:43:45 [DEBUG] Detected home directory from env var: /Users/adam
2016/09/15 17:43:45 [DEBUG] New state was assigned lineage "dbd7fe63-2bfc-4357-b74f-c2b5dc5ee50c"
2016/09/15 17:43:45 [TRACE] Graph after step *terraform.ConfigTransformer:
View terraform-panic
panic: runtime error: index out of range
goroutine 340 [running]:
panic(0x244d600, 0xc420010110)
/opt/go/src/runtime/panic.go:500 +0x1a1
github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil.(*evalCall).Eval(0xc4201c0170, 0x4068ea0, 0xc420437330, 0xc42053c250, 0x0, 0x0, 0x40, 0x0, 0x0)
/opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil/eval.go:231 +0x3f4
github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil.(*evalIndex).Eval(0xc4201c0160, 0x4068ea0, 0xc420437330, 0xc42053c250, 0x0, 0x0, 0x0, 0x2c19ead, 0x0)
/opt/gopath/src/github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil/eval.go:258 +0x12b
github.com/hashicorp/terraform/vendor/github.com/hashicorp/hil.(*evalVisitor).visit(0xc42053c240, 0x406c020, 0xc420220ba0, 0x10, 0xc4204377a0)
@adamgotterer
adamgotterer / deep_transform_values.rb
Created Nov 16, 2015
Recursively transform the values of a Hash or Array
View deep_transform_values.rb
class Hash
def deep_transform_values(&block)
_deep_transform_values_in_object(self, &block)
end
def deep_transform_values!(&block)
_deep_transform_values_in_object!(self, &block)
end
private
@adamgotterer
adamgotterer / dsl.rb
Last active Jul 26, 2016
Endpoint DSL example
View dsl.rb
module DSL
# We put our DSL syntax (methods) in a separate module (ClassMethods) because it
# will be converted to class methods once a class includes it.
module ClassMethods
attr_reader :routes
##### SUPPORTED DSL SYNTAX
def get(uri, &block)
save_route(:get, uri, block)
end
@adamgotterer
adamgotterer / gist:7897574
Last active Dec 30, 2015
Identify en email address under the cursor using rangy
View gist:7897574
// Still a work in progress
// NOTE: Requires Rangy 1.3alpha to use the word options with expand
// NOTE: Must include the core and the text select libraries
// TODO: Update loop to use rangy node iterator
// TODO: Only return email addresses
function getEmailUnderCursor(elem, x, y) {
if(elem.nodeType == elem.TEXT_NODE) {
//var doc_range = elem.ownerDocument.createRange();
var range = rangy.createRange();
You can’t perform that action at this time.