@darrinholst

#blog #ruby #javascript #hashtag

CameraSync

| Comments

Ever since my wife decided to dunk our camera into a strawberry daiquiri 2 years ago we have been an iPhone as a primary camera family. Remember back when you used to have an electronic device that it’s primary purpose was to take pictures? The current iPhones are good enough now to be a primary camera for most people which is great for convenience. My problem had always been getting those photos off of the phones and into my library.

My phone was fine since I’d remember to plug it in every week or two and get the pictures off. My wife’s phone was a different story. First, I’d remember to plug it in every couple months. Second, she takes a bunch of photos…some of questionable quality. Combine that with my ocd-like behavior of needing to tag every photo resulted in marathon photo tagging sessions. That sucked.

Then I found a small app called CameraSync.

CameraSync

CameraSync does what the title says, it syncs your photos to the cloud wirelessly. So I set it up on both phones to sync new photos to a Dropbox folder and now the photos just magically appear on my desktop. Small batches FTW.

But there’s more! CameraSync also does that cool background job thing once you enter a geofence. I set it up to sync every time I arrive at my house. So now there is zero interaction with the app, it just does it’s thing by itself.

Heroku’s Ugly Secret +

| Comments

In mid-2010, Heroku redesigned its routing mesh so that new requests would be routed, not to the first available dyno, but randomly, regardless of whether a request was in progress at the destination.


The unfortunate conclusion being that Heroku is not appropriate for any Rails app that’s more than a toy.

Great analysis of Heroku’s routing.

I love the service that Heroku provides, but I probably wouldn’t put too many of my eggs in their basket.

The Riddle of the Gun +

| Comments

As I said at the outset, I do not know how we can solve the problem of gun violence. A renewed ban on “assault weapons”—nearly the only concrete measure that anyone is talking about—will do very little to make our society safer. It is not, as many advocates seem to believe, an important “first step” in achieving a sane policy with respect to guns. It seems likely to be a symbolic step that delays real thinking about the problem of guns for another decade or more. By all means, let us ban these weapons. But when the next lunatic arrives at a school armed with legal pistols and a dozen ten-round magazines, we should be prepared to talk about how an assault weapons ban was a distraction from the real issue of gun violence.

Installing PostgreSQL 9.1 on Debian 6.0 with Chef

| Comments

On a project I’ve been working on I needed to get PostgreSQL updated from 8.4 to 9.anything on a Debian 6.0 system. 8.4 is the most up-to-date package on this particular system. Googling around didn’t turn anything up so this is a documentation of what I did to get it installed using Chef.

I’m assuming you’re using the postgresql cookbook and the apt cookbook.

One of the first things that you’ll probably run into while searching for a solution is the Debian Backports project. This is a repository of backported packages that will run on an older Debian system. This is where you’ll find packages for PostgreSQL 9.1. You’ll need to add this repository to APT. Add a new file called cookbooks/postgresql/recipes/squeeze_backports.rb with the following contents

apt_repository "squeeze-backports" do
  uri "http://backports.debian.org/debian-backports"
  distribution "squeeze-backports"
  components ["main"]
end

You could add this recipe everywhere you use postgresql::server or postgresql::client, but I chose to just include it at the top of each of those recipes

include_recipe "postgresql::squeeze_backports"

Now with that repository you can install the packages using the -t option of apt-get. Unfortunately I couldn’t find an easy way for the package resource in chef to do this unobtrusively since it doesn’t look in our backports repository to figure out what version to install. I did find a bug report in Chef discussing this and a fix for it, but it wasn’t fixed in the version I was using. So we’ll do it the DevOps way and hack it…in cookbooks/postgresql/recipes/client.rb I replaced:

node['postgresql']['client']['packages'].each do |pg_pack|
  package pg_pack
end

with:

execute "install postgresql-client from backports" do
  command "apt-get -t squeeze-backports install postgresql-client -y"
  not_if "dpkg-query -W postgresql-client|grep -q postgresql-client.+"
end

