this week’s tobacco
Lucky Strike White Portion. Nothing special. Nice metal can though.
file renamer
Let’s suppose you have a bunch of files with various characters in filename which you want to get rid of. I mean you want to eliminate those characters, not the files.
afroid-laptop% paste <(ls -1 | sed -e 's/^\(.*\)$/"\1"/') <(ls -1 | sed -e 's/\ / _/g') | sed -e 's/^/mv /' mv "01 Track 01 13.mp3" 01_Track_01_13.mp3 mv "02 Track 02 22.mp3" 02_Track_02_22.mp3 mv "03 Track 03 32.mp3" 03_Track_03_32.mp3 mv "04 Track 04 42.mp3" 04_Track_04_42.mp3 mv "05 Track 05 52.mp3" 05_Track_05_52.mp3 mv "06 Track 06 62.mp3" 06_Track_06_62.mp3 mv "07 Track 07 72.mp3" 07_Track_07_72.mp3 mv "08 Track 08 82.mp3" 08_Track_08_82.mp3 mv "09 Track 09 91.mp3" 09_Track_09_91.mp3 afroid-laptop% paste <(ls -1 | sed -e 's/^\(.*\)$/"\1"/') <(ls -1 | sed -e 's/\ / _/g') | sed -e 's/^/mv /' | sh afroid-laptop% ls 01_Track_01_13.mp3 04_Track_04_42.mp3 07_Track_07_72.mp3 02_Track_02_22.mp3 05_Track_05_52.mp3 08_Track_08_82.mp3 03_Track_03_32.mp3 06_Track_06_62.mp3 09_Track_09_91.mp3 afroid-laptop%
down the road
Taboca had a little bit dodgy can, good taste though.
Gotland Gul was very rustic and has potty taste.
Mocca Pomegranate White Mini Portion was very tasty but mini so no power at all. Was the best out of this three though.
useful key shortcuts on ubuntu
I’m evil sometimes ; )
As a first scenario, I wanted to save some pages of a book provided by a flash site. This site hides the pages once seen because of copyrigth issues. I had to create a bunch of screenshots : ) I also wanted to minimize clicks or key strokes to use during a screenshot.
On ubuntu, start up ‘gconf-editor’ from a terminal. Go to path ‘apps/metacity/keybinding_commands/command_1′. Place there ‘/somepath/sshot.sh’. Content of that is like this:
afroid-laptop% cat sshot.sh import -window root -quality 90 /pathtoscreenshotscollection/`date +%Y%m%d%H%M%S`.png afroid-laptop%
Later on, under ‘global_keybindings/command_1′, insert the string e.g. ‘<Alt>T’.
Obviously you can change names and bindings as it’s appropriate for you.
Next one is to get descriptions for words form a dictionary.
Command to place is: ‘firefox “http://pewebdic2.cw.idm.fr/popup/popupmode.html?search_str=”`xsel`’.
Of course you have to install the xsel package before usage. Later you only select the word with your mouse and press F8 for example and a page appears with the word from that dictionary…
two weeks tobacco (new series)
After a session with already known brands, I ordered again a new pack with big variety of brands (12 of them). The first two portion was parallelly consumed.
Kinda first was Montecristo which is very similar to Romeo y Julieta. These two don’t contain too much water, but they aren’t in the white snus category. Balanced taste, equally distributed dose of nicotine. Bit too expensive, worths a try though.
Kinda second was the Strong Wise. It’s white for sure and advertised with the fact that it is purified from "nitrosamines that can cause cancer". This purification ends up with white powder in portions. I don’t know what to say to the staff on an airport if they ask me about that during check in. This portion somehow gives you a big shot at the beginning as far as I felt. I give it only two stars out of five.
explanation of previous (part II)
We ended up with two numbers, 0 and 181. I won’t use the commands producing them, instead simulate them with
afroid-laptop% ( echo 0; echo 181 ) 0 181 afroid-laptop%
First of all they’ll go through a loop by which the programmer (me) can transform them into things with a greater benefit. Here we go with a zsh (linux shell’s name I work with) loop which just simply repeat the incoming lines.
afroid-laptop% ( echo 0; echo 181 ) | while read i; do echo $i; done 0 181 afroid-laptop%
In a .cue file these numbers are needed in a minute:second:10th-second format (see my previous article about .cue format).
afroid-laptop% ( echo 0; echo 181 ) | while read i; do echo \ \ INDEX 01 `echo $ i "60 ~ sn p" | dc`:`echo $i "60 ~ p" | dc`:0 ; done INDEX 01 0:0:0 INDEX 01 3:1:0 afroid-laptop%
This have to be surrounded with additional and mandatory informational fields about author and title and the like. Also, I introduce increasing numbers for tracks. Pharenteses are for running stuff in a subshell ((the doubled one is the arithmetic syntactic sugar of zsh)).
afroid-laptop% ( echo 0; echo 181 ) | ( x=1; while read i; do echo \ TRACK $x AUDIO; echo \ \ TITLE \"x$x\"; echo \ \ PERFORMER \"x\"; echo \ \ INDEX 01 `echo $i "60 ~ sn p" | dc`:`echo $i "60 ~ p" | dc`:0 ; (( x = x + 1 )) ; done ) TRACK 1 AUDIO TITLE "x1" PERFORMER "x" INDEX 01 0:0:0 TRACK 2 AUDIO TITLE "x2" PERFORMER "x" INDEX 01 3:1:0 afroid-laptop%
.cue files have headers, so a header should be inserted
afroid-laptop% ( echo 0; echo 181 ) | ( echo TITLE \"x\"; echo PERFORMER\"x\"; echo FILE \"file.mp3\" MP3; x=1; while read i; do echo \ TRACK $x AUDIO; echo \ \ TITLE \"x$x\"; echo \ \ PERFORMER \"x\"; echo \ \ INDEX 01 `echo $i "60 ~ sn p" | dc`:`echo $i "60 ~ p" | dc`:0 ; (( x = x + 1 )) ; done ) TITLE "x" PERFORMER "x" FILE "file.mp3" MP3 TRACK 1 AUDIO TITLE "x1" PERFORMER "x" INDEX 01 0:0:0 TRACK 2 AUDIO TITLE "x2" PERFORMER "x" INDEX 01 3:1:0 afroid-laptop%
The next step is an ugly solution of padding the appearing numbers to length 2 with zeros using some sed magic.
afroid-laptop% ( echo 0; echo 181 ) | ( echo TITLE \"x\"; echo PERFORMER\"x\"; e cho FILE \"file.mp3\" MP3; x=1; while read i; do echo \ TRACK $x AUDIO; echo \ \ TITLE \"x$x\"; echo \ \ PERFORMER \"x\"; echo \ \ INDEX 01 `echo $i "60 ~ sn p" | dc`:`echo $i "60 ~ p" | dc`:0 ; (( x = x + 1 )) ; done ) | sed -e 's/"x\([0-9 ]\)”/”x0\1″/’ | sed -e ’s/\ \([0-9]\):/ 0\1:/’ | sed -e ’s/:\([0-9]\):/:0\1:/’ | sed -e ’s/:\([0-9]\)$/:0\1/’ | sed -e ’s/TRACK\ \([0-9]\) /TRACK 0\1 /’ TITLE “x” PERFORMER”x” FILE “file.mp3″ MP3 TRACK 01 AUDIO TITLE “x01″ PERFORMER “x” INDEX 01 00:00:00 TRACK 02 AUDIO TITLE “x02″ PERFORMER “x” INDEX 01 03:01:00 afroid-laptop%
As you can see in the original post, I redirect this to a file, because I wasn’t able to find a way by which mp3splt eats the .cue file from standard input. The && is a statement sequence operator in zsh (and in many other shells (e.g. in cmd.exe as well)) where the second command is executed only if the first was successful.
mp3splt -c /tmp/splitter.cue file.mp3 -o @t
Dash o describes the format of output files and t is for title. So the generated files will have names like x01, x02 and so on.
explanation of previous
Let’s start with sox. It can tell you various things about a file like this:
afroid-laptop% sox file.mp3 -e stat Samples read: 19139400 Length (seconds): 217.000000 Scaled by: 2147483647.0 Maximum amplitude: 0.999969 Minimum amplitude: -1.000000 Midline amplitude: -0.000015 Mean norm: 0.157586 Mean amplitude: -0.000860 RMS amplitude: 0.223554 Maximum delta: 1.243805 Minimum delta: 0.000000 Mean delta: 0.086869 RMS delta: 0.123678 Rough frequency: 3883 Volume adjustment: 1.000 afroid-laptop%
It takes a while to compute all these things, but I wasn’t able to ask for only the Length field. This output goes to the standard error, 2>&1 should be used. After I select the line starting with Length and cut the number itself using the format of that line.
afroid-laptop% sox dose-1.mp3 -e stat 2>&1 | grep ^Length | cut -d':' -f2
217.000000
afroid-laptop%
Now here comes some dc scripting which isn’t that straightforward. Here we go:
afroid-laptop% sox dose-1.ogg -e stat 2>&1 | grep ^Length | cut -d':' -f2 | sed
-e 's/$/ d [1+]si 300 ~ 0 <i sp sf lf lp ~ 0 <i sl 0 [d ll + d lf >s]ss 0 0 =s f/’
217.000000 d [1+]si 300 ~ 0 <i sp sf lf lp ~ 0 <i sl 0 [d ll + d lf >s]ss 0 0 =s f
afroid-laptop%
As a first step, the number 217 here is pushed to the stack and duplicated with command d. Let me use 1635 here to make more sense. The command f is for displaying the stack itself you work with. I use tabs to separate commands and stack content in following snippets. Just start dc and type the things below to experiment. So we start with something like this:
1635
f
1635
d
f
1635
1635
With [ and ], you can place strings to the stack, moreover, by saving those strings to registers, you can use them to execute as dc scripts. Here I save my increment script into register i.
[1+]
f
1+
1635
1635
si
f
1635
1635
Later on, there’s a division with remainder and if the remainder is not zero, then one is added to the result of division. The intent here is to split that mp3 to at most 5 minutes long slices. Feel free to try the followings with numbers dividable with 300 and note that 1 is not added.
300
f
300
1635
1635
~
f
135
5
1635
0
f
0
135
5
1635
<i
f
6
1635
At the next step I store the result into register p for “how many Parts required”, and the number below that in the stack into register f for “Full length”. After I load them back to the stack to determine the length of one slice.
sp sf lf lp
f
6
1635
Now compute the length of a slice with the same division technique as before and store it to register l for “Length” and load a 0 to the stack to start the loop (discussed later).
~ 0 <i f
273
sl f
0
f
0
In the loop, the following steps are performed: double the value on the top and load the Length, add them. At this point you have the next slice’s start time. Later I check whether I’m ready (if the starting time is greater than the Full length) and repeat loop if necessary. Note that I save this script to the same register as I use in the loop itself.
[d ll + d lf >s] ss 0 0 =s f
1638
1365
1092
819
546
273
0
So you have the timings in reverse order, therefore the command tac later on within the pipe. I delete the first line, because it’s greater than the Full length, use tac and a list of start timings is ready. For example, for a longer file it looks like this:
afroid-laptop% sox file2.mp3 -e stat 2>&1 | grep ^Length | cut -d':' -f2 | sed -e 's/$/ d [1+]si 300 ~ 0 <i sp sf lf lp ~ 0 <i sl 0 [d ll + d lf >s]ss 0 0 =s f/’ | dc | sed -e ‘1d’ | tac 0 181 afroid-laptop% sox file2.mp3 -e stat 2>&1 | grep ^Length Length (seconds): 361.116735 afroid-laptop%
Secont part will be the subject of an upcoming post ; )
split mp3 files again
afroid-laptop% cat filesplitter.sh #!/usr/bin/zsh FILE=$1; sox "$FILE" -e stat 2>&1 | grep ^Length | cut -d':' -f2 | sed -e 's/$/ d [1+]si 300 ~ 0 <i sp sf lf lp ~ 0 <i sl 0 [d ll + d lf >s]ss 0 0 =s f/’ | dc | sed -e ‘1d’ | tac | ( echo TITLE \”x\”; echo PERFORMER\”x\”; echo FILE \”$FILE\ ” MP3; x=1; while read i; do echo \ TRACK $x AUDIO; echo \ \ TITLE \”x$x\”; echo \ \ PERFORMER \”x\”; echo \ \ INDEX 01 `echo $i “60 ~ sn p” | dc`:`echo $i “60 ~ p” | dc`:0; (( x = x + 1)) ; done ) | sed -e ’s/”x\([0-9]\)”/”x0\1″/’ | sed -e ’s/\ \([0-9]\):/ 0\1:/’ | sed -e ’s/:\([0-9]\):/:0\1:/’ | sed -e ’s/:\([0-9]\)$ /:0\1/’ | sed -e ’s/TRACK\ \([0-9]\) /TRACK 0\1 /’ > /tmp/splitter.cue && mp3spl t -c /tmp/splitter.cue $FILE -o @t afroid-laptop%
one of my favourite quotes
Ted: “I have to go the bathroom.”
Harry: “Just go down your leg Ted.”
Ted: “Really, you can urinate in these?”
Harry: “You can, the question is, would you want to.”
Sphere (1998)
floating point ST15
Let fl(x) denote the floating point number which is determined by a machine from x. Other than that, e0 is the smallest floating point number with radix a, t long significand, and k- as the smallest exponent: e0=ak--1. Let (1+e1) be the floating point number (which numbers are rational numbers) after 1, e1 equals to a1-t. The mathematical meaning of a floating point number, or the number it represents is like:
t
----- m
k \ i
a ) --
/ i
----- a
i = 1
Theorem.
|fl(x)-x| is less then or equal to e1|x| if |x|>e0
Proof.
It is enough to see the proof for a x>0, the x<0 case is similar.
Note that x can be written in a form
/ \ | t infinity | | ----- m --------- m | k | \ i \ i | a | ) -- + ) -- | | / i / i | | ----- a --------- a | | i = 1 i = t + 1 | \ /
After truncation the second sum’ll disappear so that is the distance of fl(x) and x. Now let’s see e1x:
infinity
-------- m
k \ i - t + 1
a ) ----------
/ i
-------- a
i = t
Because of normalization, m1>0.
QuED..