Skip to content

Instantly share code, notes, and snippets.

@rahim
rahim / dump_known_transactions.rb
Created June 14, 2021 12:58
Dump all routable Rails transactions
#! /usr/bin/env ruby
# This dumps all known transactions (including engines) in standard controller#action format to STDOUT
#
# Built against private Rails 5.2.x APIs so success with other Rails versions is likely to be hit and miss.
require_relative "../config/environment"
class CustomInspector < ActionDispatch::Routing::RoutesInspector
def format(formatter, filter = nil)
@rahim
rahim / delayed_stats.sql
Last active May 25, 2021 21:31
Delayed Jobs MySQL stats extraction
DROP FUNCTION IF EXISTS dj_extract_active_job_class_from_handler;
CREATE FUNCTION dj_extract_active_job_class_from_handler(handler TEXT)
RETURNS TEXT DETERMINISTIC
RETURN SUBSTRING_INDEX(
SUBSTRING_INDEX(handler, '\n job_id: ', 1),
'job_class: ', -1);
DROP FUNCTION IF EXISTS dj_extract_class_method_from_handler;
CREATE FUNCTION dj_extract_class_method_from_handler(handler TEXT)
RETURNS TEXT DETERMINISTIC
@rahim
rahim / function.rb
Created August 11, 2020 12:07
Aggregate, analyze structured deprecation logs from s3 with lambda
require "aws-sdk-s3"
require "shellwords"
require "json"
def handler(event:, context:)
# Get the record
first_record = event["Records"].first
bucket_name = first_record["s3"]["bucket"]["name"]
object_key = first_record["s3"]["object"]["key"]
@rahim
rahim / wonderblum.html
Created July 23, 2020 08:54
Wonderblum Sample Email HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Wonderblum ⁕</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="shortcut icon" type="image/png" href="https://thebetter.email/favicon.png">
<style type="text/css">
@rahim
rahim / .gitattributes
Created March 19, 2018 16:07 — forked from strax/.gitattributes
Auto-resolving schema.rb version conflicts on Rails 4.0+
db/schema.rb merge=railsschema
@rahim
rahim / Monokai Extended.tmTheme
Created October 6, 2016 15:59
Very slightly tweaked Monokai
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!-- Generated by: TmTheme-Editor -->
<!-- ============================================ -->
<!-- app: http://tmtheme-editor.herokuapp.com -->
<!-- code: https://github.com/aziz/tmTheme-Editor -->
<plist version="1.0">
<dict>
<key>author</key>
<string>github.com&#x2f;jonschlinkert</string>
diff --git i/db/schema.rb w/db/schema.rb
index 8052e88..7617614 100644
--- i/db/schema.rb
+++ w/db/schema.rb
@@ -610,7 +610,7 @@ ActiveRecord::Schema.define(version: 20160408155519) do
add_index "builder_recipients", ["account_id"], name: "index_builder_recipients_on_account_id", using: :btree
add_index "builder_recipients", ["email"], name: "index_builder_recipients_on_email", using: :btree
- add_index "builder_recipients", ["opted_token"], name: "index_builder_recipients_on_opted_token", unique: true, using: :btree
+ add_index "builder_recipients", ["opted_token"], name: "index_builder_recipients_on_opted_token", unique: true, length: {"opted_token"=>100}, using: :btree
@rahim
rahim / smart_default_dir.sh
Created January 25, 2016 12:42
Time based default dir smarts
dayofweek=`date +%u` # Monday is 1
hourofday=`date +%H`
if test $dayofweek -lt 6 -a $hourofday -gt 8 -a $hourofday -lt 19
then
(hostname | grep koto > /dev/null 2>&1) && cd ~/working/litmus
fi
# Nice idea, but doesn't play well with my iTerm config for default dirs
@rahim
rahim / azure_sas.rb
Last active August 29, 2015 14:16
Manually testing Azure Shared Access Signatures in Ruby
# see http://stackoverflow.com/questions/21994466/signature-did-not-match-on-azure-sas-url
# see https://msdn.microsoft.com/library/azure/dn140255.aspx
# see https://msdn.microsoft.com/en-us/library/azure/dn140256.aspx
# see https://github.com/Azure/azure-sdk-for-ruby/issues/162
# This assumes the Azure Ruby SDK is already loaded and initialized with appropriate config
# Note we need the empty strings as the empty lines are required in the signed string
DEFAULTS = {
path: '/',
@rahim
rahim / gist:f657a9dc75f1dc82a772
Created March 6, 2015 10:15
ISO8601 millisecond handling in Ruby 2.1.5
2.1.5 (main):0 > Time.now.strftime('%Y-%m-%d %H:%M:%S.%L')
=> "2015-03-06 10:09:12.974"
2.1.5 (main):0 > str = Time.now.strftime('%Y-%m-%d %H:%M:%S.%L')
=> "2015-03-06 10:09:26.497"
2.1.5 (main):0 > Time.parse(str)
=> 2015-03-06 10:09:26 +0000
2.1.5 (main):0 > t = Time.parse(str)
=> 2015-03-06 10:09:26 +0000
2.1.5 (main):0 > t.strftime('%Y-%m-%d %H:%M:%S.%L')
=> "2015-03-06 10:09:26.497"