Friday, 6 May 2011

Rails 3 and lighttpd

This was performed on Archlinux with lighttpd 1.4.28 and rails 3.0.3

Prerequisites

Required packages:
  • lighttpd,
  • fcgi,
  • ruby,
  • and their dependencies...

Ruby Setup


Required gems:
  • fcgi,
  • bundler

(if you are behind a proxy, the magic gem command is :
# gem install GEM -r -p "http://[PROXY_URL]:[PROXY_PORT]"
)

Once you have that you need to create a "dispatch.fcgi" script to do all the rails magic. I found an example one at http://stackoverflow.com/questions/3296206/rails-3-and-fcgi .

#!/usr/bin/ruby

require 'rubygems'
require 'fcgi'

require_relative '../config/environment'

class Rack::PathInfoRewriter
  def initialize(app)
    @app = app
  end

  def call(env)
    env.delete('SCRIPT_NAME')
    parts = env['REQUEST_URI'].split('?')
    env['PATH_INFO'] = parts[0]
    env['QUERY_STRING'] = parts[1].to_s
    @app.call(env)
  end
end

Rack::Handler::FastCGI.run  Rack::PathInfoRewriter.new(YOUR_APP_NAME::Application)



Running a "bundle install" from your app root will make sure all the necessary gems are available for local use. Follow these instructions and run "ruby public/dispatch.fcgi", if you get no errors, voila!

Lighttpd Setup


Now, to set up lighttpd you need to merge this with your config:

server.modules   += ( "mod_fastcgi", "mod_rewrite" )


$HTTP["host"] == "localhost" {
        server.document-root = "/path/to/your/app/public/"

        server.dir-listing          = "disable"
        server.error-handler-404 = "/dispatch.fcgi"

        fastcgi.server      = ( ".fcgi" => ( "localhost" => (
                "min-procs"       => 1,
                "max-procs"       => 1,
                "socket" => "/tmp/ruby-beholder.socket",
                "bin-path" => "/path/to/your/app/public/dispatch.fcgi",
                "bin-environment" => ( "RAILS_ENV" => "development" )
        ) ) )

}

A quick "sudo /etc/rc.d/lighttpd restart" and a check of the error logs will tell you if it has worked

Monday, 22 November 2010

CSLU Demo Prep

Well, this is getting rather fun, but quite time consuming.

My alarm clock is ticking away and my sleep time dwindling as I type, but I just don;t feel the urge to sleep yet. I've got a talk/demo I'm preparing for Wednesday for CSLU and it is getting bigger and bigger workload wise.

I'm hoping this translates to geeky hacky fun though.

The talk is on languages and paradigms, so I'm introducing a load of languages (8 I think, off the top of my head), describing the basic constructs, and then getting the room to build a "99 bottles" program using 3 of the given languages.

The fun, but time consuming, part of this is that I'm building cheat sheets for each language. Done the first one tonight, and it was for C, so quite detailed. Hoping I can cut/paste a lot of stuff for similar languages, and hoping I don't have to fall back to a stock one. It is nice to make a custom one for the group, and also cements my own knowledge, especially of the languages I am unfamiliar with.


After the 99 bottles task, I am going to set some slightly longer challenges which can be made easier using certain paradigms. I have an OO one, which can be done procedurally. It's based around a game scenario. For procedural I will probably do a processing batch type thing. For functional I need to do a little more research.

With the department allowing me to set up a load of VMs for everyone to use too, this should be pretty fun on Wednesday ... so long as I get it all finished in time!

Monday, 27 September 2010

Conference season

September time is conference time it seems and I am currently at UbiComp2010. The UCSE2010 workshop convened yesterday which was very successful and discussion driven.

One of the main technical company sponsor was in the workshop, Autodesk, and gave an interesting talk on how they are opening their whole building's Building Information Model(BIM) to the internet. I would point you to Digital 210 King for more information.

2 weeks ago I was at IPIN, which was hosted for the first time at ETH Zurick. Very successful conference, with lots of content (200+ talks!).

For all those interested, I am putting my slides on slideshare, those being my IPIN talk (30 min ish) and my UCSE talk (5 min). The UCSE presentation has had a slide removed for confidentiality reasons, so the short presentation is even shorter.

