Skip to content

Instantly share code, notes, and snippets.

View larsch's full-sized avatar

Lars Christensen larsch

View GitHub Profile
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdio.h>
/* #define F_CPU 16000000UL */
#define BAUD 115200L
#include <util/setbaud.h>
@larsch
larsch / termbench.c
Created September 9, 2018 10:23
Basic terminal benchmark program
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <stdint.h>
#include <stdlib.h>
void writestr(int fd, const char* str) {
write(fd, str, strlen(str));
}
@larsch
larsch / iso8610_time.c
Created August 30, 2018 13:43
Minimal function to format current time according to ISO8601 with milliseconds
#include <time.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
int iso8601_time(char* buf, size_t size)
{
struct timespec ts;
struct tm tm_local;
struct tm tm_gm;
@larsch
larsch / gist:140038
Created July 3, 2009 09:58
Treetop parser for Lua objects (limited)
LUAOBJECT_GRAMMAR = %q{
grammar LuaObject
rule luaobj
space value space { def to_ruby; value.to_ruby; end }
end
rule value
nil / float / number / string / table / boolean
end
#!/usr/bin/env ruby
def lesseq(a, b, c, d)
return a * d <= c * b
end
lower_numer = 2
lower_denom = 1
upper_numer = 3
upper_denom = 1
@larsch
larsch / rotary.cpp
Created October 12, 2017 19:45
Rotary Encoder Interrupt Handler
//
// Rotary Encoder Driver
//
// Copyright (C) 2016 by Lars Christensen <larsch@belunktum.dk>
// MIT License
//
#include "rotary.hpp"
#include <avr/interrupt.h>
#include <avr/io.h>
@larsch
larsch / build_clang
Last active September 20, 2017 18:48
Download and build CLang 3.3
#!/bin/sh -ex
wget -nc http://llvm.org/releases/3.3/cfe-3.3.src.tar.gz
wget -nc http://llvm.org/releases/3.3/llvm-3.3.src.tar.gz
wget -nc http://llvm.org/releases/3.3/compiler-rt-3.3.src.tar.gz
wget -nc http://llvm.org/releases/3.3/clang-tools-extra-3.3.src.tar.gz
rm -rf llvm
mkdir -p llvm
tar xfz llvm-3.3.src.tar.gz -C llvm --strip-components=1
mkdir -p llvm/tools/clang
tar xfz cfe-3.3.src.tar.gz -C llvm/tools/clang --strip-components=1
@larsch
larsch / throttled-event-handler.js
Created February 4, 2017 15:09
Throttled Event Handling in JavaScript
/**
* Attach an event listener to an object. Invokes the handle()
* callback on every event, and the apply() handler eventually, but
* with at least 'delay' milliseconds between each invokation.
*/
function addThrottledEventHandler(elem, event, handle, apply, delay) {
let nextApply = performance.now();
let timerId = null;
function invokeApply() { apply(); timerId = null; }
elem.addEventListener(event, (ev) => {
@larsch
larsch / bootstrap-esp-open-sdk-arch.sh
Last active January 6, 2017 16:57
Bootstrap script for ESP8266 SDK on Arch Linux
#!/bin/sh -exu
sudo pacman -S --needed --noconfirm base-devel python2 expat ncurses gperf git wget unzip
sudo ln -sf /usr/bin/python2 /usr/bin/python
git clone --recursive https://github.com/pfalcon/esp-open-sdk.git
cd esp-open-sdk
make STANDALONE=y
@larsch
larsch / list-installed-arch.sh
Last active December 26, 2016 14:46
List packaged installed in Arch Linux (except base/base-devel)
comm -23 <(pacman -Qq|sort) <(pacman -Qqg base base-devel|xargs -n1 pactree -ul|sort -u)