Skip to content

Instantly share code, notes, and snippets.

kapcod / export_athena_usage.rb
Created Dec 29, 2021
Export AWS Athena usage history as CSV
View export_athena_usage.rb
require 'csv'
require 'aws-sdk-athena'
def export_athena_usage(limit:, region:, filter_scanned: 10**9)
athena = region: region
next_token = nil
fields = %w[query_execution_id query work_group]
stats_fields = %w[data_scanned_in_bytes total_execution_time_in_millis]
scanned = 0
found = 0
kapcod / cleanup_airflow_logs.rb
Created Oct 10, 2021
Airflow DAG log cleaner. Assumes log structure /var/log/airflow/<dag>/<operator>/<date>. Call: `cleanup_airflow_logs.rb 7` to retain only last week of logs
View cleanup_airflow_logs.rb
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'fileutils'
require 'time'
class AirflowLogCleaner
attr_reader :list, :to_delete
def list_folders
View simple_thread_pool.rb
# frozen_string_literal: true
# SimpleThreadPool gives a simple implementation for producer/consumers pattern
# Example:
# pool =, max_queue: 5) do |user_params|
#, user_params)
# end
# users.each do |user|
# pool << user.update_api_params
kapcod / action_rate_limit.rb
Last active Apr 9, 2021
Simple action rate limit module for Ruby on Rails, intended to be included in ApplicationController
View action_rate_limit.rb
# frozen_string_literal: true
module ActionRateLimit
user: proc { request.cookies['user_id'] },
ip: proc { request.remote_ip },
def self.included(klass)
klass.extend ClassMethods
kapcod /
Created Aug 25, 2020 — forked from skwashd/
Copy AWS SSM Parameter Store Path

This Python (3.6+) script is for migrating Amazon AWS System Manager (SSM) Parameter Store keys from one path to another.

Quick Start

To install the script do the following:

  • Configure your AWS credentials
  • Grab the code from this gist
  • Make it executable (chmod +x /path/to/
  • pip install boto3 (if you don't have it installed already)
kapcod / case_sensitive_headers_post.rb
Created Oct 16, 2017
Hack to send request using Net::HTTP with preserved headers case
View case_sensitive_headers_post.rb
class CaseSensitiveHeadersPost < Net::HTTP::Post
def initialize_http_header(headers)
@header = {}
headers.each do |k,v|
@header[k] = [v]
def capitalize(name)
kapcod / deep_freeze.rb
Last active Jul 6, 2017
Ruby Deep Freeze for Hash and Array classes
View deep_freeze.rb
# Adds deep_freeze! method to Hash
Hash.class_eval do
def deep_freeze!
each_value{|val| val.deep_freeze! if val.respond_to?(:deep_freeze!) }
# Adds deep_freeze! method to Array
Array.class_eval do
kapcod / fix_cookies_escaping.rb
Created Jan 5, 2017
Fix Rack::Utils.set_cookie_header! and delete_cookie_header! escaping
View fix_cookies_escaping.rb
class << Rack::Utils
alias_method :escape_with_plus, :escape
def escape_without_plus(s)
URI.encode_www_form_component(s).gsub('+', '%20')
def mock_escape_for_cookies
singleton_class.send :alias_method, :escape, :escape_without_plus
kapcod / ilya.track_sleep.plist
Created May 24, 2016
Track sleep of the computer with Mac OSX agent config for autoload
View ilya.track_sleep.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
kapcod / find-commit.rb
Created May 1, 2016
Finds git commit that merged other commit into master
View find-commit.rb
commit = ARGV[0]
master = ARGV[1] || 'origin/master'
unless commit
puts "Usage: find-commit.rb commit [master-branch]"
puts "Will show commit that merged <commit> into <master-branch>"
exit 1
parents = `git rev-list #{commit}..#{master} --reverse --first-parent --merges`.split("\n")