Please navigate to http://www.slideshare.net/CarlEllis to view.

C

Monday, 13 September 2010

New Article on Jimhi

I've wrote a small article on my site, about the architecture and motivation behind my site.
More of a meta-article really.

It is pretty short, simple, and written at 2am.

Enjoy!

http://jimhi.com/content/articles/jimhi/


C

Friday, 30 July 2010

Cyber Security Challenge

To all those interested, here is a copy of my email with my solution.

To whom it may concern,

Decoded this from the last challenge!

"
Congratulations  youve found and completed the REAL challenge. Your win
code is  cyb3r=s3cur1ty*ch@ll3nge+26-07-2010.

Please email this code to our team at
media@cybersecuritychallenge.org.uk. If youre the first person to do so,
and can prove you meet the eligibility criteria (British citizen
currently resident in the UK) we will be in touch to advise how to claim
your prize. Well done and good luck in the Cyber Security Challenge
competitions taking place throughout the rest of the year
"

Figured I would go through the process:

Task one
========

Copied the data into a file.
Created the following perl script:

#!/usr/bin/perl
use MIME::Base64;

while(<STDIN>){
    print decode_base64($_);
}

I then piped the data through the script into another file
$ cat data | ./base64.pl > output

At a hunch, checked if it was an image.
$ evince output

Voila!

Task two
========

Noticed the squiggles, zoomed in a lot and noticed it covered 2 pixel
strips, so converted the image to a bitmap, then created a very hacky C
file to grab the data (after checking the wiki page for the file format).
It is quite hacky, but combined with an online binary to ascii
converter, worked well.
The C file was as follows:

#include <stdlib.h>
#include <stdio.h>

void * imgdata;
int datao(int x, int y);

int main(int argc, char *argv[]){

  FILE * fp;
  int w, h, o, off, i;
  int r, g, b, re;

  //Read binary data
  fp = fopen("output.bmp", "rb");

  fseek(fp, 0x0a, SEEK_SET);
  o = getc(fp);
  printf("1\n", o);

  //First
  off = o + 1052 * 173;
  fseek(fp, off, SEEK_SET);
  for(i = 0; i < 350; i++){
    r = getc(fp);
    g = getc(fp);
    b = getc(fp);
    if (r+g+b > 600)
      re = 1;
    else
      re = 0;

    if((i+1)%8)
      printf("%d", re);
    else
      printf("%d", re);
  }
  printf("\n2\n", o);

  //section section
  for(i = 3; i <= 172; i++){
    off = o + (1052 * i) + 1047;
    fseek(fp, off, SEEK_SET);
    r = getc(fp);
    g = getc(fp);
    b = getc(fp);
    if (r+g+b > 600)
      re = 0;
    else
      re = 1;

    if((i+1)%8)
      printf("%d", re);
    else
      printf("%d", re);
  }

  printf("\n3\n", o);

  //third section
  off = o;
  for(i = 349; i >= 0 ; i--){
    fseek(fp, off + (i*3), SEEK_SET);
    r = getc(fp);
    g = getc(fp);
    b = getc(fp);
    if (r+g+b > 600)
      re = 0;
    else
      re = 1;

    if((i+1)%8)
      printf("%d", re);
    else
      printf("%d", re);
  }
  printf("\n4\n", o);

  //forth section
  for(i = 172; i >= 3; i--){
    off = o + (1052 * i) + 3 ;
    fseek(fp, off, SEEK_SET);
    r = getc(fp);
    g = getc(fp);
    b = getc(fp);
    if (r+g+b > 600)
      re = 0;
    else
      re = 1;

    if((i+1)%8)
      printf("%d", re);
    else
      printf("%d", re);
  }

  return 0;
}

//offst from data start
int datao(int x, int y){

  int width = 350;
  int height = 175;

  int offset = (y * width * 3) + x*3;
  return offset;
}

- From this I got the following text:
Cyrnfr sbyybj guvf yvax:
uggcf://plorefrphevglpunyyratr.bet.hx/834wgc.ugzy
uggcf://plorefrphevglpunyyratr.bet.hx/834wgc.ugzy

Which after running through the following perl script:

