Skip to content

Instantly share code, notes, and snippets.

@bf4
bf4 / flag_registration.rb
Created April 19, 2024 05:43 — forked from synth/flag_registration.rb
Feature flag code detection
# https://gist.github.com/synth/8c9eee23aa9df535aa42a30f7cff9ba9
require "parser/current"
module Flipper
module FlagRegistration
# These functions are all memoized because they should be static for the
# lifetime of a deployment (albeit they are really static to a Ruby process)
def self.registered_flags
@registered_flags ||= YAML.load_file("config/feature_flags.yml")
end
@bf4
bf4 / download_all_lambda_functions.sh
Created February 27, 2023 15:24 — forked from nemani/download_all_lambda_functions.sh
Download All Lambda Functions
#!/bin/bash
#
# Usage:
# ./download_all.sh
# ./download_all.sh download us-east-1 my-function
# ./download_all.sh help
#
# Downloads all aws-lambda functions to a subdirectory
# Assumes you have a role that has at least read access to lambda.
# Credits to https://gist.github.com/nemani/defdde356b6678352bcd4af69b7fe529
@bf4
bf4 / ruby_data_uri.haml
Created March 18, 2013 17:20
Image to Data URI in ruby
- img_url = "http://example.com/image.jpg"
- img_type = img_url.split('.')[-1]
- img_binary = open(img_url).read
- img_data = ActiveSupport::Base64.encode64(img_binary).gsub("\n", '')
%img{src: "data:image/#{img_type};base64,#{img_data}"}
@bf4
bf4 / polymorphic_many_to_many_in_rails.md
Last active February 6, 2024 21:13
a polymorphic many-to-many association in Rails

This was my solution for a polymorphic many-to-many association

class ItemCountry < ActiveRecord::Base
  belongs_to :locatable, :polymorphic => true
  belongs_to :country
  # fields are :locatable_id, :locatable_type, :country_id
end

class Title < ActiveRecord::Base

has_many :countries, :through => :item_countries, :as => :locatable

@bf4
bf4 / schema_dumper.rb
Created September 21, 2023 01:29 — forked from drnic/schema_dumper.rb
Our rails db includes our own tables/schema and the Salesforce/Heroku Connect schema (under "salesforce.*"). We place this file in config/initializers/schema_dumper.rb and now our rails db:schema:dump includes both our own tables and the salesforce. tables.
# This solution was based on https://gist.github.com/GlenCrawford/16163abab7852c1bd550547f29971c18
Rails.configuration.to_prepare do
ActiveRecord::SchemaDumper.ignore_tables = %w[
salesforce._hcmeta
salesforce._sf_event_log
salesforce._trigger_log
salesforce._trigger_log_archive
]
end
@bf4
bf4 / README.md
Last active May 26, 2023 06:27
clone_all repos

Clone all repos

Install as follows

\curl -sSL https://gist.github.com/bf4/c19f041bb0887476dfaa/download | \
  tar xzvf - --include '*setup' -O | bash

optionally first set PROJECT_DIR and PROJECT_CLONE_URL in your ~/.profile

@bf4
bf4 / Gemfile
Created July 2, 2013 18:36
Rails lograge and logstash request logging
gem 'lograge' # more readable logs
gem 'logstash-event' # for logstash json format
gem 'mono_logger' # threadsafe logging
@bf4
bf4 / read_deps_from_gemspec.rb
Last active January 10, 2023 15:39
resolve gem dependencies
require 'rubygems'
# https://github.com/rubygems/rubygems/blob/master/lib/rubygems/specification.rb#L981
gemspec = 'foo.gemspec'
spec = Gem::Specification.load(gemspec) # from_yaml
spec.dependencies # type (runtime), name (activesupport), requirements (">= 0")
@bf4
bf4 / Gemfile
Created September 7, 2012 18:20
Ruby Time and Timezone walkthrough
source "https://rubygems.org"
gem "rack"
gem "tzinfo"