Skip to content

Instantly share code, notes, and snippets.

View aleksihakli's full-sized avatar

Aleksi Häkli aleksihakli

  • Reaktor
  • Finland
View GitHub Profile
@aleksihakli
aleksihakli / create_fun.hh
Created April 13, 2014 20:33
pthread_create cpp wrapper
/**
* @brief create_fun creates pthreads from void* (*)(P*) typed functions.
*
* @param f function as void* (*)(P*) function pointer.
* @param p parameter as P pointer.
*
* @return possible error in thread creation, integer from pthread_create.
*/
template <typename F, typename P>
@aleksihakli
aleksihakli / printer.hh
Last active August 29, 2015 14:01
Atomic printer sketch for threaded C++11
#pragma once
#ifndef PRINTER_HH
#define PRINTER_HH
#include <string>
#include <sstream>
namespace {
/*
@aleksihakli
aleksihakli / app.coffee
Last active August 29, 2015 14:01
AngularJS localization for website
angular = require 'angular'
app = angular.module 'app', []
app.service 'LocalizationService', require './services/localizationservice.coffee'
app.directive 'tr', require './directives/localizationdirective.coffee'
module.exports = app
@aleksihakli
aleksihakli / gist:f8a8e84875b7e285ef6e
Created February 7, 2015 12:56
Naive script for streaming camera output from Raspbian as MJPEG; change user and app name to fit your needs
#!/bin/bash
### BEGIN INIT INFO
# Provides: kahvisio
# Required-Start: $network $local_fs $syslog
# Required-Stop: $network $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start kahvisio at boot time.
# Description: Enable kahvisio as a service.
@aleksihakli
aleksihakli / buffer.hh
Last active August 29, 2015 14:15
Custom and very naíve packet composition example of a C++ network programming exercise
#ifndef BUFFER_HH
#define BUFFER_HH
// Variadic template (C++11) std::string bufferer
#include <string>
#include <sstream>
namespace {
void _buffer(const std::stringstream&) {}
@aleksihakli
aleksihakli / nassign.coffee
Last active August 29, 2015 14:16
Nested assignment of properties by dot delimited key string in CoffeeScript or JavaScript objects
# Naive recursive property assignment to object from a dot delimited string, e.g.
#
# assignNestedPropertyByKeyString {}, 'biz', 'foo.bar.bah'
# -> {foo: {bar: {bah: 'biz'}}}
assignNestedPropertyByKeyString = (obj, val, keyString) ->
_assignNestedPropertyByKeyArray = (_o, _v, _keys) ->
_k = _keys.splice 0, 1
if _.isEmpty _keys
_o[_k] = _v
@aleksihakli
aleksihakli / models.py
Last active August 20, 2021 16:07
Django single session
from django.conf import settings
from django.contrib.sessions.models import Session
from django.db import models
class UserSession(models.Model):
"""
UserSession
Session tracking and management inspired by Gavin Ballard: