Tutt Blog http://blah.thetuttroom.com Calling all dorks... posterous.com Sun, 30 Oct 2011 13:16:00 -0700 Choosing a datastore on node.js http://blah.thetuttroom.com/choosing-a-datastore-on-nodejs-18447 http://blah.thetuttroom.com/choosing-a-datastore-on-nodejs-18447

After two days of faffing with every mongodb and couchdb driver, wrapper and module available, I can finally recommend mongoq. https://github.com/zzdhidden/mongoq

I'm now reading and writing data on mongohq with ease.

The whole landscape seems to be changing very quickly with node though, so I'm sure this preference will change shortly.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/172231/avatar-01.png http://posterous.com/users/4aLvzwZ1405r Effisfor Effisfor
Sun, 30 Oct 2011 13:13:00 -0700 Choosing a datastore on node.js http://blah.thetuttroom.com/choosing-a-datastore-on-nodejs-69390 http://blah.thetuttroom.com/choosing-a-datastore-on-nodejs-69390

After two days of faffing with every mongodb and couchdb driver, wrapper and module available, I can finally recommend mongoq. https://github.com/zzdhidden/mongoq

I'm now reading and writing data on mongohq with ease.

The whole landscape seems to be changing very quickly with node though, so I'm sure this preference will change shortly.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/172231/avatar-01.png http://posterous.com/users/4aLvzwZ1405r Effisfor Effisfor
Sun, 30 Oct 2011 13:13:00 -0700 Choosing a datastore on node.js http://blah.thetuttroom.com/choosing-a-datastore-on-nodejs http://blah.thetuttroom.com/choosing-a-datastore-on-nodejs

After two days of faffing with every mongodb and couchdb driver, wrapper and module available, I can finally recommend mongoq. https://github.com/zzdhidden/mongoq

I'm now reading and writing data on mongohq with ease.

The whole landscape seems to be changing very quickly with node though, so I'm sure this preference will change shortly.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/172231/avatar-01.png http://posterous.com/users/4aLvzwZ1405r Effisfor Effisfor
Tue, 16 Aug 2011 07:23:00 -0700 Changing vimeo width on Tumblr http://blah.thetuttroom.com/changing-vimeo-width-on-tumblr-36065 http://blah.thetuttroom.com/changing-vimeo-width-on-tumblr-36065

I saw a couple of scripts, none of them worked, so here's a very simple thing that worked for me:

 

https://gist.github.com/1149215.js?file=tumblr_vimeo

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/172231/avatar-01.png http://posterous.com/users/4aLvzwZ1405r Effisfor Effisfor
Sun, 20 Feb 2011 21:56:58 -0800 Setting GPS data with AVFoundation/ALAssets http://blah.thetuttroom.com/setting-gps-data-with-avfoundationalassets http://blah.thetuttroom.com/setting-gps-data-with-avfoundationalassets If, like me, you've been banging your head against the brick wall that is the iOS ALAssetsLibrary writeImageToSavedPhotosAlbum:metadata:completionBlock: in an attempt to get it to save GPS data, then enjoy this soothing compress:

CFDictionaryRef metaDict = CMCopyDictionaryOfAttachments(NULL, imageDataSampleBuffer, kCMAttachmentMode_ShouldPropagate);
CFMutableDictionaryRef mutable = CFDictionaryCreateMutableCopy(NULL, 0, metaDict);

NSDictionary *gpsDict = [NSDictionary
  dictionaryWithObjectsAndKeys:
  [NSNumber numberWithFloat:self.currentLocation.coordinate.latitude], kCGImagePropertyGPSLatitude,
  @"N", kCGImagePropertyGPSLatitudeRef,
  [NSNumber numberWithFloat:self.currentLocation.coordinate.longitude], kCGImagePropertyGPSLongitude,
  @"E", kCGImagePropertyGPSLongitudeRef,
  @"04:30:51.71", kCGImagePropertyGPSTimeStamp,
  nil];