#!/usr/bin/perl

use MIME::Base64;

while(<stdin>){
  $_ =~ tr/a-zA-Z/n-za-mN-ZA-M/;
  print $_;
}


Which led me to ...

Task three
==========

This one was tricky. I looked for ascii values on the data, reversed,
big endian, little endian, looked for 7bit data compacted into 8, 7bit
and parity (odd/even) and then only looking at bits which passed the test.

Early on I noticed there were no '3's in the data, but didn't see the
shocking clue.

Then I tried some basic frequency analysis, but as there were 56 unique
entries it was probably a polyalphabetic cypher if it was. Tried the
kasiski technique, ended up with random numbers, but tried none the
less. I was convinced that the page name was a key, or something simple,
like "cypher". Alas, it was not true. Whilst looking at the binary for
the 500th time looking for patterns of shifts which you could be
employing, but finally I saw the solution. Turns out I was doing the
rookie mistake of starting out complex.

Following is the ruby file used to decode the data:

class Cypherc


    attr_accessor :bytearray, :rawdata


    def initialize


        rawdata =

"68edcdec4e2c8eae8d2c8e2dedcd6e04d2042fedae52ceac04ccedaecd8c042ccd8c046cedad0e8dac8eac8c048e0dac044aa82889046c0d2c8d8daccdecacc5042bedae4e04ee2dcd046ced8cac042d6e04046c2f4c664ea76e666cae4e268e2f456c0d088d8d66cdecac6546c6a506e6a546062606c504a141a1410a8dac2c6eac04acad2c2d8d048e0d2d6e046ced8cac048eed04edae4e048eac2cad042c8e04adac8c2d2c086c2f4cac4e6eac6cae4e2d8e2f6c0d2c8d8daccdecacc5ed4eecc5ae6dc50429cc042fedae524eac048e0dac04cc2d4e6e8e040eac4e6eedcd048eed048ced046eed85042ccd8c046c2ccd040e4eedceac042fedae04adacac8e048e0dac04ac8d2dec2d4c2d8d2d8e2f046c4e2d8eac4e2d2c0405484e2d8e2d6e0d046c2d8e2d4faccd046cae4e4eaccd8e8d2f044eac6e2d8caccd8e042dcd048e0dac04aa692504eeac04ee2d8d8d044cac042dcd048eedae6c0d048eed042c8cce2d6eac040dedee048eed046c8d2c2dad042fedae4e040e4e2d4facc504eaac8d8d048cedcdac042ccd8c04eceded8c048dae6c6d042dcd048e0dac04682f4cac4e046aac6cae4e2d8e2f04680d2c8d8daccdecac046cedad0eac8e2d8e2dedcd6e048e2c6d2dcdec040e8d2c6cac048e0d4eedaeec0dedae8e048e0dac044eac6e8e04edcc048e0dac0

