Thursday, February 25, 2010

Gcraziest

This has to do with an earlier script I wrote for cheating at Scrabble etc. You feed it a bunch of letters and it finds all the words that can be made from those letters.

Immediately after I'd made that script I figured it would be fun to make that thing into a simple GTK (GNOME) app, since I hear people making those kinds of things all the time, in context of scratching their own itches. Also I heard about this thing called Quickly, which would let me do just that. In theory.

I hacked the GUI together in a day or so, and then put in the extra function of finding the generated words in a dictionary, because someone suggested it, and it seemed useful. I also figured out how to use GConf instead of making a file-based configuration. Then I took the time to find out how language versions may be added, and I made a Polish and English version of the GUI. I even made an icon, and a logo, thanks to my mad Inkscape skills!

And then I completely failed at putting it up to Launchpad, because I couldn't find any documentation, and I had some troubles with all the GPG keys, website logins, signed Codes of Conduct, forgotten pass-phrases, and things of similar nature. I got frustrated and it took me almost 2 months of stalling before, as a reaction to Jono Bacon's challenge thingie, I finally sat down and figured out all the Launchpad things.

And lo and behold! Here it is: https://launchpad.net/~konrad-siek/+archive/ppa. Also, you can install it by adding ppa:konrad-siek/ppa to your repositories in Synaptic or whatever (more on that later).

I'm not posting the code here, because it's on the long side, but it is available at GitHub as gcraziest/ and, as previously stated, at https://launchpad.net/~konrad-siek/+archive/ppa.

Also, here's a screenshot:

Gcraziest screenshot

Important: The wretched package doesn't want to accept dictclient as a dependency. And I'm too fed up to do anything about it.

How to install (on Ubuntu): You can...
  1. Open the Ubuntu Software Center, select Edit -> Software Sources...
  2. In the Software Sources dialog select the tab Other Software
  3. There, select add and type in the apt line for the package archive (viz. ppa:konrad-siek/ppa);
  4. Find the program in Get software, in a section like ppa that just appeared.
  5. Also, you have to take care of the pesky dependency, so you can use the search field to find and install the package python-dictclient.
Another alternative is to do it the gritty way and create a list for apt. That you can do by creating a file in /etc/apt/sources.list.d/ and inside it type in deb http://ppa.launchpad.net/konrad-siek/ppa/ubuntu lucid main. You substitute lucid for whatever version of Ubuntu you happen to be running. Then you can install the program via whatever package management tool you want (but remember about that one pesky dependency!), e.g. apt:
sudo apt-get update && sudo apt-get install python-dictclient gcraziest
Done.

Tuesday, February 23, 2010

Rotate video

No weird title for this one. No, this one was 100% purely itch-scratch oriented, and written in under under two hours.

Problem: I've been bowling and I made some short movies with my cell phone, but I recorded them horizontally instead of vertically. I basicaly forgot that, unlike with pictures, when you watch the movie you can't just press the rotation arrow in the movie player to turn it vertical or whatever.

Thus, a little zenity-enabled script around mencoder to convert these ineptly taken movies.

The code:
 