CFDictionarySetValue(mutable, kCGImagePropertyGPSDictionary, gpsDict);

//  Get the image
NSData *imageData = [AVCaptureStillImageOutput  jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];

//  Get the assets library
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:[image CGImage] metadata:mutable completionBlock:captureComplete];

This should live in the completionHandler of the captureStillImageAsynchronouslyFromConnection method of your AVCaptureConnection object. self.currentLocation is just a CLLocation and GPSTimestamp (A UTC timestamp) and Lat/Lng Ref are hardcoded here for simplicity's sake. And who dislikes simplicity?

Permalink | Leave a comment  »

]]>
Wed, 04 Aug 2010 04:42:15 -0700 You cannot programatically 'Like' something using the Graph API on Facebook http://blah.thetuttroom.com/you-cannot-programatically-like-something-usi http://blah.thetuttroom.com/you-cannot-programatically-like-something-usi I'm going to repeat that because type is cheap:

You cannot programatically Like something using the Graph API on Facebook.

You may be attempting this because it seems completely rational; you may even have seen this working on big sites, y'know, custom Like buttons. You are wrong.
It's not that these sites have a special relationship with Facebook, or that Facebook are worried that you'll make an Add To Cart button that actually
makes your visitors Like Equestrian Pornography websites, it is actually because you are an alien*. And wrong.

Sorry.

*Evidence that you are an alien.
http://forum.developers.facebook.com/viewtopic.php?pid=235590

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/172231/avatar-01.png http://posterous.com/users/4aLvzwZ1405r Effisfor Effisfor
Wed, 04 Aug 2010 04:32:17 -0700 CSS Positioning awry with new HTML spec http://blah.thetuttroom.com/css-positioning-awry-with-new-html-spec http://blah.thetuttroom.com/css-positioning-awry-with-new-html-spec This is just sheer ignorance on my part [again]. If you have suddenly noticed all your CSS relative or absolute positions are slightly off, take a look to see if you've changed the HTML spec of the page. I changed mine to match the recommended Facebook spec and all my positions went askew by 5 pixels.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/172231/avatar-01.png http://posterous.com/users/4aLvzwZ1405r Effisfor Effisfor
Sat, 12 Jun 2010 14:38:00 -0700 jQuery UI + Droppable Drop Event http://blah.thetuttroom.com/jquery-ui-droppable-drop-event http://blah.thetuttroom.com/jquery-ui-droppable-drop-event

My Droppable 'Drop' Event wouldn't fire. Pooh.

I had an image in my drop area div.

I removed it and it now fires the event. Yippee.

All other events fired as you'd expect, so I think this is a bug.

Moral of this woeful little tale: Keep your images in the background of your div, or get hacking.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/172231/avatar-01.png http://posterous.com/users/4aLvzwZ1405r Effisfor Effisfor
Tue, 25 May 2010 09:13:00 -0700 Postgres with Rails http://blah.thetuttroom.com/postgres-with-rails http://blah.thetuttroom.com/postgres-with-rails

I needed to get my Rails app running with a Postgres DB today (so I could take advantage of the excellent Texticle) , but found it a little trickier than expected.

Here's what I had to do (using Ubuntu Karmic)

1/ Install Postgres

This is as easy as sudo apt-get install postgresql for Ubuntu folk.

2/ Make a yourself a superuser

By default, Postgres uses 'ident sameuser' so you don't need a password when connecting from the same machine. I did:

sudo -u postgres createuser --superuser $USER
sudo -u postgres psql

which will take you to the psql command line. Set yourself a password with:

postgres=# \password $USER

This password is used (I think) when connecting to the DB remotely. The only time I've had to use it is to do a db:pull with taps.

3/ Install the postgres and postgres-pr gem

I'll be honest. I don't remember if both are necessary (I could have sworn it was just postgres), but I've got both installed so it can't hurt to have both.