42fac2c4ec5"


        @rawdata = rawdata


        bytearray = []


        (0 ... rawdata.size/2).each do |i|

            bytearray &lt;&lt; "0x#{rawdata.slice!(0,2)}"

        end


        @bytearray = bytearray

   

    end


    def differencekeysize(length)

        diff = []

        initial = @bytearray[0]

        (1...@bytearray.size).each do |i|

            if (i%length &lt; 1)

                d = Integer(@bytearray[i]) - Integer(initial)

                initial = @bytearray[i]

                diff &lt;&lt; d

            end

        end

        return diff

    end


    def asciicharacters

        ac = {}

        (0...@bytearray.size).each do |i|

            if(Integer(bytearray[i]) &lt; 128)

                puts "#{i} : #{@bytearray[i]}"

                ac[i] = @bytearray[i]

            end

        end

        return ac

    end


    def paritycheck(byte, type = 1)

        #number of 1s

        binary = Integer(byte)

        tocheck = binary &amp; 0x7f

        par = binary &gt;&gt; 7

        ones = 0

        (0..7).each { |i|

            ones += tocheck &amp; 0x01

            tocheck = tocheck &gt;&gt; 1

        }

        ok = false

        if(type == 1)

            if par == 1 and ones.odd?

                ok = true

            elsif par == 0 and ones.even?

                ok = true

            end

        elsif(type == 2)

            if par == 1 and ones.even?

                ok = true

            elsif par == 0 and ones.odd?

                ok = true

            end

        end


        return ok

    end


    def bitvalue(byte)

        return byte &amp; 0x7f

    end


    def diffscan(index)

        diffs = []

        tocheck = @bytearray[index]

        (index+1 ... @bytearray.size).each{|b|

            diffs &lt;&lt; Integer(@bytearray[b]) - Integer(tocheck)

        }

        return diffs

    end


    def ngrams(n)

        bins = {}


        (0...@bytearray.size - n).each { |i|

            key = @bytearray.slice(i, n).to_s

            if bins[key].nil?

                bins[key] = 1

            else

                bins[key] += 1

            end

        }


        return bins

       

    end


    def bincheck

        bins = {}

        ks = 10


        (0 ... rawdata.size/ks).each {|i|

            bins[i] = rawdata.slice(ks*i, ks)

            t = []

            (0 ... bins[i].size/2).each do |j|

                t &lt;&lt; "0x#{bins[i].slice(j*2,2)}"

            end

            bins[i] = t

        }


        comp = []

        bins.each{ |k,v| comp &lt;&lt; bins[k][0] }

    end


    def shiftbits(byte)

        binary = Integer(byte)

        bottom = binary &gt;&gt; 5

        top = (binary &amp; 0x1f) &lt;&lt; 3

        return bottom ^ top

    end


    def decode

        @bytearray.each { |b|

            print "#{shiftbits(b).chr}"

        }

    end



end


c = Cypherc.new

c.decode

Those are my workings, 3 hours on the steg stuff probably, and much too
long on the last challenge.

Looking forward to more challenges :-)

Carl Ellis
http://www.jimhi.com

Friday, 23 July 2010

Cardiff and Lands End

So I decided to go on a week long tour of the good bit of the south, namely, the southwest. First though, a stop off at Cardiff to see an old friend.

As Cardiff had been explored before, and I had the car, first on the list of places to go was a pilgrimage to Barry Island, the place where every Welshman should be scarred with. Not quite sure why it is called an Island, as it was inside a cove, but those southern welshies are fairly off most of the time, like those Taven Ferry folk. Apart from children, dodgy amusements, fish and chip shops, and a dirty beach, there really wasn't much there. Some nice photo opportunities though, soon to be on my public Picasa profile. After a scramble up the headland, we decided to go and find a real beach!

The first one we hit ... had a power station firmly attached to it. Nice. So biting the bullet we continued westward, edging towards Bridgend. Luckily, before we hit that town a sign for Southerndown Beach. This was a brilliant little surfer beach and had some excellent photo spots from atop the cliffs and within the ruined castle on the opposite hilltop. As above, photos incoming.

Finally, we head back to Cardiff for food, narrowly missing the general 10pm restaurant deadline by a mere 45min, we opted for Dominos pizza. Dropping the car off in a 24hour place, I then endured the scariest walk of my life to the flat. Cardiff is scary compared to little old Lancaster, deserted hilltops, dense woodland, etc.

After that, I left for Cornwall! First stop was Newquay and a cliff walk from Watergate Bay to Porth, which was stunning! If you want to learn to surf, this seems like the place. Next day I moved towards a small village called Treen, near Penzance, via most of the southern coast. Amazing little village called Mousehole, where on the beach people had stacked rather flimsy towers of beach rocks, ready to be washed by the tide. It was like an art installation, but seemed so natural.

Treen has a history about it, near its headland is what is called the Logain Stone, which you can rock with your hands due to fine balance! Or you used to be able to, until some chap from the navy in the 1800s decided he wanted to prove the navy could topple it. After much complain by the local tourism industry, he paid to have it put back, but it has never rocked as easily since, which is something I can attest to after daring the rather leery scramble to the rock.

Next day found me at Lands End, doing the usual touristy stuff, but I did get some dirty looks off passers by as I did some undaring bouldering to get a good photo. Then to St. Ives to wonder the streets.

