Skip to content

Instantly share code, notes, and snippets.

@dira
dira / gist:d172776adaef81876df7b519fe32b64c
Last active January 28, 2020 09:32
Convert a pdf (table with text) to very readable jpgs, one per pdf page
# install gs (Ghostscript)
# install ImageMagick
# add to ~/.bash_profile:
pdf_to_jpg () {
filename=${1:-5}
precision=${2:-1}
convert -density 150 $filename -background white -alpha background -alpha off +adjoin -quality 100 -sharpen 0x1.0 "${filename%.*}-%0${precision}d.jpg"
}
kill -s sigusr2 `ps -aux | awk '/puma/ {print $2}' | awk 'NR==1'`
@dira
dira / .bash_profile
Created November 27, 2018 11:10
Git flow: bash commands for quick deploy
alias get_in_master='git checkout develop && git pull && git checkout master && git pull && git merge --no-edit develop'
alias push_it='git push && git checkout develop'
@dira
dira / reflect_on_associations.rb
Created January 9, 2018 14:03
Rails - use reflection to get all declared ActiveRecord associations between entities
Rails.application.eager_load!
data = ActiveRecord::Base.descendants.map{|klass| [klass, klass.reflections.map{|k, v| [v.class.name, k]}] }
data.map{|klass, relations| relations.map{|k, v| "#{klass} #{k.gsub('ActiveRecord::Reflection::', '').gsub('Reflection', '').underscore.humanize.downcase} #{v}"} }.flatten
@dira
dira / count_todos.bash
Created July 3, 2017 08:41
Count how many #TODO you have in a (Rails) app
ack TODO app | grep TODO | wc -l; ack TODO lib | grep TODO | wc -l; ack TODO spec | grep TODO | wc -l
class LegacyInspector
def initialize(should_have_data_newer_than=nil)
@should_have_data_newer_than = should_have_data_newer_than || 6.months.ago
end
def connection
@connection ||= ActiveRecord::Base.connection;
end
def tables
@dira
dira / gist:3e6473a6110d635eeecb
Created June 19, 2014 14:04
vim: refresh current buffer
:e
@dira
dira / gist:7102780
Last active December 26, 2015 05:48
refer to an object's constructor in coffeescript
object.constructor
exiftool "-AllDates+=13:2:13 0:0:0" .
@dira
dira / get_captions.js
Created October 15, 2012 13:23
Get all caption texts in the 'Captions' screen in Picasa
areas = document.getElementsByTagName('textarea')
for (i in areas) {
text = areas[i].innerHTML
if (text !== undefined && text.indexOf('Click to') == -1) {
console.log(text);
}
}