For the last couple of days i've been working on a c++ version of the Sinatra web application framework, last night at Demo Dag Malmö i did a small demo of it so i might as well do a little write up too. So a "hello world" will look like this:
In this example we'll listen for requests on / and return the string "Hello world!". The syntax is inspired by Nancy.
Currently it supports Get request and can decode parameters if present. There's also a rough support for returning (html) files and for unknown routes a 404 will be returned.
To return the file index.html when a client requests /.
Most of the syntax is still in it's infancy, so it may very well change based on input and the never-ending quest to type less. For now it's self hosted using Boost.Asio but at some point it would be nice to be able to host it under nginx/apache via some kind of module. So to start any of the examples you simple call the run method with a port number that it should listen on.
Testing is done using the framework bandit, which is also a bit of inspiration for the project.
Frankie is up on github, for now I'm using issues in the repository to track stuff that needs to be done. Feel free to point and laugh and help me make it better. To build it you'll need boost installed and clang, at this point it's only tested on OSX 10.8 with clang 5.0 (llvm 3.3).
So I got a Raspberry Pi at home that I use as a dashboard, it shows me all family calendars, train status for my stop etc. To get it to work as good as possible I made the following tweaks to my installation.
To keep the screen allways on & auto start midori
$ sudo nano /etc/lightdm/lightdm.conf # add the following lines to the [SeatDefaults] section # don't sleep the screen xserver-command=X -s 0 dpms
$ sudo nano /etc/xdg/lxsession/LXDE/autostart # comment everything and add the following lines @xset s off @xset -dpms @xset s noblank @midorifrom http://www.niteoweb.com/blog/raspberry-pi-boot-to-browser Unclutter To hide the mouse pointer when it's not used install unclutter, sudo apt-get install unclutter Script to autostart rails on startup
#! /bin/sh ### BEGIN INIT INFO # Provides: rails # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start a Rails instance # Description: Do the simplest thing possible in keeping with # upstart to spin up a single Rails instance. ### END INIT INFO # Author: Sam Pointer & Fredrik Leijon # # Do NOT "set -e" PATH=/sbin:/usr/sbin:/bin:/usr/bin:/home/pi/.rvm/bin USER="pi" PORT=3000 RAILS_ROOT="/home/pi/path_to_app" COMMAND="rails s -d" DESCRIPTION="Rails instance" RVM_PROFILE="/home/pi/.rvm/environments/default" # Load the VERBOSE setting and other rcS variables . /lib/init/vars.sh # Define LSB log_* functions. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. . /lib/lsb/init-functions # # Function that starts the daemon/service # do_start() { # Return # 0 if daemon has been started # 1 if daemon was already running # 2 if daemon could not be started su -c "source $RVM_PROFILE && cd $RAILS_ROOT && $COMMAND" $USER } case "$1" in start) [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESCRIPTION" do_start case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; esacfrom http://blog.sam-pointer.com/2011/03/24/starting-a-rails-instance-automatically-on-boot-on-ubuntu-server.html, slightly modified to support rvm. Script is also available here as a gist.
If you have a wcf service hosted in IIS that is using a binding that isn't based on http wiring (like net.tcp) it with your IoC container requires some additional steps. For this example i'm using Castle Windsor, first install the Castle Windsor WCF integration facility from nuget, that will pull Castle Windsor & their extensions for wcf.
If the binding used for the wcf service isn't based on http then the Applicaton_Start method in global.asax.cs won't be called before the service is invoked. This will cause a problem if our serivce has dependecies that need to be injected. To setup the container used to resolve dependencies we create a class in the App_Code folder under the website that has a method with the following signature: public static void AppInitialize() this method will be called before our service is invoked the first time so it is a perfect place to setup our IoC container.
A simple registration would look like this
public class AppInit { private static IWindsorContainer _container; public static void AppInitialize() { _container = new WindsorContainer(); _container.AddFacilityThe last thing to do is in the Serivce.svc markup add the castle factory attribute: Factory="Castle.Facilities.WcfIntegration.DefaultServiceHostFactory, Castle.Facilities.WcfIntegration".(); _container.Register(Component.For ().ImplementedBy ()); } }
In some cases it can be quite useful to share static content between different web applications. A way of achieving this is to include the files in a dll as embedded resources and serve them using a custom VirutalPathProvider, for most things this will work without any additional work. However if you are using dotless to make your css more maintanable you need to do reconfigure dotless to work with files served from a VirtualPathProvider.
The 2 small changes you need to do in your web.config are, under system.webServer > handlers change the value resourceType attribue from File to Unspecified.
And in the dotless configuration section add a source attribute with the value dotless.Core.Input.VirtualFileReader.
Also make sure that there's no static added under system.webServer > handlers for the less extension.