Skip to content

Instantly share code, notes, and snippets.

@thil
thil / db_transaction_adapter.rb
Created October 3, 2023 22:39
Add wrapped db transaction to dry transactions
# frozen_string_literal: true
module DbTransactionAdapter
# Add the ability to wrap number of steps into database transaction
#
# @example
# db_transaction, :db do
# step :validate
# check :clear
# step :create # failure here will rollback previous side effects
@thil
thil / gist:7949f2b006951e75324b
Created July 14, 2014 01:54
Find duplicate names from csv
cat blah.csv | cut -f1 -d , | uniq -d
[mergetool "p4merge"]
cmd = /Applications/p4merge.app/Contents/MacOS/p4merge "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
keepTemporaries = false
trustExitCode = false
keepBackup = false
[merge]
tool = p4merge
@thil
thil / gist:5085359
Last active December 14, 2015 12:19
remove every second file
ls | sed -n "p;N;" | xargs rm -r
#remove spaces from file
for file in *;do mv $file ${file// /};done
@thil
thil / gist:4654659
Created January 28, 2013 11:06
Sinatra database rake tasks
require 'active_record'
require 'fileutils'
namespace :db do
desc "loads database configuration in for other tasks to run"
task :load_config do
ActiveRecord::Base.configurations = db_conf
ActiveRecord::Base.establish_connection db_conf
end