1 #!/bin/bash
2 #
3 # Rotate video
4 #
5 # A short and handy way to rotate videos, one file at a time (sorry).
6 #
7 # Usage:
8 # rotate_video [INPUT [OUTPUT [ROTATION]]]
9 #
10 # (If no arguments are given, the script will show appropriate dialogs)
11 #
12 # Requires:
13 # mencoder
14 # zenity
15 #
16 # Author:
17 # Konrad Siek <konrad.siek@gmail.com>
18 #
19 # License information:
20 #
21 # This program is free software: you can redistribute it and/or modify
22 # it under the terms of the GNU General Public License as published by
23 # the Free Software Foundation, either version 3 of the License, or
24 # (at your option) any later version.
25 #
26 # This program is distributed in the hope that it will be useful,
27 # but WITHOUT ANY WARRANTY; without even the implied warranty of
28 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 # GNU General Public License for more details.
30 #
31 # You should have received a copy of the GNU General Public License
32 # along with this program. If not, see <http://www.gnu.org/licenses/>.
33 #
34 # Copyright 2010 Konrad Siek
35
36 # Auxiliary shorthand for rotating:
37 # rotate INPUT OUTPUT ROTATION
38 function rotate() {
39 mencoder -vf rotate="$3" -o "$2" -oac copy -ovc lavc "$1"
40 }
41
42 CCW_90="90°"
43 CW_90="90°"
44 ROT_180="180°"
45
46 case "$#" in
47 0) # Interactive mode
48 file=$(zenity \
49 --file-selection \
50 --title="Select a video to rotate" \
51 --separator="\n" \
52 )
53 if [ -f "$file" ]
54 then
55 output=$(basename "$file")
56 extension="${output#*.}"
57 output="$(dirname "$file")/${output%%.*}"
58 rotation=$(zenity --list \
59 --title="Specify rotation angle" \
60 --column="Rotation angle" \
61 "$CW_90" "$CCW_90" \
62 )
63 case "$rotation" in
64 "$CW_90")
65 rotate "$file" "$output$CW_90.$extension" 1
66 exit 0
67 ;;
68 "$CCW_90")
69 rotate "$file" "$output$CCW_90.$extension" 2
70 exit 0
71 ;;
72 *)
73 zenity --error --text="No rotation specified."
74 exit 3
75 ;;
76 esac
77 else
78 zenity --error --text "Cannot open file '$file'."
79 exit 2
80 fi
81 ;;
82 1) # Just filename
83 output=$(basename "$1")
84 extension="${output#*.}"
85 output="$(dirname "$1")/${output%%.*}"
86 rotate "$1" "$output$CW_90.$extension" 1
87 ;;
88 2) # Two filenames
89 rotate "$1" "$2" 1
90 ;;
91 3) # Two filenames and rotation spec
92 case "$3" in
93 cw) rotate "$1" "$2" 1;;
94 ccw) rotate "$1" "$2" 2;;
95 *)
96 echo "Unknown option '$3'." >&2
97 echo "Try 'cw', 'ccw' or nothing instead." >&2
98 ;;
99 esac
100 ;;
101 *) # Anything else - show usage
102 echo "Usage:" >&2
103 echo -e "\t$0 [INPUT [OUTPUT [cw|ccw]]]" >&2
104 exit 1
105 ;;
106 esac


The code is also available at GitHub as bash/rotate_video.

Wednesday, February 17, 2010

Shasteriskt

I don't know what to say... I might have inadvertently written a mildly annoying spam bot for Twitter and/or Identica and other stuff of that nature.

Example:
./shasteriskt 'myusername:mysecretpassword' 2 'Bored!' 'Annoyed!'

will post two messages to each of the services (defined in the script, Twitter and Identica by default.

The only use for this I can think of is bumping up your Cursebird stats.

Also, your login and password are not necessarily safe when using this script.

Code:
 
1 #!/bin/bash
2 #
3 # Shasteriskt
4 #
5 # A quick and dirty way to generate a ton of spam to
6 # microblogging serivces. This is a script of low-grade
7 # evil.
8 #
9 # Parameters:
10 # USERNAME:PASSWORD - credentials to services
11 # NUMBER - number of repeats
12 # WORDS - a list of words to post
13
14 # Depends:
15 # curl
16 #
17 # Author:
18 # Konrad Siek <konrad.siek@gmail.com>
19 #
20 # License information:
21 #
22 # This program is free software: you can redistribute it and/or modify
23 # it under the terms of the GNU General Public License as published by
24 # the Free Software Foundation, either version 3 of the License, or
25 # (at your option) any later version.
26 #
27 # This program is distributed in the hope that it will be useful,
28 # but WITHOUT ANY WARRANTY; without even the implied warranty of
29 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 # GNU General Public License for more details.
31 #
32 # You should have received a copy of the GNU General Public License
33 # along with this program. If not, see <http://www.gnu.org/licenses/>.
34 #
35 # Copyright 2010 Konrad Siek
36
37 URLs=( \
38 'http://twitter.com/statuses/update.json' \
39 'http://identi.ca/api/statuses/update.json' \
40 )
41
42 if [ "$#" -lt 4 ]
43 then
44 echo "Usage: $0 USER:PASSWORD NUMBER WORD [ WORD [...] ]"
45 exit 1
46 fi
47
48 credentials=$1; shift
49 total=$1; shift
50
51 words=( )
52 counter=0
53 while [ -n "$1" ]
54 do
55 words[$counter]="$1"
56 counter=$(($counter+1))
57 shifto
58 done
59
60 for i in $(seq 1 $total)
61 do
62 for w in "${words[@]}"
63 do
64 for url in "${URLs[@]}"
65 do
66 curl --basic \
67 --user "$credentials" \
68 --data status="$w" "$url"
69 done
70 done
71 done


The code is also available at GitHub as bash/shasteriskt.