They required some dependencies which were resolved by installing libpq-dev. On Ubuntu, this is:

sudo aptitude install libpq-dev

Now you're free to do

gem install postgres
gem install postgres-pr

4/ Set your database.yml

Finally, set the config/database.yml file in your Rails app to mimic:

development:
  adapter: postgresql
  database: db_name
  pool: 5
  timeout: 5000

No need for a username/password because of step 2.

Fin.

Permalink | Leave a comment  »

]]>
Thu, 22 Apr 2010 09:27:00 -0700 Fun and games with repeating jQuery animations http://blah.thetuttroom.com/fun-and-games-with-repeating-jquery-animation http://blah.thetuttroom.com/fun-and-games-with-repeating-jquery-animation

If you've ever been tempted to start new animations in a jQuery callback closure, then don't. Bad things happen.

Exhibit A:

$('div.one').animate({'opacity':0}, 200, 'linear', function(){
  $('div.one').css('display', 'none');
  $('div.two').animate({'opacity':1});
});

So far so good. All's fine and dandy with this first animation on div.two, but if you later try to animate div.two a second time, weird stuff starts happening in which this first animation repeats itself several times after your new animation finished. Very annoying and hard to track down as (as far as I'm aware) there's nothing 'wrong' with doing things this way. I'm not sure if this bug always crops up, but it certainly did for me today. You might be lucky.

I'm now achieving the same thing with...

$('div.one').animate({'opacity':0}, 200, 'linear, function(){$(this).css('display', 'none')}');
$('div.two').delay(200).animate({'opacity':1});

...where I use jQuery's lovely new delay method to get things happening in the right order. Huzzah!

Permalink | Leave a comment  »

]]>
Sun, 18 Apr 2010 13:37:00 -0700 Vimeo gem on Rails http://blah.thetuttroom.com/vimeo-gem-on-rails http://blah.thetuttroom.com/vimeo-gem-on-rails

When I followed the instructions on github to install the Vimeo gem on my Rails app, I kept getting a "Missing gems:   vimeo" error,
I found the answer in the issues section, courtesy of sealabcore:

gem install oauth-client
gem install httpclient

Not before messing around for a good couple of hours trying to fix it though. Yay?

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/172231/avatar-01.png http://posterous.com/users/4aLvzwZ1405r Effisfor Effisfor
Tue, 13 Apr 2010 08:23:46 -0700 Git add, commit and push to heroku in one command http://blah.thetuttroom.com/git-add-commit-and-push-to-heroku-in-one-comm http://blah.thetuttroom.com/git-add-commit-and-push-to-heroku-in-one-comm If all of the following apply to you:
  • You are making a heroku app
  • You are playing with something that needs to be tested live on the server (eg Incoming mail script)
  • You are lazy and the three commands to add stuff to your git repo, commit it and push to heroku are just too much for you in the wee hours of the morning
  • You don't understand why using the message "changed" for a version control contribution would ever be frustrating for someone else
  • You don't care
Then do the following:
  • Make a script called up (no extension) in your script folder alongside generate
  • Put this in the file:
    git add .
    git commit -m "minor change for live test"
    git push heroku
  • In Terminal, navigate to your app's folder, and type chmod a+x script/up
Now you can:
  • Commit your files and push them live in one simple command: script/up

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/172231/avatar-01.png http://posterous.com/users/4aLvzwZ1405r Effisfor Effisfor
Sun, 04 Apr 2010 18:29:00 -0700 Template variables don't load in Sinatra/HAML http://blah.thetuttroom.com/template-variables-dont-load-in-sinatrahaml http://blah.thetuttroom.com/template-variables-dont-load-in-sinatrahaml

Having trouble seeing variables render in your HAML templates with Sinatra?

That's because the lightweight server doesn't reload your code.

I'm using Shotgun to achieve this, reloading code on every request. Only for development mind.

