Skip to content

Instantly share code, notes, and snippets.

View sepastian's full-sized avatar
💭
\_ . |‾‾‾| o-`o

Sebastian Gassner sepastian

💭
\_ . |‾‾‾| o-`o
View GitHub Profile
@sepastian
sepastian / cache_expiration_in_rails_admin.rb
Created October 31, 2013 15:46
Cache expiration in RailsAdmin using Rails 4
# The Rails Guide on Caching suggests to use ActionController#expire_fragment
# in a controller to expire a cached fragment
# (http://guides.rubyonrails.org/caching_with_rails.html#fragment-caching)
#
# Unfortunately, hooking into controllers is not easily possible in Rails Admin,
# why another strategy for expiring cached fragments must be used.
#
# The Rails Guide also describes how to use custom keys for caching.
# To implement caching in Rails Admin, maintain a custom key for each fragment
# in the cache. Whenever the model changes, use a callback to update the key.
@sepastian
sepastian / m4a2flac.sh
Last active December 28, 2015 04:59
Convert m4a (iTunes store) to FLACC using avconv.
# Convert m4a (iTunes store) to flac using avconv.
ls *m4a | while read f; do avconv -i "$f" "${f/m4a/flac}"; done
@sepastian
sepastian / hash_deep_traverse.rb
Created January 29, 2014 13:36
Hash#deep_traverse extends Ruby's Hash class with a method yielding pairs consisting of path and value. Each path consists of a list of keys leading to the last, right-most key.
class Hash
def deep_traverse(&block)
stack = self.map{ |k,v| [ [k], v ] }
while not stack.empty?
key, value = stack.pop
yield(key, value)
if value.is_a? Hash
value.each{ |k,v| stack.push [ key.dup << k, v ] }
end
end
@sepastian
sepastian / reset_pwd_os_x_10_4.sh
Created February 13, 2014 07:45
Reset the password of any user in Mac OS X 10.4.
# Reset the password of any user in Mac OS X 10.4.
# Boot into single user mode pressing and holding Ctrl + S after pressing the power button.
# When the root prompt appeats, do:
sh /etc/rc
passwd admin
reboot
@sepastian
sepastian / locomotive_cms_install.sh
Last active August 29, 2015 14:00
LocomotiveCMS install
# Install Locomotive CMS's wagon and engine
# Ruby version used: ruby-2.1.1 [ i686 ] RVM
# Depends: mongo, imagemagick
# Wagon
# See http://doc.locomotivecms.com/get-started/install-wagon#linux
gem install locomotivecms_wagon
# Engine
@sepastian
sepastian / gist:3519bc30689fb8650686
Created September 12, 2014 13:32
Upgrading PostgreSQL 9.1 to 9.3 on Debian 7 (wheezy) using pg_upgrade
# https://no0p.github.io/postgresql/2014/03/29/upgrading-pg-ubuntu.html
@sepastian
sepastian / raspberry_headless_initial_login
Last active May 1, 2019 20:16
Headless initial login and initialization of a Raspberry PI
# Use lsleases (https://github.com/j-keck/lsleases) to detect the Raspberries IP address.
# Other suggested using ping and arp, both of which rely on the hostname of the Raspberry to display as 'raspberry';
# depending on the network, the hostname may change;
# lsleases will still work.
$ sudo lsleases -s
2015/01/15 15:36:40 startup - version: 1.4.0
2015/01/15 15:36:40 enable active check - ping every: 15m
#
# Reboot the Raspberry and wait
@sepastian
sepastian / rails_4.2_default.rb
Last active September 25, 2015 05:40
Rails 4.2 template with active admin, devise, pundit, bootstrap, slim, unicorn, pg (optional), git
# Use with `rails new -m https://gist.githubusercontent.com/sepastian/8d9bf523d3950d4c8a4d/raw/88fd29455af48f5d99569063a6239b5dcdac3d96/rails_4.2_default.rb -d postgresql`
require 'fileutils'
if Rails.version !~ /\A4\.2/
puts "Required: Rails 4.2.x; found: Rails #{Rails.version}."
puts "$ bundle update rails"
exit 2
end
@sepastian
sepastian / crontab.sh
Created March 17, 2015 09:02
rbenv and cron
# Run a Ruby script every minute.
# Use the Ruby provided by rbenv.
#
# Edit with crontab -e.
*/1 * * * * /bin/bash -c 'export PATH=$HOME/.rbenv/shims:$HOME/.rbenv/bin:"$PATH"; eval "$(rbenv init -)"; cd $HOME/path/to/script/; ruby ./graph.rb > /output/path/index.html'
### Keybase proof
I hereby claim:
* I am sepastian on github.
* I am sepastian (https://keybase.io/sepastian) on keybase.
* I have a public key whose fingerprint is 214D 35E9 65E8 6DDF AFE4 F388 03AB E849 A825 7946
To claim this, I am signing this object: