There is no cheaper storage than USB sticks. When writing this, they’re 30 bucks for 64GB. Unlike hard drives, they don’t eat a lot of juice when you keep them plugged in, they’re quiet, they are not sensitive to having a dusty home (thank god!), and they last. It’s also very easy to wipe out the dumb cruftware that comes pre-installed on them.
If you’re a command line guy like me, it’s obvious that you must have a Raspberry Pi server at home. It’s also obvious that you need to cram it full as many USB sticks as you can, in order to thumb your paranoid nose at Dropbox. Before pointing said nose at a full screen terminal and punching in powerful, arcane commands that connect you to the fathers of Unix. And feel like them. Even though you have a mouse, copy-and-paste, and command completion.
What gets really, really annoying is having your assorted drives from different eras and sizes on different mount points. Enter LVM.
When you get your next bigger thumb drive and cram it into your pi, don’t do mkfs /dev/sdx1 right away. (/dev/sdx1 is the placeholder device name used in this post for your new usb drive, which assumes you have already connected 23 thumb drives to your pi, which is the only reasonable thing to do. If you’re new to this, your actual device name could also be /dev/sda1 or /dev/sdb1).
So instead of doing
1
mkfs -t ext4 /dev/sdx1
right away, you do:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# Prepare a device to become part of a volume group,
# which is LVM's equivalent of a fraternity hazing
# a prospective new member
pvcreate /dev/sdx1
# Create the new volume group and add /dev/sdx1.
# Since the member no langer has a notion of individuality
# he may be admitted to the group.
vgcreate vg0 /dev/sdx1
# Create a new logical volume. Delightfully, the member
# now expresses himself exlusively through this new group identity.
lvcreate -n store --size 64G vg0
mkfs.ext4 /dev/vg0/store
mount -t ext4 /dev/vg0/store /mnt/store
So far this is just typing extra commands, but now you can transfer the data of one of your existing 23 usb sticks into /mnt/store.
1 2 3
mount /dev/sdw1 /mnt/old
mv /mnt/old/* /mnt/store
umount /mnt/old
Et voila! Instead of two annoyingly invidual mount points with 30G and 60G capacity, you have one with 90G capacity!
This means, whenever you run out of space, instead of extending your dropbox plan, you just add another thumb drive, haze him, and admit him to your group.
Of course you need some data security, so theoretically you should use half of your usb drive army to create a software raid1, and then pile your LVM on top of that.
That’s where git annex does a world of good.
Like with any decent dropbox replacement, you will probably have all those files on your laptop, your server, your home laptop, and the server in the basement you forgot about. That is more than two copies, and that is a good thing. You also get checksums.
So if you put your git annex on your LVM, you will have a pool of checksummed extendible storage that you can sync to any command line you come across.
And if you care about someone enough to bother, and that person has a recent mac, you can set up the same thing with git annex assistant.
Starting up the jackd sound server first, then starting up supercollider, and then connecting everything later can be a major hassle.
jackd’s relatively new temporary server mode makes this much, much easier. You just put your jack command line in ~/.jackdrc and boot the server from your SuperCollider IDE (I use scvim). Jack comes up automatically.
To make things even more customizable, I put a little bash script in /usr/local/bin/jackd. It launches jackd with pasuspender and allows for a sound card called AUTODETECT; that just checks if my big sound card is available and falls back to my normal one.
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/bin/bash
if [ "" = "`grep IOx /proc/asound/cards`" ]; then
AUTODETECT=PCH
else
AUTODETECT=IOx
fi
ARGS=$@
ARGS=${ARGS/AUTODETECT/$AUTODETECT}
/usr/bin/pasuspender -- /usr/bin/jackd $ARGS
Things like these are the reason working with linux audio is worth it, in spite of having less ready made software available. If something’s a hassle, you write a script and never think about it again.
Gosh, I wish the real world had scripts.
Speaking of the real world, in the real world processors have more than one core, which is why it is really great SuperNova exists. SuperNova is a drop-in replacement for sclang that supports multicore processors. Thank you very much, Tim!
SuperNova currently requires you to start up jack manually, but with another startup wrapper script it behaves just like sclang:
Imagine the possibilities if the real world had scripts. Remember everyone’s name. Automatically listen emphatically and show agreement when people speak, while you’re off in tinkerspace changing the world. Oh, the joy!
Here’s a hard one… I’m getting a hunch Carlo Capocasa is not going to click it. To long. To unwieldy. Everyone thinks I’m in the Mafia.
c2c would have been great, just my initials and the coast to coast reference. But then there’s that band from France. Bummer.
So I settled for c4e, which is short for create (c, four letters, and then e). It’s what I stand for. Create, don’t worry about getting or moving around. Create. The world will be better.
I was trying to solve a hardware problem, and one of the many attempts was to upgrade my kernel from 3.2 (standard for Ubuntu 12.0) to 3.4. It didn’t solve my problem, because nobody had fixed the bug yet, even in 3.6. But I liked my self-compiled 3.4 realtime kernel so much I decided to keep it.
A little background, if you are going to do serious music making under linux, a realtime kernel is the way to go. It lets you do things live, that are otherwise only possible pre-recorded. Live linux music works especially well if you are using the amazing SuperCollider realtime music programming language. I have been using Alessio Bogani’s kernel PPA, which worked a charm. For my hardware tinkering I rolled my own as well, which was surprisingly easy thanks to the instructions by pablomme on AskUbuntu. But to make it even easier, if you like, I have made available AMD64 deb packages.
Edit:
Wally in the comments kindly pointed out Alessio’s PPA is no longer available for Precise. Just checked my apt/cache folder and it has the kernel, but no headers. Sorry!
See what’s happening here? For the computer, it’s like when a random friendly sales team member randomly shows up at random times of thethe day to you, the random programmer, to say things like “sup man, hey yo IT pro what’s cookin man, hey, you must be doing some serious thinking and shit, but man, hey, just gotta check you out and ask what’s cookin’, man, so, hey, man, what’s cookin’?” and then look at you with big, brown eyes waiting for an intelligent answer.
This not only wastes aerial brownian motion, but can also suck up to 60% of your brain power (long term effects not counted). No wonder the poor, idle machine can’t get things done any more, because the CPU is clooged with the interrupt controller gone haywire incessantly screamin “SUP, MAN! YEAH!” It’s like Guantanamo for geeks. It’s not torture, bit it is enhanced communication.
The most obvious solution is to fire the sales team.
1 2 3 4
# /etc/default/grub
# Find GRUB_CMDLINE_LINUX_DEFAULT and add acpi=off to the end, like so:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi=off"
followed by
1 2 3
sudo update-grub
sudo reboot
# Good riddance
This works like a charm. The sales team is gone, the chatter stops, and the CPU is free to work again (not to mention the tremendous emotional satisfaction).
However, it has a big minus. I have found that the sales team, properly kept outside of the IT office (kind of like farmers put wire fence around trees in goat pens), actually gets things of its own done. More specifically, I realized my Indigo IOx Expresscard
was no longer working, which was the reason I bought my beloved Lenovo in the first place. I hate to admit it, but firing the sales team is actually kind of a bad idea. Uh… sup guys, wanna come back, like, uh, would you?
Luckily, a very smart fellow on the linux kernel bug forum found a better solution: Instead of firing the entire sales team, we only fire the team member that does the most interrupting. Sales can still be made, we can work, all is well. First we need to find the culprit:
1 2 3
# Find the chatterbox
grep enabled /sys/firmware/acpi/interrupts/*
# He has the file with the highest number
1 2 3 4
sudo crontab -e
# now add this line, save, quit
@reboot echo "disable" > /sys/firmware/acpi/interrupts/gpeXX
# Note: for some reason, adding the line to /etc/rc.local doesn't work
1 2 3 4 5 6 7 8 9 10 11
#!/bin/bash
# Put this in a new file /etc/pm/sleep.d/30_disable_gpe (XX is the culprit found above)
case "$1" in
thaw|resume)
echo "disable" > /sys/firmware/acpi/interrupts/gpeXX 2>/dev/null
;;
*)
;;
esac
exit $?
This simply clobbers the interrupt that is problematic, while the express card still works great.
Oh, and I’m kidding about the sales team. I love you guys.
In a rush? Scroll all the way down to skip the tinker story, rant, and attempts at humor, and get just the instructions on how to get it working.
Oh. My. God.
Sweet Hail Mary Jeebus.
This thing will make me religious again. And I have now got one at home! Just came in today… It is my altar, my power beast, and my sacred connection to the akashic records.
It is a musical keyboard with touch sensors in the keys and an network interface. It is the Endeavour Evo Series One.
I knew it would take a new company to make something new. And realize MIDI is dead. These guys did both.
Since I don’t go near Macs these days (Steve at least made imprisonment fun) the first thing I needed to do was get it to work under linux, and the SuperCollierobject oriented programming software synthesizer (my second wholly holy grail of computerized musicality).
First I had to know what the evo was doing. So I fired up wireshark and took the Evo’s delicious touch sensitive keys for a spin (You don’t need to do this to get it working, but it can be helpful for troubleshooting).
1 2
sudo apt-get install wireshark
sudo wireshark
Ignore the security warning, we’re on a local network
Click the top left Icon and select eth0 wired network
Now plug the evo in and turn it on
And, lo and behold, there were the packets! Clear, crisp OSC packets, the way musical information needs to be transmitted these days.
Fire up the receptor, the mighty SuperCollider language!
1 2
# replace with your supercollider ide
scvim
(in IDE)
1 2 3 4
(
// This just dumps whatever SuperCollider is receiving
OSCFunc.trace(true);
)
Well, not much going on yet. Mash the evo’s keyboard all you like, but SuperCollider isn’t catching on.
And it wouldn’t; the evo sends packets from 169.254.31.0 port 0 by default, so we’re going to have to bend them around. Luckily, the evo can do DHCP, so the first part of our solution is getting a DHCP server going.
1
sudo apt-get install isc-dhcp-server
Then back up these config files and edit them to look like this:
Then give yourself the static IP address 192.168.175.11 in Network Manager. To do so
Click the Network Manager Icon, and select Edit connections
Click the Wired connection, and click Edit
Click the tab IPv4-Settings
Unter Addresses, enter 192.168.175.11 as address, 255.255.255.0 as netmask, and 192.168.175.11 as gateway.
Click routes, check the box Use this connection only for resources on its network, and confirm with OK (makes sure plugging in the evo won’t bring you offline. If you want to use wired internet again, uncheck the box)
Click Save and then Close
If you know what you’re doing you can replace the 192.168.xxx.xxx addresses above with whatever works best for you.
1 2
# Restart the DHCP server
sudo /etc/init.d/isc-dhcp-server restart
Now turn the evo off and back on again, and stop and restart wireshark’s listening on eth0. And, lo and behold, the evo is now sending from 192.168.175.100! Evo, you smart, smart machine.
But SuperCollider still isn’t catching on. It must be the pesky port 0 the evo sends on. To my knowledge, there is no way to convince it not to do that, probably short of re-flashing the firmware, and messing with the Evo’s firmware is not amongst my current desires. I spend too much time fussing with technology and not enough time being musically creative as it is, and I really don’t want to spend any time wondering whether I bricked the thing or not.
Speaking of bricking, I did brick my web server once, using a handy linux web server bricking tool called iptables. It allows you to close, reject, re-route and rewrite pretty much any kind of traffic, including your own connection to your sever. Which is a good thing, because the danger also means power. It also runs in the kernel, so I assume it will add little latency (The kernel is part of the upper crust of the hegemony inside your computer, and, like any good autocrat it has all the connections needed to preferentially aquire resources). Could it be that this is the solution to our little port 0 problem? Well, in short, yes. Observe and bow to the mighty kernel (and don’t worry, unlike most iptables commands, this one is actually not dangerous!)
1 2
# run as root, and also add to the beginning of /etc/rc.local
iptables -t nat -A PREROUTING -p udp --dport 0 -j REDIRECT --to-ports 57120
This takes all the udp traffic coming in on port 0, and rewrites it to port 57120, which is what SuperCollider likes to listen to by default. Yes, SuperCollider does have the this.openPort(1234); and this.openPorts; commands, but sclang does not seem intent to listen on port 0 under any circumstances. Correctly, I might add, in terms of networking standards. Good luck the kernel doesn’t give a fuck.
And yeah, I do like writing ‘lo and behold’. Lo and behold, I wrote lo and behold! Lo and behold, you can now turn the tracing off again.
1 2 3
(
OSCFunc.trace(false);
)
And this, nicely, also gives away how to work with the messages from SuperCollider. Here’s some code that actually creates some decent sound pressing and sliding keys.
Click the Network Manager Icon, and select Edit connections
Click the Wired connection, and click Edit
Click the tab IPv4-Settings
Unter Addresses, enter 192.168.175.11 as address, 255.255.255.0 as netmask, and 192.168.175.11 as gateway.
Click routes, check the box Use this connection only for resources on its network, and confirm with OK (make sure plugging in the evo won’t bring you offline. If you want to use wired internet again, uncheck the box)
Click Save and then Close
Set up DHCP server
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# run this
sudo apt-get install isc-dhcp-server
# Put this in/etc/default/isc-dhcp-server
INTERFACES="eth0"
I need backup. The time I almost lost 80 hours of work tought me that. And I can’t trust myself to handle the encryption. The guy who lost his life savings in bitcoins tought me that. And me, at four in the morning on a work day, trying to get GPG keys right for duplicity.
I also need about 200GB off site for stuff that I will never use again but want to keep. Enter Glacier.
Glacier will let me keep those 200GB online for 2 bucks a month. Ridiculously cheap, no? That’s what I thought. The catch is, if you ever need to restore it, Amazon essentially does a random hash on your bandwidth usage and presents it to you as your bill. Seriously, that price structure is really, really hideous.
Why would Amazon do such a thing? I wonder. They don’t normally suck. They recently coaxed an on-line vendor into sending me three boxes of dry ice because I wanted to see what would happen if I ordered Yoghurt. No one has ever so disproportionately outperformanced my expectations.
To mitigate my distrust of Glacier I kept on looking around and eventually came across a comment somewhere by somebody who said he’s an ex Amazon employee. Apparently it’s all custom hardware, with custom processors (seriously? wow) and custom hard drives with really slow spin cycles to reduce wear and power consumption.
This didn’t make me like the price structure more, but it did help me believe that Glacier is more than just an elaborate scam. They can actually afford to be cheap. It the high retrieval fees reflect a trade-off with their hardware that actually exists, they are not just a way of preying on retrievers to subsidize those who don’t retrieve. They are Amazon’s safeguard against using their special custom hardware in a way that will break it.
What also helped is the realization that to have a safety net against an avalanche on your Glacier bill, you do a simple thing: Throttle bandwidth.
So I came up with the following strategy to sieze the opportunity that is Glacier:
* For big, important stuff I might need in a month, use it as secondary off site backup.
* For huge stuff I might need in 10 years, use it as the only backup. Keep the external hard drives but don’t worry if they rot.
* Make a bet that before I might need to restore the full monty, someone, somewhere will create a Glacier client that will just let me set a budget and a timeframe. As a last resort, set up a RaspberryPi and a USB drive and keep it downloading for a couple of months. An Amazon Export-By-Mail might do the trick as well.
A little note on encryption:
The crypto community will never stop badmouthing Amazon S3 server side encryption, and I understand why. It’s mathematicians who don’t care how big a number is as long as it’s not infinite.
Not screwing up encryption just takes too much time when it comes to backups. And with Amazon’s encryption, they store the keys in a different place than the files. This means that a bored employee will not be tempted to thumb through my vacation pictures, which is good enough for me. The manager who has the keys will probably be too clueless to decrypt the data.
And you might be in the same situation as me: Big product with a huge amount of customer benefit built on Symfony 1.4 with years yet to maintain it and expand on it.
So you might want to start using traits, just like me. The first thing to do was, of course, to just do it:
1 2 3 4 5 6
<?php
// in lib/MyClass.php
class MyClass {
use MyTrait; // in lib/myTrait.php
}
To which the feedback was very clear:
Fatal error: Trait ‘ImageUpload’ not found in /path/to/project/lib/MyClass.php
Symfony was not autoloading traits.
Which is good. Symfony autoloads selectively, and you might not want to autoload every stray php file a stray programmer might have forgotten inside lib. (kidding)
I found by poking around in the Symfony 1.4 sources that the method actually selecting which files get autoloaded and cached is sfAutoloadConfigHandler::parseFile. It contains a regex that filters files to contain a line that starts with nothing or whitespace, followed by the words final or abstract, and then class or interface.
So a quick and dirty way to get traits autoloaded is to include a commented out mock class or interface definition in the trait file.
1 2 3 4 5 6 7 8
<?php
// in lib/MyTrait.php
/*
class MyTrait // Must be preceded on this line by nothing or whitespace
*/
trait MyTrait { // Gets autoloaded and cached by Symfony 1.4
}
Of course this is not pretty, but it will do if you need to autoload a couple of traits now and worry about clean code later.
class myAutoloadConfigHandler extends sfAutoloadConfigHandler {
// This method an exact duplicate of sfAutoloadConfigHandler::parseFile in Symfony 1.4.18,
// with only the regex modified from (class|interface) to (class|interface|trait)
static public function parseFile($path, $file, $prefix)
{
$mapping = array();
preg_match_all('~^\s*(?:abstract\s+|final\s+)?(?:class|interface|trait)\s+(\w+)~mi', file_get_contents($file), $classes);
foreach ($classes[1] as $class)
{
$localPrefix = '';
if ($prefix)
{
// FIXME: does not work for plugins installed with a symlink
preg_match('~^'.str_replace('\*', '(.+?)', preg_quote(str_replace('/', DIRECTORY_SEPARATOR, $path), '~')).'~', str_replace('/', DIRECTORY_SEPARATOR, $file), $match);
if (isset($match[$prefix]))
{
$localPrefix = $match[$prefix].'/';
}
}
Then start using it by creating or adding to your existing config/config_handlers.yml
1 2 3 4
# in config/config_handlers.yml
config/autoload.yml:
class: myAutoloadConfigHandler
file: %SF_LIB_DIR%/myAutoloadConfigHandler.php
Then clear the cache, and your trait should be autoloaded and cached by symfony, in just the same way interfaces and classes are.
To stay on the really really safe side, it is a good idea to monitor possible Symfony 1.4 maintenance releases for changes to lib/config/sfAutoloadConfigHandler before upgrading. It’s unlikely to happen, but it might.
And this is how to get using a really powerful PHP 5.4 feature with your existing Symfony 1.4 project. Yay!
As a web developer, you will likely at some point have a script on mydomain.com, that sends email to myuser@mydomain.com. If you have Google Apps Email set up for myuser@mydomain.com mydomain.com’s MX records, you won’t receive the mail because your mail transfer agent will just put your mail in myuser’s mailbox on the server, where myuser will never see it.
If you’re using postfix, you can go into /etc/postfix/mail.cf (or similar) and remove mydomain.com from the configuration entry mydestination. Then all mail will be delivered as usual.