Listing posts
Displaying posts 271 - 275 of 318 in total
Rails | Handle common controller exceptions
Last update
2017-06-30
2017-06-30
«rescue controller exceptions»
Here is an example that shows how to deal with the common ActionController::InvalidAuthenticityToken
error:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # app/controllers/application_controller.rb class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. protect_from_forgery with: :exception # http://stackoverflow.com/questions/32133648/rails-test-against-and-handle-actioncontrollerinvalidauthenticitytoken/32135194#32135194 rescue_from ActionController::InvalidAuthenticityToken, with: :rescue_from_invalid_authenticity_token protected def rescue_from_invalid_authenticity_token(exception) render layout: true, text: 'document expired' end end |
~~~ * ~~~
Linux sparse file
Last update
2017-06-21
2017-06-21
« — »
To create a sparse file:
1 | dd if=/dev/zero of=file.ext bs=1 count=0 seek=10G |
The command ls -slh file.ext
will output something like this:
1 | 3G -rw------- 1 cloud cloud 10G Jan 01 2017 file.ext |
there are two size columns: the first 3G
is the allocated space and the second 10G
is the max space allocable (that means we still have 7G
of space left).
See also Wiki archlinux
~~~ * ~~~
Images tile collage
Last update
2017-06-17
2017-06-17
« — »
1 2 | # 1920x1080 with 1px border on black background montage [1-6].jpg -tile 3x2 -geometry 638x538+1+1 -background black out.jpg |
1 2 3 4 5 | # process each image in current folder: Dir['*.jpg'].sort.each_slice(6).each_with_index do |names, i| print "#{i}\r" system %Q|montage #{names.join ' '} -tile 3x2 -geometry 638x538+1+1 -background black out/#{'%04d' % i}.jpg| end; puts '' |
~~~ * ~~~
~~~ * ~~~
ALSA multiple soundcard slot order
Last update
2017-05-11
2017-05-11
« — »
Edit /etc/modprobe.d/alsa-base.conf
to sort them (I have three devices):
1 2 3 4 5 | options snd slots=snd-emu10k1,snd-hda-intel,snd-bt87x options snd-emu10k1 index=0 options snd-hda-intel index=1 options bt87x index=2 |
Source: ALSA