Skip to content

Instantly share code, notes, and snippets.

@hacst
hacst / README.txt
Created January 15, 2012 08:27
Automatic update and restart shell scripts for rotc servers
Automatic updates and restarts for an rotc server
=================================================
1) Create an rotc user on your server (home: /home/rotc/)
2) Checkout rotc using git to /home/rotc/rotc/
3) Place these two scripts into the /home/rotc/rotc/ folder (and adjust them)
4) Adjust runme.sh:
* Make the -srv variable point to your server configuration.
* If you don't intend to run the script as root remove the sudo's inside.
If you run as root make sure the runme.sh script isn't editable by anyone else).
@hacst
hacst / playingwithchrono.cpp
Created March 17, 2012 09:12
Cross-platform, high-resolution time measurement using C++11's std::chrono
#include <iostream>
#include <chrono>
#include <thread>
using namespace std;
using namespace chrono;
int main()
{
cout << "Measurement resolution: " <<
@hacst
hacst / touchpad.sh
Created September 21, 2012 19:36
Small script for reliably disabling the touchpad over suspend/resume. Tested on Ubuntu 12.04 with a Lenovo X230.
#!/bin/sh
#
# Small script for enabling/disabling the touchpad
# reliably even if it is "hotplugged" with every
# wakeup from standy. Tested on Lenovo X230 with
# Ubuntu 12.04.
#
# Author:
# Stefan Hacker <[email protected]>
@hacst
hacst / gist:3824223
Created October 3, 2012 00:37 — forked from rlemon/gist:3814072
Callback maybe
It threw an exception from hell,
You ask me, trace wouldn't tell,
I know JS really well,
Events are in my way.
I trade my sleep for a fix,
time and more time trying tricks,
I wasn't looking for this,
Callbacks are in my way.
@hacst
hacst / .bashrc
Created January 15, 2013 12:30
Custom dash prompt which displays current branch and dirty status in the prompt line when in a git repository folder. Add to .bashrc or another file executed by it like .bash_aliases.
RS="\033[0m" # reset
HC="\033[1m" # hicolor
INV="\033[7m" # inverse background and foreground
function git_dirty() {
if [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]; then
echo -n "\[$INV\]*"
else
echo -n "\[$HC\]"
fi
@hacst
hacst / binasc2asc
Created February 3, 2013 23:02
Since people don't stop writing text as binary ASCII and rewriting the same line over and over again to decode it gets boring real quick remember it as a gist ;) Usage: echo 01000010 00101101 01110011 01101001 01100100 01100101 | ./binasc2asc.py
#!/usr/bin/env python
import sys
print "".join([chr(int(c,2)) for c in sys.stdin.read().strip().split()])
@hacst
hacst / main.cpp
Created May 25, 2013 19:44
Experimentation with typesafe indices for https://plus.google.com/u/0/103771295878903986513/posts/CiwQXgwHbJ1 Basically the gist of what I wanted from a strongly typedef'd size_t. This example only implements the operators I needed and already took quite a bit of code that might (will ;) ) contain bugs and unexpected behavior. For my application…
#include <vector>
#include <cstddef>
template<typename Tag>
class TypesafeIndex
{
public:
inline TypesafeIndex() : m_i() {};
inline explicit TypesafeIndex(const size_t a_value) : m_i(a_value) {};
@hacst
hacst / gist:2b047b19e2eb7b053610
Created October 2, 2014 20:27
MetaParams::typeCheckedFromSettings specialization for size_t in case I end up needing it one day (Mumble code)
template <>
size_t MetaParams::typeCheckedFromSettings(const QString &name, const size_t &defaultValue) {
QVariant cfgVariable = qsSettings->value(name, defaultValue);
bool ok = false;
qulonglong value = cfgVariable.toULongLong(ok);
if (!ok || value > std::numeric_limits<size_t>::max()) {
qCritical() << "Configuration variable" << name << "is of invalid format. Set to default value of" << defaultValue << ".";
return defaultValue;
}
@hacst
hacst / crash.c
Last active August 29, 2015 14:10 — forked from mkrautz/crash.c
// Build x64 version with "cl -O2 /fp:fast crash.c"
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
struct TonalityAnalysis {
int count[2]; //< Remove this or change it to multiples of 4 and it works
float std[4];
};
@hacst
hacst / line-dasharray-test.html
Created January 23, 2015 16:29
Tests animation of a signal on a line using paths with stroke-dasharray
<html>
<style>
.line {
stroke: black;
fill: none;
stroke-width: 2px;
}
.signal {
stroke: red;