Skip to content

Instantly share code, notes, and snippets.

View dkam's full-sized avatar

Dan Milne dkam

View GitHub Profile
@dkam
dkam / gist:4108942
Created November 19, 2012 04:22
Unfuck
$ cat /proc/partitions
major minor #blocks name
11 0 717120 sr0
8 0 732574584 sda
8 1 19679593 sda1
8 2 2931862 sda2
8 3 709960545 sda3
8 32 312571224 sdc
8 33 312570183 sdc1
test "swapping products for collections" do
c = create(:work)
b1 = create(:book, collection: c)
b2 = create(:book, collection: c)
b3 = create(:book)
result = CollectionMethods.swap_product_for_collection([b1,b2,b3])
assert result.length == 2
@dkam
dkam / Image Quality
Last active December 12, 2015 15:59
Image quality
# Smallest images:
dkam@Nervous-Energy ~/booko (master) $ find public/images/covers/* -type f -print0 | xargs -0 du -s | sort -n | head -10 | cut -f2 | xargs -I{} du -sh {} | awk '{ print $2 }' | xargs identify -verbose | grep Quality
Quality: 85
Quality: 85
Quality: 79
Quality: 85
Quality: 77
Quality: 70
Quality: 85
Quality: 85
#!/usr/bin/env ruby
# encoding: UTF-8
###
# Looks for all files in your root media directory with an extension listed in *accepted_formats* array
# then passes them to ffmepg to report back resolution. Reports file name, resolution, resolution name
#
# EG: ./media_size_report.rb /mnt/my_nas/movies
#
# List media sizes in order of most common:
@dkam
dkam / Number_to_human.rb
Last active July 21, 2016 23:56
To Human.
class Numeric
def to_human
units = %w{B KB MB GB TB}
e = (Math.log(self)/Math.log(1024)).floor
s = "%.3f" % (to_f / 1024**e)
s.sub(/\.?0*$/, units[e])
end
end
dkam@Nervous-Energy ~/booko (rails4_visual) $ ab -n 10 -c 2 https://dev.booko.info/9781595824172/Star-Wars-Thrawn-Trilogy
This is ApacheBench, Version 2.3 <$Revision: 1178079 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking dev.booko.info (be patient).....done
Server Software: nginx/1.5.8
Server Hostname: dev.booko.info
dkam@Nervous-Energy ~/booko (rails4_visual) $ ab -n 10 -c 2 http://booko.com.au/9781595824172/Star-Wars-Thrawn-Trilogy
This is ApacheBench, Version 2.3 <$Revision: 1178079 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking booko.com.au (be patient).....done
Server Software: nginx/1.4.4
Server Hostname: booko.com.au
@dkam
dkam / gist:9755012
Created March 25, 2014 03:56
Postgresql pub/sub in Ruby
require 'sequel'
DB = Sequel.connect('postgres://user:pass@localhost/db')
DB.listen(:my_channel, loop: true) {|channel, pid, payload| puts "Got payload '#{payload}' on channel '#{channel}'" }
Sequel.extension(:pg_hstore, :pg_hstore_ops, :pg_array)
DB = Sequel.connect('postgres://user:pass@localhost/db')
class Messages < Sequel::Model
end
Messages.first
#=> #<Messages @values={:id=>1, :observable_name=>"testo", :observable_content=>{"key1"=>"value1", "key2"=>"value2", "key3"=>"value3"}, :created_at=>2014-03-25 15:37:30 +1100}>
@dkam
dkam / Technisat_TS35_lircd.conf
Created July 3, 2014 04:30
Technisat TS35 lircd.conf
begin remote
name /etc/lircd.conf
bits 13
flags RC5|CONST_LENGTH
eps 30
aeps 100
one 907 885
zero 907 885
gap 113935
toggle_bit 2