summaryrefslogtreecommitdiffstats
path: root/functions
blob: 78e07fdfd6ac2983b8dcd77e4a1ed13b063febcf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
function web {
    local port=$1
    if [[ -z $port ]]; then
        plackup -MPlack::App::Directory -e'Plack::App::Directory->new'
    else
        plackup -MPlack::App::Directory -e'Plack::App::Directory->new' --port $port
    fi
}
function perldoc {
    # XXX bash specific
    if type cpandoc > /dev/null 2>&1; then
        cpandoc "$@"
    else
        command perldoc "$@"
    fi
}
function webcam {
    local width=$1
    local height=$2
    if [[ -z $width ]];  then width=640;  fi
    if [[ -z $height ]]; then height=480; fi
    mplayer tv:// -tv driver=v4l2:width=${width}:height=${height}:device=/dev/video0 -fps 15 -vf screenshot
}
function webcam_record {
    local width=$1
    if [[ -z $width ]];  then width=640;  else shift; fi
    local height=$1
    if [[ -z $height ]]; then height=480; else shift; fi
    mencoder tv:// -tv driver=v4l2:width=${width}:height=${height}:device=/dev/video0:forceaudio:adevice=/dev/dsp -ovc lavc -oac mp3lame -lameopts cbr:br=64:mode=3 -o $1
}
function setfont {
    printf '\e]710;%s\007\e]711;%s\007' "$1" "$1"
}
function mem_usage {
    ps -eo rss,ucmd | sort -rn | head -n$([ -z "$1" ] && echo 20 || echo $1)
}
function opened_files {
    strace $* 2>&1 | grep -E '^open\('   | \
                     grep -v ENOENT      | \
                     grep -v O_DIRECTORY | \
                     cut -f2 -d"\"" | \
                     grep -vE '^/proc/'  | \
                     grep -v '^/sys/'    | \
                     grep -v '^/dev/'
}
function alert {
    echo "DISPLAY=$DISPLAY xmessage -center -default okay $1" | at $2
}
function fm22avi {
    fceux --playmov $1.fm2 --sound 1 --soundq 1 --soundrate 48000 --nospritelim 1 --pal 0 --xscale 1 --yscale 1 --opengl 0 --special 0 $2 --videolog "mencoder - -o $1.avi -ovc x264 -x264encopts qp=0 -oac mp3lame -lameopts mode=3:preset=128 -noskip -nocache -mc 0 -aspect 4/3 NESVSETTINGS"
}
function pdfcat {
    local out=$1
    shift
    gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$out $*
}
function svup {
    svc -u "$HOME/.services/$1"
    svget "$1"
}
function svstop {
    svc -d "$HOME/.services/$1"
    svget "$1"
}
function svkill {
    svc -k "$HOME/.services/$1"
    svget "$1"
}
function svdn {
    svst "$1" && svstop "$1"
    svst "$1" && sleep 1
    svst "$1" && svstop "$1"
    for i in 1..5; do
        svst "$1" && sleep 1
    done
    svst "$1" && svstop "$1"
    for i in 1..10; do
        svst "$1" && sleep 1
    done
    svst "$1" && svkill "$1"
}
function svget {
    svstat "$HOME/.services/$1"
}
function svst {
    svget "$1" | grep -q ": up ("
}
function svre {
    svdn "$1"
    svup "$1"
}
function svlog {
    tail -F "$HOME/.log/$1/current" | tai64nlocal
}
function pick_music {
    lastfm_export --user doyster --dsn dbi:SQLite:${HOME}/.tracks.sqlite
    sqlite3 ${HOME}/.tracks.sqlite "SELECT artist FROM yearly_tracks WHERE artist NOT IN (SELECT DISTINCT(artist) FROM weekly_tracks) GROUP BY artist ORDER BY count(artist) * (strftime('%s') - max(timestamp)) DESC LIMIT $([ -z "$1" ] && echo 20 || echo $1)"
}
function rand_music {
    local db
    if [[ $1 == '--old' ]]; then
        db=old_tracks
        shift
    else
        db=yearly_tracks
    fi
    lastfm_export --user doyster --dsn dbi:SQLite:${HOME}/.tracks.sqlite
    for i in $(seq 1 $([ -z "$1" ] && echo 20 || echo $1)); do
        echo "select distinct(artist) from $db where artist not in (select distinct(artist) from weekly_tracks);" | sqlite3 ~/.tracks.sqlite | rand_line | sed "s/'/''/" | sed "s/.*/select artist, album from $db where artist = '&' group by artist, album;/" | sqlite3 ~/.tracks.sqlite | rand_line | sed 's/|/ - /'
    done
}
function t {
    if [[ -d blib ]]; then
        perl -Mblib -MTest::Pretty "$@"
    else
        perl -Ilib -MTest::Pretty "$@"
    fi
}
function pt {
    if [[ -d blib ]]; then
        prove -Mlib::require::all=blib/lib,blib/arch -Pretty -b "$@" t
    else
        prove -Mlib::require::all=lib -Pretty -l "$@" t
    fi
}
function hostcert {
    openssl s_client -connect "$1" < /dev/null 2>/dev/null | perl -nle 'print if /BEGIN CERTIFICATE/../END CERTIFICATE/' | openssl x509 -text | perl -nle 'print unless /BEGIN CERTIFICATE/../END CERTIFICATE/'
}

# vim:ft=sh: