ruby sort hash by value

lets say you have a hash
hh = {1=>'y', 2=>'a'}
if you need to sort a hash by its value this works like this
Hash[hh.sort_by{|k, v| v}]

in case your hash looks like this
hh = {1=>'y',2=>'A'}
you should be aware to change your value to lower case like this
Hash[hh.sort_by{|k, v| v.downcase}]

in case your hash looks like this
hh = {1=>0.0,2=>nil,3=>4.0}
you need to replace nil with a sortable value
hh.sort_by{|k, v| v ? v : 0}

postgresql refresh function

if you have postgresql view that needs to be refreshed immediately after the parent model has changed you need to define a function and a trigger to do so.

the function:
create or replace function refresh_model_view()
returns trigger language plpgsql
as $$
refresh materialized view model;
return null;
end $$;

the trigger
create trigger refresh_model_view_trigger
after insert or update or delete or truncate
on parent_model for each statement
execute procedure refresh_model_view();

more omxplayer options

although been the best videoplayer on the raspberry the documentation is quite spread out over the net. so here the most useful commands to start a omxplayer:

--loop run a video in a loop
--win 'x1 y1 x2 y2' run video in a window defined by upper left corner(x1,y1) and right bottom corner(x2,y2)
--no-osd display without showing information
--blank showing video and blacking the rest of the screen

sub! problem

I had a problem caused by the sub! function.
What I did:
myobj = Model.create({"field"=>"text"})
myobj.field.sub! "text", "replacedwith"
puts myobj.field
#returns replacedwith
puts myobj.field
#returns text

using this line it works
myobj.field = myobj.field.sub "text", "replacedwith"

I am using rails 4.1.5 and ruby 2.0.0

youtube videos on a raspberry pi

if you want to show youtube videos on raspberry pi you better do not go with a web browser but with the omxplayer.
this is a preinstalled videoplayer which is specially made for raspberry pis and works perfectly.

more info on the omxplayer can be found here

to show youtube videos you need the help of youtube-dl. because the package you get via apt-get is not the last version you better install via wget

sudo wget -O /usr/local/bin/youtube-dl
sudo chmod a+x /usr/local/bin/youtube-dl

to play a video go to the terminal and type

omxplayer `youtube-dl -g [yotubeurl]`