How to get PostgreSQL to work with Rails3 on Mac OSX snowleopard

I’m about to host a web app on Heroku and they are using PostgreSQL for database. Followed the instructions and added gem ‘pg’ to my Gemfile and made bundle install but it failed:
Installing pg (0.11.0) with native extensions /Users/kalle/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:552:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

Thought I didn’t have PostgreSQL installed so installed it via MacPorts:
sudo port install postgresql90

but still got the same error! After a bit of googling I found out it was due to that the bin folder was not in the path. So by doing this it worked:
export PATH=/opt/local/lib/postgresql90/bin/:${PATH}
env ARCHFLAGS="-arch x86_64" bundle install

Vindmätarbygge – framgångar

Sist jag rapporterade om projektet hade jag bara lyckats kompilera NewSoftSerial men sedan dess har jag lyckats köra det och efter ytterligare en del omkodning bla pga Minins minimala mängd RAM så fungerar det nästan!

Minin har bara 1k RAM så jag kan inte läsa in hela HTML svaret i minnet för det kan mkt väl vara större än så. Eftersom jag bara är intresserad att just nu rapportera in svar och att det går bra skrev jag en ny POST funktion som läser rad efter rad och kollar om en av dem innehåller HTTP/1.1 200 OK så jag vet att det gick bra. Man skulle kunna göra en utökning av GET med som bara returnerar själva XML delen som ett REST anrop ger tillbaka, allt för att nyttja så minimalt med RAM som möjligt.

Dock har jag ett problem kvar, efter att läst en del data så bootar Arduinon om! Jag har lyckats lokalisera det till när jag gör läsning från porten så gissar att NewSoftSerial inte klarar sig så bra i mycket minnes begränsat utrymme. Någon som har bra tips om hur man lätt debuggar dessa typer av problem? Bara göra massa print känns för osäkert då det kan uppstå timing problem etc…

Vindmätarbygge – serieport

Arduino Mini Pro har bara en hårdvarubaserad serial port. GSM Arduino lib som jag tänker använda kräver en för att prata med Telit kretsen men samtidigt vill man gärna ha på debuggingen och den är bunden till den enda hårdvaruporten som finns. Problem!

Det finns ju ett Arduino lib för mjukvaruportar men det är en hel del som inte stöds i det. Men dock finns NewSoftSerial som har stöd för det mesta så det borde inte vara så svårt att skriva om GSM Arduino lib att använda den serieporten istället. Så det blev kvällens lilla projekt.

Så nu har jag en ny version av det som jag kallar Soft GSM Arduino lib. Dock krävde det att jag fick hacka om NewSoftSerial lite också så att den blev än mer kompatibel med vanliga hårdvaruserieportarna. Dock inte hunnit med att testa något alls, men det kompilerar iaf:)

Nu är det dags att sova, god natt!

Vindmätarbygge – vindgivare

Som jag skrev igår skickade jag mail till flera svenska återförsäljare. Fick ett par svar idag och tänkte bara snabbt sammanfatta läget.

Safecast – skickade ett långt svar men hade inget konkret svar men var intresserade och ville veta mer. Diskussionen fortsätter och skickade dem ett längre mail precis.

Svenska Termoinstrument – svarade att de representerar två tyska tillverkare av vindgivare (Adolf Thies GmbH resp Lufft GmbH ) vars givare endast är avsedda för industrin (vindkraft, fastighetsautomation etc.). Några lågprisgivare under 1500 kr finns tyvärr inte i deras sortiment.

Livedata – deras billigaste givare låg på ca 5000 kr, långt över vad jag hoppats på. De får gå bort.

FDS Mätteknik har jag inte hört något från. Dock fick jag en kommentar från Magnus som byggt WindWiz på mitt förra inlägg att ClasOhlson har en trådkopplad givare som reservdel till en annan väderstation. 440 kr kostar vindriktning och vindhastighetsgivare ihop. Beställt!

Vindmätarbygge – start

Har börjat på ett litet projekt, bygga en vindmätare som via mobilnätet postar mätdata till en webserver som sedan kan plotta grafer etc.

Hemma hade jag redan några Arduino samt en GSM modul. Och just till denna GSM modul finns det redan ett Arduino lib så man kan göra GET och POST anrop mot en webserver.

Dock när jag skulle börja med att ansluta min Arduino upptcäkte jag att mina 5V mini inte var direkt lämpliga då jag skulle behöva lite konverteringselektronik för signalnivåerna. Så beställde istället några nya 3.3V istället som jag kan ansluta direkt.

Har även börjat leta efter lämpliga vindgivare som inte kostar en förmögenhet. Började med att kontakta Campbell Scientific och Vaisala men de vill ha mellan 10.000 och 30.000 för de givare jag frågade om. På tok för dyrt! Har skickat iväg ett antal mail till flera olika svenska leverantörer för att se vad de kan erbjuda. De jag kontaktat är SafeCast, Svenska Termoinstrument, LiveData och FDS Mätteknik.