execute "install libpq-dev from backports" do
  command "apt-get -t squeeze-backports install libpq-dev -y"
  not_if "dpkg-query -W libpq-dev|grep -q libpq-dev.+"
end

and in cookbooks/postgresql/server_debian.rb I replaced:

node['postgresql']['server']['packages'].each do |pg_pack|
  package pg_pack
end

with:

execute "install postgresql-server from backports" do
  command "apt-get -t squeeze-backports install postgresql -y"
  not_if "dpkg-query -W postgresql|grep -q postgresql.+"
end

One last thing you’ll need to do is make sure the PostgreSQL version is set correctly in cookbooks/postgresql/attributes/default.rb which just means removing the check for debian 6.0 so it defaults to 9.1. It ends up looking something like:

when "debian"

  case
  when node['platform_version'].to_f <= 5.0
    default['postgresql']['version'] = "8.3"
  else
    default['postgresql']['version'] = "9.1"
  end

Given all of those changes and if all the moons line up then on your next chef client run you should have version 9.1 installed. Good luck and please add a comment if there is a more elegant way that I missed.

Regex Golf

| Comments

I was going to name this post Vim Golf, but it turned out to be more of a regex experiment than vim keystrokes.

So I found this cool ifttt recipe that logs all of your tweets to a dropbox file. It puts them all in a single file with a format of:

At a drive in. Wat?  @ Valle Drive-In http://t.co/Z9lz7O5F
Jun 30, 2012
http://twitter.com/darrinholst/status/218878382123909120
- - - - -

I see blurry apps
Jun 30, 2012
http://twitter.com/darrinholst/status/219074474073538560
- - - - -

Since the twitter api only allows you to get to 3200 of your tweets I though it would be a good idea to get the rest of the tweets that are accessible to me in there as well. The quickest way I know to get my latest tweets is at allmytweets.net. Allmytweets will pull down all your tweets and then show them on their page. The html ends up looking like:

8"><img src="css/extlink.png"></a></li><li>Straw in the wro
ng hole.  @ High Life Lounge <a href="http://t.co/kdMfTvPk">
http://t.co/kdMfTvPk</a> <span class="created_at">Jun 12, 20
12</span> <a href="https://twitter.com/#!/darrinholst/status
/212644435689881600"><img src="css/extlink.png"></a></li><li
>I can see @dwolla from here! <span class="created_at">Jun 1
2, 2012</span> <a href="https://twitter.com/#!/darrinholst/s
tatus/212639918541910016"><img src="css/extlink.png"></a></l
i><li>Simplify Design With  Zero, One, Many rules <a href="h
ttp://t.co/0bvdVzzo">http://t.co/0bvdVzzo</a> <span class="c

All the data is there, but not very useful for a txt file. Here’s the commands I threw at it to format it up:

Split li tags up to separate lines

%s/<li>/\r<li>/g

Preserve new lines in the tweets with a token

%s/\n/##NL##/g

Change new line tokens in between li tags back to new lines

%s/<\/li>##NL##<li>/<\/li>\r<li>/g

Reverse the order of the tweets, I want them in chronological order (The only non-replace command)

g/^/m0

Remove li start tags

%s/<li>//g

Replace li end tags with a separator

%s/<\/li>/\r- - - - -\r/g

Turn new line tags back into new lines

%s/##NL##/\r/g

Get rid of the start span tag for the date

%s/<span class="created_at">/\r/g

Get rid of the end span tag and tweet link start tag. Also change from https to http

%s/<\/span> <a href="https/\rhttp/g

Get rid of those stupid #!s

%s/\/#!\//\//g

Get rid of the image from allmytweets.net

%s/"><img src="css\/extlink.png"><\/a>//g

HTML decode

%s/&amp;/\&/g
%s/&lt;/</g
%s/&gt;/>/g
%s/&nbsp;/ /g

Get rid of remaining html

%s/<a href="//g
%s/">.*<\/a>//g

Clean up trailing spaces

%s/ *$//g

EDITING TEXT IS FUHHHH UHN! I wish I would have though of this 3800 tweets ago though.