Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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_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 / 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 / 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 / pull_remote_db.sh
Last active April 22, 2022 10:28
Bash Script to dump remote db & restore on local
#!/usr/bin/env bash
##
# @section Variables
SOURCE_DB=
TARGET_DB=
REMOTE_USER=${REMOTE_USER:-"postgres"}
SSH_URI=
SSH_OPTIONS=${SSH_OPTIONS:-""}
@estum
estum / array_input.coffee
Created September 2, 2016 08:21
SimpleForm: Array Input
@Forms ?= {}
class Forms.ArrayInput
REMOVE_BUTTON_HTML = """<button type="button" class="close" aria-label="Close"><span aria-hidden="true">&times;</span></button>"""
ADD_ITEM_SELECTOR = "a.array-input-add-item"
getTargetFrom = (element) ->
el = ($ element)
el.closest(el.data("target"))
@estum
estum / swallow_reader.rb
Created September 4, 2016 10:24
Swallow Reader extension for Active Record Has One Through Association
# = Swallow Reader
#
# Adds <tt>:swallow</tt> option to <tt>has_one :through</tt> association builder.
# When this option set to <tt>true</tt> and through association was loaded, target record will
# be readed directly from parent without executing the join query.
#
# For example:
#
# class Review < ActiveRecord::Base
# belongs_to :song