Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
#
# Creates a multi-partition QEMU disk image from our buildroot outputs and embeds grub2
#
# TODO: Better error handling
# TODO: Better args (grub.cfg path is assumed)
#
DEBUG=1
IMAGE_NAME="dhc.img"
@anthonygclark
anthonygclark / variant_queue.cc
Created May 2, 2017 22:28
std::queue with boost::variant and dispatch type handling
#include <iostream>
#include <queue>
#include <boost/variant.hpp>
struct message_tag {
bool handled = false;
message_tag() = default;
message_tag(std::nullptr_t) { }
};
#!/usr/bin/env python2
from Tkinter import *
# Input value
input_value = 0
# Output value
output_value = 0
# Output Location
output_field = None
# using lambdas
#
c_to_f = lambda c: (c * (9.0/5.0)) + 32
f_to_c = lambda f: (f - 32) * (5.0/9.0)
print "Equality check: ", c_to_f(-40) == f_to_c(-40)
# using function
#
// List comprehension in C++11 in form of SQL-like syntax
// Example code from http://vitiy.info/cpp11-writing-list-comprehension-in-form-of-sql/
// Written by Victor Laskin (victor.laskin@gmail.com)
#include <iostream>
#include <functional>
#include <vector>
#include <future>
#include <algorithm>
using namespace std;
#!/bin/bash
_FAIL="[-]"
_SUCCESS="[+]"
_NOTE="[*]"
function _progress()
{
local PID=$1
local msg="$2"
@anthonygclark
anthonygclark / lua.vim
Last active December 21, 2015 00:08
Better (and possibly broken) lua highlighting for vim. Goes in ~/.vim/after/syntax/
syntax match luaMinus /-\@<!--\@!/
syntax match simpleOperator "[.!~:*&%<>^|=,+]"
syntax match simpleOperator "/[^/*=]"me=e-1
syntax match simpleOperator "/$"
syntax match simpleOperator "&&\|||"
syntax match simpleOperator "[][]"
syntax match parenDelimiter "[();\\]"
syntax match luaCustomParen "(" contains=parenDelimiter
syntax match luaCustomFunc "\w\+\s*(" contains=luaCustomParen
@anthonygclark
anthonygclark / stats.py
Created April 25, 2013 04:22
Some python lambdas for standard deviation....
median = lambda data: data[len(data)/2]
mean = lambda data: float(sum(data)/len(data))
hi_low = lambda data: (data[0], data[len(data)-1])
variance = lambda data, avg: sum([x**2 for x in [i-avg for i in data]])/float(len(data))
std_dev = lambda data: math.sqrt(variance(data, mean(data)))
@anthonygclark
anthonygclark / tftp.py
Last active August 25, 2018 01:00
Twisted TFTP Server with client map
# Anthony Clark
#
# Simple TFTP Server in Twisted
# TODO timeouts/error handling
#
#
# Most TFTP server do not have a
# way to change file root per client.
# This one does however using the client
# map below
@anthonygclark
anthonygclark / dtgz.sh
Created November 13, 2012 05:00
dialog tgz
#!/bin/bash
# Dialog progress for targz
# Taken from `man pv`
[ $# -lt 2 ] && echo "Supply output filename.tgz and list of files" && exit 1
out=$1
shift; files=$@
(tar cf - $files \ | pv -n -s $(du -sbc $files | grep 'total' | awk '{print $1}') \
| gzip -9 > $out) 2>&1 | dialog --gauge 'Progress' 7 70