Hittade även lite andra hobby projekt när jag sökte runt efter bra lösningar. Det intressanta var att båda projekten bygger på Arduino 🙂 Visar lite hur stort Arduino börjat bli. WindWiz år också en GSM uppkopplad vindmätare och använder en mätare från ClasOhlson. Så letade runt lite hos dem och hittade en vädligt prisvärd lösning, reservdel till väderstation. För endast 245 kr fick jag en komplett vindmätare med både hastighet och riktning. Dock idag när jag fick den insåg jag att jag missat en viktig del, den kopplades inte in med sladd som jag trodde utan trådlöst 🙁 Så började söka på nätet och hittade ett projekt till av en svensk kitare som verkar använt precis samma mätare. Har skickat ett mail så får vi se om han kan hjälpa till att koppla in den jag köpte från Classe.

Mätaren från Classe har ett par lödpunkter på kretskortet som skulle tyda på att man kan få ut seriedata direkt från kretskortet och inte behöver bygga en radiomottagare. Så här ser kretskortet ut:

Kretskortet med lödpunkter utmärkta

Får se när jag får svar på mailen jag skickat iväg men nästa steg blir nog i vilket fall att koppla ihop GSM kort och Arduino och prova biblioteket för att posta in lite data i en enkel web app jag hackat ihop.

Timelapses and video

Last week we where hiking in the Swedish mountains and as usual I brought the camera and a GorillaPod. Earlier this summer I saw Sean Stiegemeiers amazing timelapse from Iceland and got interested in creating these kinds of videos. One of the evenings we had some really nice clouds coming in over us and passing some peaks closeby. I put up the camera and shot a number of sequences. Found out that I could generate timelapses directly from Lightroom(following Sean McCormack on Twitter) so started experimenting with it. I wanted to merge several of them into one video and the only video editing tool I have is iMovie or Windows Movie Maker. I decided to use iMovie since I have used it mostly lately. Here is the result.

Doing this and converting another video also shot earlier this summer I learned a number of things that I wanted to share.

  1. When making timelapses take many photos!
    In a video a second or two is a very short clip and aim for 24 frames per second so if you want a 10 second clip, you have to take 240 photos!
  2. Black first frame?
    The generated videos from Lightroom all have a first black frame. I do not know how to turn that off but neither have I found anyone having this issue. When I imported the videos to iMovie it didnt become a problem but it might be due to the cross fading transitions I use.
  3. Compression settings. What are good values and how do you avoid getting a 500 Mb file?
    The details is of course very depending on which software you use but in general it should apply to any. In iMovie you have a couple of options. The one that I have noticed influences the file size the most is the maximum bitrate. Of course Quality is a major factor but if you want high quality but not huge size then its the bitrate. After googling a bit I found out that for a 720p movie 6Mbit/s is good. You could go a bit lower but I tired 4.5 Mbit/s and saw some compression artifacts that I didn’t wanted. The rest of the settings I left on default, see image below.

Fri myndighetsinformation!

Igår började lagen om vidareanvändning av information att gälla. Den är en konsekvens av PSI(Publi Sector Information) direktivet från EU. Detta är viktigt ur ett demokratiskt perspektiv för det ger oss alla möjlighet att använda den information myndigheterna samlar ihop om oss och vårt samhälle! Men det är också en enorm potential för en massa entreprenörskap!! Men för att den möjligheten inte skall gå i stöpet är det enormt viktigt att informationen blir tillgänglig i väldokumenterade och standardiserade strukturer. Så nu vill vi se alla myndigheter komma med öppna och tydliga APIer!

Flera webentreprenörer tar nu och uppmanar myndigheterna att snabba på denna process och att göra det enkelt och tydligt. Jag vill härmed ansluta mig till denna grupp genom att publicera följande öppna brev som är författat av Jonas Lejon och Joakim Jardenberg:

Kära generaldirektörer, låt oss tillsammans göra världen bättre!

Ni sitter sedan många år tillbaka på stora mängder data som är intressant ur flera aspekter. Det handlar om information som vi skattebetalare redan betalt för. Olika aktörer i samhället kan vidareutnyttja information för olika ändamål, t.ex. genom skapandet av nya e-tjänster, såväl kommersiella och ideella. Men ofta har det varit förknippat med stora kostnader och svårtillgängliga lösningar. Äntligen ser vi en ändring komma till stånd.

Att vi entreprenörer kan ta del av denna information även elektroniskt har vunnit laga kraft sedan idag, den 1:a juli 2010. Den så kallade PSI-lagen (Prop. 2009/10:175) öppnar upp för stora möjligheter att skapa tjänster som förbättrar vardagen för oss alla.

Att ni själva sitter på kunskapen att förädla denna information i viss mån är mycket möjligt, rent av sannolikt, men om fler får möjlighet att jobba tillsammans så kommer garanterat resultaten att bli ännu bättre. Det saknas sannerligen inte internationella exempel på de effekter man får av att släppa publikt data tillgängligt för vidareutnyttjande.

Vi vill därför uppmana alla myndigheter och deras chefer att snarast börja arbeta i PSI-direktivets anda och uppfylla den intention som lagen speglar. Citerar från regeringskansliets sida om PSI – vidareanvändning av information:

”Syftet med lagen är att främja utvecklingen av en informationsmarknad genom att underlätta enskildas användning av handlingar som tillhandahålls av myndigheter.”

För att detta ska bli verklighet krävs i praktiken ett API till era tjänster. Vi vill därför med detta brev uppmärksamma er på behovet av att ni skyndsamt öppnar upp en sådan möjlighet. Först då kan vi börja jobba på allvar, och först då kan både ni, vi, lagstiftarna och samhället se den fulla nyttan av den utveckling som startar nu. Vi är många som är villiga att hjälpa till, så se det här brevet också som en utsträckt hand. Dialogen är igång, nu är bollen er.

Ovanstående text är i huvudsak författad av Jonas Lejon (ansvarig bland annat för tjänsten govdata.se)), bearbetad av Joakim Jardenberg (bland annat projektledare för Makten och Öppenheten) och helt fri att kopiera, bearbeta och vidarebpublicera enligt CC0.

—-

För den som vill läsa mer om den nya lagen 2001:566 så finns lagtexten bl.a. på Lagen.nu: https://lagen.nu/2010:566. Mycket intressant finns att läsa i propositionen bl.a. detta:

i direktivet före-skrivs att handlingar ska göras tillgängliga i alla befintliga format hos myndigheten. Detta innefattar även kravet att elektroniska handlingar ska lämnas ut i elektronisk form, under förutsättning att det är möjligt och lämpligt.

Hjälp oss att sprida budskapet genom att länka och återpublicera ovan text!

Och jag kan inte annat än att falla in i uppmaningen: Hjälp oss att sprida budskapet genom att länka och återpublicera ovan text!

Smartson kamera test

Smartson presenterade nyss en ny variant av deras tester. Man testar ihop i team samt de vill man använder sin blogg! Känns både väldigt skoj och helt rätt. Just med att testarna bloggar i sina bloggar gör ju att spridningen nog blir större.

Jag anmälde mig och Staffan till deras test av Canon 550D. Vi kan bli ett riktigt bra team tror jag. Staffan funderar just på att skaffa en systemkamera så han har många nybörjarfrågor och funderingar. Å andra sidan har jag fotat mycket med systemkameror de senaste 5-6 åren. Jag har ett par DSLRer men ingen med video så testen innehåller både sådant jag känner väl till samt video som jag är jättesugen att testa.

Om vi kommer med kommer jag både ladda upp bilder här men kanske även återaktivera min fotoblog. Nu är det bara hålla tummarna.

Creating your own engine for Lightroom galleries

I have been pondering creating my own plugin for generating web galleries of my photos for some time but this weekend I took the time! I have been looking around at different solutions and both Highslide Gallery from The Turning Gate and Elegance from Photographer’s Toolbox are both clean and uses CSS and JavaScript. But they both had a number of issues I didn’t like. The main problem with elegance is that someone with a large display cannot really enjoy the photos since they do not scale, and someone on a small screen can’t see the whole photo. TTG Highslide lacked a few other features,no way to change the controls to small white icons instead of text, no way to place the controls above the enlarged image, no numbers in the heading, unable to remove the thumbstrip when viewing the enlarged images and not possible to constrain the size of the popup so it does not resize depending on image.

But HighSlide which TTG HighSlide is based on is extremly re-configurable and you can fix all of those issues. Specifically easy to do since it also has a very nice visual editor!

Though to use my own modified version required me to write my own web engine. It was very easy to get started with the aid of the Lightroom SDK. With the tutorials in the manual one can create a new web engine in minutes. On the other hand it was not that easy to integrate with Highslide. But after a couple of hours I now have a working version which I’m satisfied with at the moment. I used the Highslide editor to create a how I wanted the enlarged photos and navigation to look like. I downloaded the zip file from the editor, copied it into my new lrwebengine folder. Created a new index.html file and copied all from the highslide-custom-example.html into it. All new styles etc I put into a new gallery.css file. Once I had got a look I liked the next step was to take it appart and but into header.html, footer.html and grid.html. 

