Compiling http://www.darwinsys.com/file/ for Android

Cross compiling is always a PITA, so here goes:

1
2
3
4
5
6
7
8
9
10
11
12
13
AR=arm-linux-androideabi-ar
OLDPWD=/home/transfusion/android-bash/fileutil
LD_LIBRARY_PATH=/home/transfusion/android-ndk-r9c/platforms/android-18/arch-arm/usr/lib/
PATH=/home/transfusion/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
LD=arm-linux-androideabi-ld
PWD=/home/transfusion/android-bash/fileutil/bin
STRIP=arm-linux-androideabi-strip --strip-unneeded
CXX=arm-linux-androideabi-g++
CFLAGS=-L/home/transfusion/android-ndk-r9c/platforms/android-18/arch-arm/usr/lib/ --sysroot=/home/transfusion/android-ndk-r9c/platforms/android-18/arch-arm/ -I/home/transfusion/android-ndk-r9c/platforms/android-18/arch-arm/usr/include/
RANLIB=arm-linux-androideabi-ranlib
ANDROID_NDK=/home/transfusion/android-ndk-r9c
CC=arm-linux-androideabi-gcc
READELF=arm-linux-androideabi-readelf

I have android-ndk-r9c extracted to my home directory.

1
2
3
4
5
6
cd file-5.11
cd src
ln -s $ANDROID_NDK/platforms/android-19/arch-arm/usr/lib/crtend_so.o
ln -s $ANDROID_NDK/platforms/android-19/arch-arm/usr/lib/crtbegin_so.o
./configure --prefix=/home/transfusion/file-android-build --host=arm-linux ---datarootdir=/system/share
make && make install

See https://stackoverflow.com/questions/6881164/crtbegin-so-o-missing-for-android-toolchain-custom-build as to why those two files need to be linked. The magic.mgc file is going to be placed in /system/share/misc/magic on the device. Copy all the files into /system on the device, and create the symlink to libmagic.so in /system/lib if it hasn’t been created

1
2
cd /system/lib
ln -s libmagic.so.1.0.0 libmagic.so.1

If all works well,

1
2
$ file /system/bin/file
/system/bin/file: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped

Wikipedia jumps on the Helvetica bandwagon

Helvetica Scenario.

Alternative to checkinstall

https://unix.stackexchange.com/questions/16375/keeping-track-of-programs

1
2
3
4
5
./configure --prefix /usr/local/stow/PROGRAM_NAME
make
make install
cd /usr/local/stow
stow PROGRAM_NAME

When you want to remove the symlinks created in /usr/local/ for your particular program:

1
stow -D PROGRAM_NAME

Extremely useful in Cygwin where checkinstall and package managers aren’t available.

Gentoo on OpenVZ VPS, my experience

The target VPS is running Debian 6 i686 from an OpenVZ template. First, I used this straightforward script; you can find the stage3 tarball in /releases/x86/current-stage3/ : http://linux.arantius.com/how-to-install-gentoo-onto-any-openvz-vps Next I set portage up: https://matt.bionicmessage.net/blog/2011/02/05/Recipe%3A%20’Gentooize’%20an%20existing%20virtual%20server%20(VPS))

1
2
3
localhost usr # wget http://distfiles.gentoo.org/snapshots/portage-latest.tar.bz2
localhost usr # eselect profile set 1
localhost usr # emerge --sync

Here is how I managed to get networking working with /etc/conf.d/net ; apparently venet0:0 isn’t necessary anymore (we can simply add our IPv4 address to venet0 but very strangely, our external IPv4 address doesn’t show up in ifconfig but works.) Without further do…

1
2
3
4
5
6
7
8
9
10
# cat /etc/conf.d/net
config_venet0="127.0.0.2/32 198.***.***.***/32 2a01:****:***:**::****:****/128 2a01:****:***:**::****:****/128 2a01:****:***:**::****:****/128 2a01:****:***:**::****:****/128"
routes_venet0=("default")
route -A inet6 add ::/0 dev venet0
postup() {
route -A inet6 add ::/0 dev venet0
}
predown() {
route -A inet6 del ::/0 dev venet0
}