Today back to Newquay, and a day at the Eden Project. Brilliant place, if a little inundated with small children, but then, it is for them. Big kids have to fit in I suppose! After chilling out in Watergate Bay again, Im in the pub writing this (Cornish Ale has nothing compared to Lancastrian). Tomorrow, I go bouldering at Carn Brea. Woo. Then back into the Shire.

EDIT: Photos available here.

Thursday, 15 July 2010

Battery Monitor

I use a rather spartan windowing manager called awesome in all of my machines. This has been a fine setup until I used it on my netbook due to one small issue, battery monitors.

On my desktop machines and the laptop I use gkrellm to monitor cpu and memory and for the laptop it has a handy battery usage label. With the netbook however, screen real estate is quite valuable, so I opted for finding something to sit in the system tray.

After a quick look it seems there was nothing which was lightweight or simple or not requiring me to install the entirety of gnome.

In the end I made my own called rbatmon, then packaged it up for use in the AUR. If you have a substandard flavour of linux, not to worry, You can grab the script from my githib page here.

The most interesting challenge of this was building a package for the first time. There is a great package for Archlinux called abs (available on pacman) which fills /usr/share/pacman with some example PKGBUILDS for standard sources of gettings code from VCS's.

Page on my site regarding this is here.

AUR page is here.

C

Wednesday, 30 June 2010

Website Layout

I have modified the layout of jimhi to be user friendly. It still has a bit of improvement to be had, but at least you can find pages other than the start one now!

I shall put a feature in the site which puts it back into ridiculous interaction mode soon.

Tuesday, 8 June 2010

Very basic Makefile for LaTeX documents

So I wanted to make a basic makefile for my tex documents, so I took the Makefile from http://www.acoustics.hut.fi/u/mairas/UltimateLatexMakefile/ and modified it to be amazingly simple.

Heres the Make file:

CC=
FLAGS=

LATEX= latex
BIBTEX= bibtex
DVIPS= dvips
PS2PDF= ps2pdf

SRC := $(shell egrep -l '^[^%]*\\begin\{document\}' *.tex | sed -e 's/.tex//')
TRG = $(SRC).dvi
PSF = $(SRC).ps

all : pdf

dvi :
  $(LATEX) $(SRC) && $(BIBTEX) $(SRC) && $(LATEX) $(SRC) && $(LATEX) $(SRC)

ps : dvi
  $(DVIPS) $(TRG)

pdf : ps
  $(PS2PDF) $(PSF)

clean :
  rm *.bbl *.aux *.blg *.dvi *.log *pdf *.ps



Fairly simple and lets you choose your toolchain.

C

Wednesday, 26 May 2010

Blogs and Wonder

Hello!

I have got the barebones of a new site up at http://www.jimhi.com so go and have a bit of a browse!

Also the Lancaster Computing Society has a development blog up!
Find it at http://compsocblog.blogspot.com/

Short post from me, all developmenty stuff is going on the Computing Society blog.

C

Thursday, 25 March 2010

Article is actually ... up!

Wow, it has been ... 5 months since I said I would write that article? Well ... here it is! A link to it anyway: http://www.jimhi.com/content/articles/ .

Will be writing a nice auto table of contents generator and folding javascript now, so it looks a bit nice and follows the site a bit more.

Probably wise to add a link back too !

Next article to be written will be on a java version of the Enigma machine I wrote. Then I shall write up a maze generator and solver which Stephen Wattam and myself built for the Computing Society.

Laters

Tuesday, 24 November 2009

Possibly the third attempt to start using this.

Yo.

Well, as everyone who has a blog is aware, its hard to actually find anything to put in it, never mind actually remembering to write it.