Then it was bout time to start tweaking the manifest and the galleryInfo files to do what I wanted. One of the things I have not liked with the default galleries is the odd folders they put photos in. But in Lightroom Blog I found out how to control where the web engine store photos.

I ran into some more small problems, related to Lua since I had never written any programs in Lua before. Programming in LUA was useful! Also looking into the LightroomForums.Net was helpful for more Lightroom and plugin related problems.

I have not added support for LiveUpdate yet since that required some more JavaScripting.

Things to improve:

  • change the size of the enlarged photo
  • change the colour of the background for the enlarged photo
  • change font and size for Title, Description, Image number and Caption
  • change number of coloumns
  • change page background colour and thumbnails layout
  • add support for live update
  • add support for facebook comments?

If you want to create your own Highslide gallery or based on some other library you can download my files here. I have not included the Highslide files since they are not totally free and you need to agree to the license before using them.

Experiences from another 24 hour camp…

I’m on the train home to Gothenburg after a couple of superfun days in Stockholm!

On Wednesday evening we(me, Staffan, Daniel and Anders) took the boat to Yasuragi Hasseludden together with about 120 other internet geeks for the second 24 hour Business Camp. We all had a great evening with delightful food and marvelous bathing in the hot springs at Yasuragi! Thursday started with presentations from the sponsors and it was really interesting to see that the sponsors put in much more support or funding this time than last. The whole 24 hour concepts seems to have matured and caught a much bigger interest this time. Though the whole comradeship and openness which I like a lot was still very present!

At lunch on Thursday it all started with 24 hours of frenetic coding and building. The rooms was filled again with almost tangible energy which is a great drug to help that sleep stay away. Compared to last time and to my experience from 24HourSormland we did a lot of things right this time! I’ll try to recollect the most important ones here.

Agile development – we decided to have 30 minutes development itterations. Problems became visible quickly, everyone in the team was aware of how things developed etc. At times, specifically late in the morning the iterations became a bit longer, about an hour each and things started to slow down. It’s hard to tell when to stop for a short sleep break. We gave up at 6 in the morning and slept for 3 hours for a final burst until 12.

Many developers – On the last 24hbc I was alone and on 24HourSormland we were four people but I was the only developer. This time we were three developers and it was so obvious how much quicker things got implemented! Also problems was solved much quicker since if we found out that someone had been stuck on one problem during an iteration all three of us could try to solve it! And we could provide each other with new perspectives on the problem as well.

Clear concept and finished idea – when going to Yasuragi we had most of the interaction with HiThere ready. The application flow had been decided in advance, everyone in the team knew roughly how it was supposed to be used and what things needed to be developed. This really helped us to divide things into tasks, Anders worked with the graphics, Staffan worked the backend, Daniel with the iPhone app and I worked with the social network integration.

Prepare as much as possible – we were very well prepared. The hosting on GleSYS servers were setup days in advance. We had registered the domain, pointed it at our server, installed all software on the server and had prepared a deployment script. By execute that script we had a new version up and running live on the site within minutes! We had made sure we know how to get push notifications working on the iPhone, we had checked all certificates were proper and working, all development tools working. We had even prepared to develop the whole site and application without any network connectivity, e.g. setup a code sharing repository on a USB stick which we could hand around to synchronize the code in the team.

Some lessons learnt:
It helps a lot to have used the APIs or libraries before. This time a lot of time was spent on the Facebook integration and there are still more to fix here. One reason why it took time to solve things was that we used the Facebooker plugin to Rails. It works great to use plugins in Rails when everything works but if they are not well documented which is the case with Facebooker and things starts to behave strangely it is much harder to find what is causing the problem. We have a couple of other projects which are about to use Facebook in a similar way so even if things didn’t work out a lot was learnt about the Facebook API.

Another thing which we didn’t focus on was a sales pitch. It was more ad hoc style since we all focused on the problems ahead. The model used at 24HourSormland is probably better, where presentations are done a couple of days after the actual camp. Or one should bring on a person in the team focusing on marketing, sales and presentation during the 24 hours!

Some really useful tools:
Skype – Skype was really useful during the event. We created a chat for the four of us and used it to sync each iteration. Once every hour or so we took a short break in conjunction with the sync to get short breaks too but Skype helped us stay focused on the tasks while quickly making everyone aware how things developed. Some problems were also discussed via Skype as well.

DropBox – DropBox was great for sharing files among us such as graphics or shorter texts. It cannot handle revisions as a code repository can but it is still very useful because it is fast and files stays organized. It is also great how well it integrates into the ordinary file system.

So that’s a long summary of a great event! If you like HiThere, please head over to the 24 hour business camp website and vote for us! You can read a bit more about HiThere on the 24hbc blog but it’s in Swedish. There are also lots of photos uploaded and tagged on Flickr!

Tags: ,