routes_venet0=("default") only sets the IPv4 default route, and I haven’t found a way to set the IPv6 default route without knowledge of the gateway IP address, hence the postup() and predown() scripts. Nevertheless, they are “good enough.”

1
# rc-update add net.venet0 default

to bring venet0 up at default runlevel. At this point you should be able to run

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
localhost usr # /etc/init.d/net.venet0 restart
SIOCADDRT: File exists
* Bringing down interface venet0
* Running predown ...
SIOCADDRT: No such device
* Bringing up interface venet0
* 127.0.0.2/32 ... [ ok ]
* 198.***.***.***/32 ... [ ok ]
* 2a01:****:****:**::****:****/128 ... [ ok ]
* 2a01:****:****:**::****:****/128 ... [ ok ]
* 2a01:****:****:**::****:****/128 ... [ ok ]
* 2a01:****:****:**::****:****/128 ... [ ok ]
* You are using a bash array for routes_venet0.
* This feature will be removed in the future.
* Please see net.example for the correct format for routes_venet0.
* Adding routes
* default ... [ ok ]
* Running postup ...

while logged in without your SSH connection dropping on either IPv4 or IPv6. I am still in the process of setting up ntp, a mailer daemon, syslog-ng, etc. so I may post an update if I find anything extraordinary.

