Skip to content

Instantly share code, notes, and snippets.

@scottserok
scottserok / benchmark_utility.rb
Created March 11, 2017 13:27
Ruby benchmark utility module to print time spent, memory used, and gc usage.
require 'benchmark'
# Found a couple of useful methods that make benchmarking my scripts easy
# Usage:
# print_gc_usage do
# print_memory_usage do
# print_time_spent do
# SomeClass.new
# end
# end
@scottserok
scottserok / OdooGKE
Last active November 30, 2017 21:34
Odoo ERP Docker Compose
# Disclaimer: This is untested
#
# Odoo.com ERP version 11
#
# Local testing via "$ docker-compose up" and navigating to localhost:8069
#
# Deploy to Google Cloud Platform's Kubernetes Engine to make use of available
# capacity in your existing GKE cluster (if you have it).
#
# 1. Create a GCP account at console.cloud.google.com, install "gcloud" and "kubectl"
@scottserok
scottserok / protobuf-backtrace
Last active December 1, 2017 21:26
protobuf-backtrace-3925
#0 0x00007f5559b3878f in __syscall4 (a4=<optimized out>, a3=<optimized out>, a2=<optimized out>,
a1=<optimized out>, n=<optimized out>) at ./arch/x86_64/syscall_arch.h:38
#1 __restore_sigs (set=set@entry=0x559ecaf49a80) at src/signal/block.c:43
#2 0x00007f5559b388a9 in raise (sig=sig@entry=6) at src/signal/raise.c:13
#3 0x00007f5559b10f2e in abort () at src/exit/abort.c:9
#4 0x00007f55596887e1 in die () at error.c:478
#5 rb_bug_context (ctx=ctx@entry=0x559ecaf49c40, fmt=fmt@entry=0x7f5559837a82 "Segmentation fault at %p")
at error.c:508
#6 0x00007f555977570e in sigsegv (sig=<optimized out>, info=0x559ecaf49d70, ctx=0x559ecaf49c40) at signal.c:907
#7 <signal handler called>
@scottserok
scottserok / 001_secrets.rb
Created April 8, 2018 21:35
Load docker secrets into Rails
# config/initializers/001_secrets.rb
# Loads docker secrets into ENV
# Example docker-compose.yml:
#
# version: "3.4"
# services:
# web:
# image: myapp
# build: .

Keybase proof

I hereby claim:

  • I am scottserok on github.
  • I am scottserok (https://keybase.io/scottserok) on keybase.
  • I have a public key ASB0HHIWyjKG7Ttju5EvL7VpxLL1EMR4aKloaC8s3LN33Ao

To claim this, I am signing this object:

@scottserok
scottserok / wizard.coffee
Last active July 22, 2018 13:19
Multi-step form with support for datepicker and chosen-select written in Coffeescript.
# Abstract Wizard to assist user with building a resource step by step.
# Include https://daneden.github.io/animate.css/ for animations.
#
# <div class="step"> are icons used to indicate which step the user is currently in
#
# <fieldset> are used to define what is displayed in each step of the form
#
# There should be equal number of .step elements as there are fieldset elements
# Create an instance of App.Wizard with the div ID of the modal
# 1 form per App.Wizard instance
@scottserok
scottserok / Dockerfile.aws_ruby_pg
Last active December 4, 2018 22:35
Dockerfile for AWS Serverless Ruby 2.5.3 with PG driver
FROM amazonlinux
LABEL maintainer="scott@serok.us"
RUN yum install -y https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-2.noarch.rpm
RUN sed -i "s/rhel-\$releasever-\$basearch/rhel-latest-x86_64/g" "/etc/yum.repos.d/pgdg-10-redhat.repo"
RUN yum install -y gcc openssl-devel libyaml-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel ruby-devel gcc-c++ jq git patch which tar procps make glibc-devel postgresql10 postgresql-devel
RUN curl https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.3.tar.gz > ruby-2.5.3.tar.gz
RUN tar -xvzf ruby-2.5.3.tar.gz
RUN cd ruby-2.5.3 && ./configure && make && make install
@scottserok
scottserok / email_mx_validator.rb
Last active January 23, 2019 16:37
Add a custom MX validator to your rails app in app/validators/email_mx_validator.rb
# frozen_string_literal: true
require 'mail' unless defined? Mail
require 'resolv' unless defined? Resolv
# == Summary
# This validator checks for a valid DNS MX resource
# for the given email address. The domain of the email
# address is extracted and used to perform a DNS lookup
# for an MX resource. A valid DNS MX resource does not
@scottserok
scottserok / csv_builder.rb
Created January 31, 2019 23:07
Simple class to easily build CSV outputs for your POROs or ActiveRecord models.
# CsvBuilder configures a model to generate a resource. Inspired by ActiveAdmin.
#
# Usage example:
#
# csv_builder = CSVBuilder.new User, col_sep: ';'
# csv_builder.column :id
# csv_builder.column :email
# csv_builder.column("Name") { |resource| resource.display_name }
# csv_builder.headers %w[ID Email Name]
# csv_builder.scope { |scope| scope.where('created_at > ?', 7.days.ago) } # unavailable for POROs
@scottserok
scottserok / tiny_graphql_server.rb
Last active May 8, 2019 17:52
Tiny GraphQL server to share authentication and authorization pattern for mutations
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'graphql'
gem 'rack'
gem 'webrick'
gem 'mail'
end
require 'json'