Skip to content

Instantly share code, notes, and snippets.

View CGA1123's full-sized avatar
🛰️

Christian Gregg CGA1123

🛰️
View GitHub Profile
def query(conn, sql, timeout_ms:)
conn.send_query(sql)
if conn.block(timeout_ms / 1000.0) # seconds
conn.get_last_result
else
conn.cancel
conn.get_last_result
end
end
require 'concurrent'
module ActiveSupport
module Cache
class AsyncWriteStore < SimpleDelegator
def self.supports_cache_versioning?
true
end
def initialize(klass_or_sym, *args)
@CGA1123
CGA1123 / initializer.rb
Last active January 14, 2020 12:21
umbra setup example
# config/initializers/umbra.rb
require 'umbra'
Umbra.configure do |config|
config.redis_options = { url: ENV['REDISCLOUD_URL'] } # connect to our redis instance
config.error_handler = proc { |e| Bugsnag.notify(e) } # notify our error tracker
config.request_selector = proc { |env, _resp| env['REQUEST_METHOD'] == 'GET' } # only replicate GET requests
config.logger = Rails.logger
end
#!/usr/bin/env bash
set -eu
# Finds the heroku slug id from the compile apps latests releases
# via the commit SHA
function heroku_slug () {
heroku releases --app ${1} --json | \
jq -rc --arg commit "${2}" \
'.[]
#!/usr/bin/env ruby
require 'bugsnag/api'
BUGSNAG_PERSONAL_TOKEN = ENV.fetch('BUGSNAG_PERSONAL_TOKEN')
URL_REGEX = /https:\/\/app.bugsnag.com\/carwow\/(?<project_slug>.*)\/errors\/(?<error_id>[a-zA-Z0-9]+)(\?.*)?/
PROJECTS = {
'project_slug' => 'bugsnag_project_id'
}
class BackfillJob < ApplicationJob
queue_as :backfill
def perform(file_num:, max_file_num:, batch_size: 500)
fetch_from_s3(file_num).each_slice(batch_size) do |ids|
FactoryOrderQuote.where(id: ids).update_all(status: :not_renewable)
end
return if file_num >= max_file_num
#!/usr/bin/env bash
set -eu
QUERY_FILE=
COUNTRY=
BUCKET=
OUTPUT=cars_${COUNTRY}
RAW_OUTPUT=${OUTPUT}.csv
SPLIT_DIR=${OUTPUT}_split
@CGA1123
CGA1123 / backfill_query.sql
Last active May 31, 2019 22:14
Backfill Query
WITH discontinued_derivatives AS (
SELECT id
FROM research_site.derivatives
WHERE date_discontinued IS NOT NULL
AND date_discontinued < current_date
),
unavailable_models AS (
SELECT slug
FROM research_site.models
@CGA1123
CGA1123 / morning.sh
Created June 27, 2018 09:29
Script for a better morning
#!/bin/bash
set -u
# Do things...
tmux start-server
# Open tmux session for a project
function tmux_setup () {
local PROJECT=${1}
local PROJECT_DIR=${MORNING_PROJECTS_HOME}/${PROJECT}
cd ${PROJECT_DIR}
@CGA1123
CGA1123 / bin_test_script.rb
Created December 28, 2016 18:06
Simple Rails Test Script, Resets Database, Runs RSpec, & Rubocop
#!/usr/bin/env ruby
require 'pathname'
# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
Dir.chdir APP_ROOT do
test_env = 'test'
puts "Application Environment: #{test_env}"