One of Gmail's spam defenses that I bumped into

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
# sendmail -v *@gmail.com
Subject: Hello World!
This is an email to myself.
.
*@gmail.com... Connecting to [127.0.0.1] via relay...
220 transfusion.vm ESMTP Sendmail 8.14.4/8.14.4/Debian-2.1ubuntu4; Mon, 10 Mar 2014 05:57:40 -0400; (No UCE/UBE ) logging access from: localhost(OK)-localhost [127.0.0.1]
>>> EHLO transfusion.vm
250-transfusion.vm Hello localhost [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-EXPN
250-VERB
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5
250-DELIVERBY
250 HELP
>>> VERB
250 2.0.0 Verbose mode
>>> MAIL From: SIZE=50 AUTH=root@transfusion.vm
250 2.1.0 ... Sender ok
>>> RCPT To:<*@gmail.com>
>>> DATA
250 2.1.5 <*@gmail.com>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
050 <*@gmail.com>... Connecting to gmail-smtp-in.l.google.com. via esmtp...
050 220 mx.google.com ESMTP t3si9104892qar.125 - gsmtp
050 >>> EHLO transfusion.vm
050 250-mx.google.com at your service, [2a01:**:****:***::*]
050 250-SIZE 35882577
050 250-8BITMIME
050 250-STARTTLS
050 250-ENHANCEDSTATUSCODES
050 250 CHUNKING
050 >>> STARTTLS
050 220 2.0.0 Ready to start TLS
050 >>> EHLO transfusion.vm
050 250-mx.google.com at your service, [2a01:**:****:***::*]
050 250-SIZE 35882577
050 250-8BITMIME
050 250-ENHANCEDSTATUSCODES
050 250 CHUNKING
050 >>> MAIL From: SIZE=331
050 250 2.1.0 OK t3si9104892qar.125 - gsmtp
050 >>> RCPT To:<*@gmail.com>
050 250 2.1.5 OK t3si9104892qar.125 - gsmtp
050 >>> DATA
050 354 Go ahead t3si9104892qar.125 - gsmtp
050 >>> .
050 550-5.7.1 [2a01:**:****:***::*] Our system has detected that this message does
050 550-5.7.1 not meet IPv6 sending guidelines regarding PTR records and
050 550-5.7.1 authentication. Please review
050 550-5.7.1 https://support.google.com/mail/?p=ipv6\_authentication\_error for more
050 550 5.7.1 information. t3si9104892qar.125 - gsmtp
050 ... Connecting to local...
050 ... Sent
250 2.0.0 s2A9ve5k026538 Message accepted for delivery
*@gmail.com... Sent (s2A9ve5k026538 Message accepted for delivery)
Closing connection to [127.0.0.1]
>>> QUIT
221 2.0.0 transfusion.vm closing connection
You have new mail in /var/mail/root

My first foray into Brainfuck

Print damned.

1
print "damned"

Obfuscate it.

1
print 'qnzarq'.decode('rot13')

Now print “damned” in Brainfuck, and let’s play codegolf.

1
++++++++++[>++++++++++>+++++++++++<<-]>.---.>-.+.<++++.-.

Challenge accepted.

1
-[>++>++>++<<<-----]>--.---.>+++++++.+.>-.-.

http://www.iamcal.com/misc/bf_debug/ Debugger to help you visualize what’s going on. The first brainfuck works by incrementing the first cell to 10, then the loop increments the second cell to 100 and the 3rd cell to 110, and the <<- decrements the loop “counter”, which is held by the first cell.

At the end of the loop we should have [0][100][110]. Everything after the loop just increments or decrements to the appropriate ascii decimal value and outputs to stdout.

http://www.asciitable.com/ The second one works by first decrementing the value of the first cell, which is 0; hopefully the bf interpreter will wrap around to 255. Not all bf interpreters do this; https://apps.ubuntu.com/cat/applications/saucy/bf/ does but http://swapped.cc/#!/bff doesn’t.

Since the ascii decimal codes of the letters d, m, n, e, d are all in between 100 and 110 (a is 97), the shortest way I could think of was to have a big number to use as the loop counter and decrement it in intervals. 102 is 40% of 255, or 2/5ths, so after incrementing twice for cells 1, 2, and 3 go back to cell 0 and decrement by 5. At the end of the loop we should have [0][102][102][102].

Some interesting bf-related links:

https://stackoverflow.com/questions/16836860/how-does-the-brainfuck-hello-world-actually-work
http://esoteric.sange.fi/brainfuck/impl/interp/i.html
http://esolangs.org/wiki/Brainfuck_algorithms add, dup, swap, mul, if implemented in bf.

http://www.reddit.com/r/tinycode/comments/1oqgwm/shortest_hello_world_brainfuck_code/

Bitcoin dev is someone's paranoid father.

Imagine having Satoshi Nakamoto for a father. http://arstechnica.com/business/2014/03/bitcoin-creator-satoshi-nakamoto-revealed-after-years-of-mystery/ He is your usual cranky old man in his 60s. His supposed daughter had this to say about him:

‘He is very wary of government interference in general,’ she says. ‘When I was little, there was a game we used to play. He would say, ‘Pretend the government agencies are coming after you.’ And I would hide in the closet.’

He was a software engineer for the FAA, has worked on military systems, and has done work for Hughes Aircraft at RCA.

Shooting the messenger: Level Counterforce

http://arstechnica.com/business/2014/01/protestors-show-up-at-the-doorstep-of-google-self-driving-car-engineer/
http://www.motherjones.com/mojo/2014/01/bay-area-google-protests-uncomfortably-personal

The activists claim high-paid tech employees are squeezing out the middle and working classes from the city.

Perhaps it has never occurred to them that they are living in a meritocracy. Perhaps it has never occurred to them that Google has competitors, too…

A mere 10% of scientific research is reproducible, in some cases.

http://today.duke.edu/2014/02/reproducibility The proposed solution is integrating the raw data, the computing, and analysis into one package as opposed to using different software tools for different stages of research which may make it cumbersome for students to back-step.

Enter R Markdown, a statistical package that integrates seamlessly with the programming language R. The team chose R Markdown for its ease of use – students wouldn’t have to learn a new computer syntax – and because it combines the raw data, computing and written analysis into one HTML document. The researchers hoped a single HTML file would give students a start-to-finish understanding of assignments, as well as make studying and grading easier.

What the hivemind had to say on this: https://pay.reddit.com/r/science/comments/1z8w5k/scientists_propose_teaching_reproducibility_to/

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×