Ok, so personal stuff. Started my studentship at Lancaster University within the EIS(http://eis.comp.lancs.ac.uk) research group. Still unsure of an actual topic, although I will probably swing towards the algorithmic side of localisation in WSN.

Still, I rarely have time to do any personal code, yet some stuff happens. Recently wrote a basic heightmap generator in Ruby, currently porting to Lua, and it outputs some nice images using image tools like RMagick or just plain VT100 colour output.

Post to follow explaining the code.

Tuesday, 25 August 2009

NSTA - Progress

Woo Progress!

NSTA was progressed to a fully fledged prototype. It now outputs the node position and the connections in the logical graph. Shall do some message browsing and a quick propogation algorithm and release it for you viewing displeasure!

C

Monday, 3 August 2009

Academic Updates

Francois, Hugo and myself have almost finished writing the paper summing up our work on PAMPA for the last 2 years. We shall be submitting to the International Workshop on Middleware for Pervasive, Mobile and Embedded Computing, at Middleware 2009 in Illinois, USA.

I have also been working on making my NS-2 trace anaylser package ready to be released and making a small example program to use. Hopefully shall be released soon. Shall open it and SourceForge it once it is ready.

Cheers all!

Thursday, 25 June 2009

Funding Results

Woo,

I am now an officially funded Ph.D student soon to be studying Localisation of mobile nodes in Wireless Sensor Networks.

I will now eat cake.

Degree finished

Ok, so my degree results are in and I passed with first class honours. Sweet.

Now just to wait for my Ph.D funding. Hopefully today or tomorrow.

I am currently working on a C/Lua agent based AI simulation and will soon br poking around with my colleagues game engine to give it physics.

Will post interesting stuff.

Monday, 27 April 2009

Exam 1 Science 0

Well, it has been a while.

I have been working on a paper of my cumulative work from the past 2 years to submit to IEEE LCN 2009 .... however the paper deadline was today. I had an exam, and so time was spent revising.

I decided to pull the paper and look to submit for MobiCom09. This should give me some time to get some more data and show better trends.

Plus any edit time is good time.

So! Exams. Concurrency and Operating Systems today. I think it went ok. Questions I answered were on User/Kernel threads, implementing fork() from first principles, some mutual exclusion questions, spin locks over semaphores and such for the lower level concurrency section.

Discussion piece for System calls, device drivers and then some file system questions and Amdahls Law stuff.

All in all it was a rather decent exam.

Right. Personal stuff.

New house, with FLATMATES. Makes such a difference not coming home to an empty cold flat everyday. There are challengers for Xbox supremacy. I like living here.

Stuck in exam period however, with exams Wednesday and Friday and the following Monday. Cram time.

There is going to be such a weekend after this that Lancaster will not know what hits it.

:D

Later

Monday, 5 January 2009

Ruby and Watir: Sending keyboard events to an element

Ok, so you need to send certain keyboard events to an element to properly test a webpage, but stuck how to do it?

Ive looked at some tutorials on the web, but there doesn't seem a simple solution.

However, I have been experimenting, and this method seems to work fine.

First off create your Watir::IE object

ie = Watir::IE.new

Then navigate to the page you are testing

ie.goto("mypage.myserver.com")

Grab the descriptor of the element you wish to send a keyboard command to (for example, a text field)

element = ie.textField(:id, "myText")

Now, I found that keyboard events only work if the Watir::IE window is on top and has focus, so for example if we wish to send a "Pageup" keyboard command to the element "myText" we would do so by

ie.bring_to_front
element.focus

element.container.focus
element.container.send_keys("{PGUP}")

This method does require Autoit(http://www.autoitscript.com/autoit3/) to be installed, and a full list of keyboard events can be found here: http://www.autoitscript.com/autoit3/docs/appendix/SendKeys.htm

Christmas Time

Well Christmas time has been and gone, and I must say that spending time with my family after 2 years is ... odd.

First off there are the hours they are awake. I don't mind getting up at 7am, however going to bed at 10pm? Thats the half day mark!

Catching up with childhood friends is also quite surreal. Everyone seems to regress 5 or so years back to the mentality of school children and old rivalries emerge. I don't think I shall be staying so long for Easter.

Well the last weekend has ended, and work begins anew! At least I can crawl out of bed to my office this week as working from my folks kitchen table. The joys of programming for a living.

And on the programming for a living note, I will be posting a tutorial on how to send keyboard events to elements using Watir.

Wednesday, 27 August 2008

Summer, Lisbon and Research

Well the talk in Glasgow went great, and I managed to receive a grant to visit the university of lisbon for a week in the summer to continue my research.

I managed to find some interesting results and managed to create a small java application to view my results visually.

It came out quite nice, and as such I have plenty of interesting avenues of new research for next year, including a new radio propagation method that takes into account buildings. It would help urban scenarios imensely.