Skip to content

Instantly share code, notes, and snippets.

@estum
estum / app-env
Last active February 13, 2024 14:33
Simple dotenv wrapper on Bash (replace dotenv gem).
#!/usr/bin/env bash
#
#/ Usage: app-env [[-e <DOTENV_FILE>]... ] [[-s <SOURCE_FILE>]... ] [--] <command> [<args>...]
#/ app-env [-h|--help]
#/
#/ Executes a given command with environment variables loaded from dotenv files.
#/ Dotenv files are executed in current shell context, wrapped with `set -e'.
#/ Source files, which are set with the `-s' flag will be included after `set +e'
#/ It is possible to provide several files, just by using flags as many tymes as you need.
#/
@estum
estum / cached_count.rb
Last active April 22, 2016 22:00
CachedCount: the ActiveRecord::Relation extension to speed up query records
require "redis"
require "cityhash"
module CachedCount
mattr_accessor(:ttl, instance_accessors: false) { 60 }
mattr_accessor(:redis, instance_accessors: false) { Redis.new }
class << self
def flush!
keys = redis.scan_each(match: "cached_count/*").to_a
@estum
estum / pry-show_tables.rb
Created October 15, 2015 09:51
Pry `show-tables` command to list tables for the current ActiveRecord connection.
Pry::Commands.create_command "show-tables" do
group "Rails"
description "List tables for the current ActiveRecord connection"
def options(opt)
opt.banner unindent <<-BANNER
Usage: show-tables
List tables for the current ActiveRecord connection
BANNER
end
@estum
estum / README.md
Last active October 5, 2015 18:18 — forked from jherdman/README.md
A Gem loading benchmark script

Benchmark Bundler

Because loading gems can take longer than you think

$ curl -fsSL https://gist.github.com/estum/0420eb893c053ae632a5/raw/a8b66f4b248c2c2597e90c3cc4aae505f4bd0f78/benchmark.rb | ruby
............................................................[DONE]

Gem                            Time(sec)     Pct %
--------------------------------------------------
@estum
estum / pry-show_translation.rb
Last active October 15, 2015 09:47
pry: Command to show the I18n translations tree for the given path
Pry::Commands.create_command "show-translation" do
group "Rails"
description "Show translations for the given path"
def options(opt)
opt.banner unindent <<-BANNER
Usage: show-translation [ -y | -r ] <lang.translated.path>
Show translations for the given path.
BANNER
@estum
estum / assign_icon.jsx
Last active August 29, 2015 14:23
OSX JavaScript: Assign given icon to file or folder
#!/usr/bin/env osascript -l JavaScript
// ==========
// = Usage:
// ./assign_icon.jsx TARGET_FILE SOURCE_IMAGE
// ==========
ObjC.import("Cocoa");
function run(input) {
@estum
estum / osascript.rb
Created June 17, 2015 02:08
Ruby Osascript runner class
class Osascript
def self.call(*args, &block)
new(&block).call(*args)
end
attr_accessor :script
def initialize(script = nil, lang: "AppleScript")
@script = block_given? ? yield : script
@lang = lang
@estum
estum / array_to_proc.rb
Last active August 29, 2015 14:19
Array#to_proc: quick iterate chaining calls like .map(&[...])
unless Array.method_defined?(:to_proc)
class Array
# Converts array to proc with chained calls of items.
# Every item can be either a method name or an array with
# a method name and args.
#
# ==== Examples
#
# the_hash = { :one => "One", :two => "Two", :three => 3, :four => nil }
# mapping = { "one" => "1", "two" => "2", "" => "0" }
@estum
estum / awesome_print_proc.rb
Created April 13, 2015 00:33
AwesomePrint::Proc: inspecting Proc instances with source code (using Sourcify)
# = Awesome Print Proc Formatter
#
# Prints source when inspecting Proc object.
# Requires <tt>sourcify (>= 0.6.0.rc4)</tt> gem.
begin
require "sourcify"
rescue LoadError
end
@estum
estum / README.rdoc
Last active August 23, 2023 13:47
iTerm: Coprocess-script to auto-paste sudo password from keychain

iTerm Coprocess-script to auto-paste sudo password from keychain

Usage

  1. Open Keychain Access.app and create new object using the host as a name (“example.com”), username with sudo rights (“user”) and it’s password.

  2. Add a trigger for iTerm’s profile (‘Advanced‘ tab):

    • Regular Expression: \$ sudo

    • Action: Run Coprocess…

    • Parameters: /path/to/iterm_reply_with_keychain.rb user@example.com