Skip to content

Instantly share code, notes, and snippets.

View TALlama's full-sized avatar

Seth A. Roby TALlama

View GitHub Profile
@TALlama
TALlama / anonymizer.rb
Created May 17, 2024 16:03
This class will use your existing FactoryBot factories to rewrite the data already in the db, keeping the associations and structure but replacing the content.
class Anonymizer
include ActiveSupport::Benchmarkable
attr_reader :factory_names, :callbacks
def initialize(factory_names = nil, callbacks = {})
raise ArgumentError.new("You must be in development to use the anonymizer") unless Rails.env.development?
require Rails.root.join("spec/factories") unless FactoryBot.factories.count > 0
@factory_names = [*factory_names].compact.map(&:to_sym)
@TALlama
TALlama / git-pit
Last active May 16, 2024 17:01
Keep your local git branches clean! This is a script I use to loop through all my local branches, then delete any branches that have already landed in upstream. It will notice if it landed as a merge commit or a rebase. It will list out what's merged and not for any branches it keeps, so you can tell what you should revisit and what you should g…
#!/usr/bin/env ruby
require "colorize"
class Branch
attr_reader :name, :base_branch
def initialize(name, base)
@name = name
@base_branch = base || %x{git log -1 --format="%h" @{u}}.chomp
@TALlama
TALlama / gist:6527241
Created September 11, 2013 17:52
Using CodeClimate's coverage reporting alongside an existing formatter.
require "codeclimate-test-reporter"
CodeClimate::TestReporter.start
# output Rcov-style coverage files
require 'simplecov'
require 'simplecov-rcov'
class SimpleCov::Formatter::MergedFormatter
def format(result)
require "codeclimate-test-reporter"
p ||= Chronic::Parser.new
def p.get_anchor(tokens, options)
puts "get_anchor", " tokens: #{tokens}"
grabber = Chronic::Grabber.new(:this)
pointer = :future
repeaters = get_repeaters(tokens)
repeaters.size.times { tokens.pop }
puts " grabber: #{grabber}"
@TALlama
TALlama / jquery.visibletext.js
Created July 29, 2012 01:54
A jQuery extension to return only the visible text in a node.
jQuery.fn.visibleText = function() {
if (this.length === 0) return null;
if (this.length > 1) return this.first().visibleText();
if (this[0].nodeType === 3) return this.text();
var buffer = [];
$.each(this.contents(), function(ix, e) {
if ($(e).is(':visible')) {
return buffer.push($(e).visibleText());
}
@TALlama
TALlama / screenshot.js
Created June 19, 2012 22:07 — forked from javan/screenshot.js
Create a screenshot of any URL using phantomjs (headless webkit)
//
// Example usage: phantomjs screenshot.js http://yahoo.com /tmp/yahoo.png
//
var system = require('system');
var url = system.args[1];
var filename = system.args[2];
var page = new WebPage();
page.open(url, function (status) {
@TALlama
TALlama / gist:1901983
Created February 24, 2012 16:51
Tweet from Safari
tell application "Safari"
set _tab to the current tab of window 1
tell _tab to do JavaScript "var t = escape(getSelection()); if (t.length > 0) t = '“'+t+'”: '; window.location = 'twitterrific:///post?message='+t+''+escape(window.location.href)"
end tell
@TALlama
TALlama / fizzbuzzbenchmark.rb
Created December 22, 2010 23:21
Spending way too much time optimizing code that does nothing, with metrics.
require 'benchmark'
def fizzbuzz_if(k)
k%3==0 ? (k%5==0 ? "fizzbuzz" : "fizz") : (k%5==0 ? "buzz" : k)
end
def fizzbuzz_d(k)
{true => {true => "fizzbuzz", false => "fizz"}, false => {true => "buzz"}}[k%3==0][k%5==0] || k
end
<input type='file' id='picker'>
<img style='border: 1px solid black' id='img'>
<script>
var onFilePicked = function(el, callback, opts) {
opts = opts || {}
var delayedCallback = function(url) {
setTimeout(function() {callback(url)}, 0);
}
el.onchange = el.onmouseout = function(event) {