Ruby + Sinatra + Pi = Webserver

For my last Raspberry Pi Project I tried some Webframeworks. The Sinatra Framework is an simple an quite elegant Webframework for Ruby.

As preparations you have to Install the folowing Raspbian/Debian Packages:

apt-get install ruby ruby-dev

Ruby requires the following Gems:

sudo gem install sinatra
sudo gem install thin
sudo gem install i2c

If everything went fine during your Installation process, you’ve to write only a few lines of code:

# sinatra.rb
require 'sinatra'

set :port, 8080

get '/hi' do
  "Hello World!"
end

After saving this file your Website is ready to run. Just start it.

ruby sinatra.rb

Now you can visit your First „Hello World“ Page on http://raspberrypi:8080.

ML in JAVA with WEKA (on Android)

WEKA can easily be used to perform some simple Machine Learning in JAVA. While developing a small project for classifying some data derived from a wearable for activity recognition, I missed a short summary what is needed to classify with WEKA in a JAVA project. So this post serves as a memo to myself (or anyone who finds it usefull).

A standard WEKA installation contains all the needed java files. Normally in your WEKA installation folder there resides a weka-src.jar file. Extract it with an archive manager which is able to handle the ZIP format. Create a lib directory (if not present) and run ANT.

Now it’s pretty straight forward to create some code that builds a model from some data (in this case stored in a CSV file) .
I’ve setup a short GIST containing everything needed to build the model, Evaluate a model and classify some live captured data (aka classify a single datum).

This is just a starting point to get setup. It is possible to implement much more sophisticated ML Pipelines with WEKA 😉 The Documentation under http://weka.sourceforge.net/doc.stable-3-8/ might help you.

If you want to use that on Android you can do that. The Problem is that WEKA makes use of the JAVA Swing libs to realise the GUI. This can be solved by just stripping these parts out, or just use the this repo where someone did it for us: https://github.com/rjmarsan/Weka-for-Android.

easiBeacons with AltBeacons Lib

Just got some Beacons from easiBeacons. Beacause the shipped Android Library from easibeacon is still very simple, I tried the Android Beacon Library.

It’s pretty easy. You just need the according BeaconParser.

Some sample code for the AltBeacon Library is right on their Website.

CORS and NodeJS with Express

If you’re building an RESTfull API with NodeJS (and Express), you’ll probably need CORS.
Otherwise nobody will be able to user your public API via Browsers.
So this is important vor Third-Party JQuery, Angular, whatever… Clients.

With this small Piece of Code you could make your API public and answer the CORS (Preflight) Requests.

This small function can be used via:
var express = require('express');
var app = express();
app.use(allowCrossDomain);

Duff’s Device:

Discovered some awesome piece of ANSI C Code using switch/case statements!

send(to, from, count)
register short *to, *from;
register count;
{
        register n = (count + 7) / 8;
        switch(count % 8) {
        case 0: do {    *to = *from++;
        case 7:         *to = *from++;
        case 6:         *to = *from++;
        case 5:         *to = *from++;
        case 4:         *to = *from++;
        case 3:         *to = *from++;
        case 2:         *to = *from++;
        case 1:         *to = *from++;
                } while(--n > 0);
        }
}

How is it working? Here’s the answer!

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

Managing Multiple WordPress Sites

If you have to manage different WordPress Sites at once, then you know how much time it could take to update around 20 blogs. WordPress supports since version 3.0 Site Networks. This WordPress feature is great, but has some limitations. So for example you have to run your Site Network on one Server. So I had to get something which allows me to manage blogs over different Webhoster. There are some Tools which can reduce the time to a get updates and that stuff to a minimum. Weiterlesen

© 2018 Martin Philipp

Theme von Anders Norén↑ ↑