$ sudo gem install shotgun$ shotgun -p 4567 sinatra_app.rb

Thanks

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/172231/avatar-01.png http://posterous.com/users/4aLvzwZ1405r Effisfor Effisfor
Fri, 19 Feb 2010 03:49:00 -0800 Google is so sensitive these days http://blah.thetuttroom.com/google-is-so-sensitive-these-days http://blah.thetuttroom.com/google-is-so-sensitive-these-days

Check case of all your Google App Engine static files, as it would seem it's much pickier live, than local.

Working locally, not live

<script type="text/javascript" src="/scripts/jquery.jcrop.min.js"></script>

Works on both

<script type="text/javascript" src="/scripts/jquery.Jcrop.min.js"></script>

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/172231/avatar-01.png http://posterous.com/users/4aLvzwZ1405r Effisfor Effisfor
Wed, 17 Feb 2010 08:36:00 -0800 Around the houses, App Engine stylee http://blah.thetuttroom.com/inboundmail-madness http://blah.thetuttroom.com/inboundmail-madness

I'm quite aware of the depths of my e-stupidity, but the only way I could get an image out of an email attachment sent to a Google App Engine app and uploaded to S3 using Boto, was this absurd backflip (literally).

class LogSenderHandler(InboundMailHandler):    def receive(self, message):        attachments = []        if message.attachments:            if isinstance(message.attachments[0], basestring):                attachments = [message.attachments]             else:                 attachments = message.attachments        for filename, content in attachments:            img = images.Image(content.decode())            if img:                img.rotate(360)                 sitehelpers.upload_to_s3(filename,                            StringIO(img.execute_transforms(output_encoding=images.JPEG)),                            message.sender)

Yes, I did just rotate an image for the sake of it, the only way to get a stream accepted by Boto (GAE Image will just send an object), is to flip the image around 360 degrees and then execute the transformation.
Anybody out there in the land of tWeb is welcome to call me on this, but in case you are struggling and need any solution possible, this works a treat for me. Ask Jeremy Clarkson about performance.

 

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/172231/avatar-01.png http://posterous.com/users/4aLvzwZ1405r Effisfor Effisfor
Wed, 17 Feb 2010 05:21:00 -0800 And so it began... or: App Engine db.ReferenceProperty() http://blah.thetuttroom.com/and-so-it-began-or-app-engine-dbreferenceprop http://blah.thetuttroom.com/and-so-it-began-or-app-engine-dbreferenceprop
12:39 me: Have you ever used referenceProperty?
12:40 Mason: nope. Isnt it just a reference to another entity?
12:42 me: Yeah, I have a photo model which references a member model for it's author, works fine, but the member model references a photo for it's avatar and because one comes before the other in my models code, the first doesn't know the reference to a model that doesn't exist yet.
  Is that fucked?
  Seems quite bog to want to do that.
12:43 Mason: Dont see the problem
  ah right
  Im with you
  Yeah, thats a circular reference I think
12:44 Which is generally a bad idea
  Although, actually, its not really a circular reference
  But id avoid that kind of thing
 me: Well it seems you have to, but the alternative seems a worse idea.
12:46 Mason: putting an avatar flag on each photo?
12:47 I think thats a better way
12:48 me: That means every user needs to do a db search of all the photos.
  I think I've found the solution
 Mason: it doesnt because appengine will index it
12:49 me: You can not explicitly state what model the reference is, and you still get all the object related goodness on the models.
 Mason: great
  worth knowing
 me: ie avatar = db.referenceProperty()
rather than db.referenceProperty(photo)
12:50 Yeah, on a blog once more
 Mason: set up toot.thetuttroom.com for all this shite
  its gold
  We could just post our gmail chats. That would be novel
12:51 2 geeks trying to work the web out. The Beeb would do a piece on it

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/172231/avatar-01.png http://posterous.com/users/4aLvzwZ1405r Effisfor Effisfor