Skip to content

Instantly share code, notes, and snippets.

View larsch's full-sized avatar

Lars Christensen larsch

View GitHub Profile
@larsch
larsch / testpcap.c
Last active January 11, 2022 08:14
libpcap latency/break test
#include <pcap.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <signal.h>
pcap_t* pcap;
void* thread(void* arg) {
@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) => {
#!/bin/sh -exu
ip netns delete ns1
ip netns delete ns2
ip netns add ns1
ip netns add ns2
ip link add veth-ns1 type veth peer name veth-ns2
ip link set veth-ns1 netns ns1
ip link set veth-ns2 netns ns2
ip -n ns1 link set veth-ns1 up
ip -n ns2 link set veth-ns2 up
#!/bin/sh -exu
ip netns delete ns1
ip netns delete ns2
ip netns add ns1
ip link add veth-ns1 type veth peer name veth-ns2
ip link set veth-ns1 netns ns1
ip -n ns1 link set veth-ns1 up
ip link set veth-ns2 up
ip -n ns1 address add 10.0.0.1/30 dev veth-ns1
ip address add 10.0.0.2/30 dev veth-ns2
@larsch
larsch / README.md
Last active October 2, 2016 13:41
Cura 2 Machine Definition for Ultimaker 2 Clone/RAMPS

Ulti-Alu-Maker Cura 2 Configuration file

Machine definition for custom Aluminium Extrusion Ultimaker 2 clone (Ulti-Alu-Maker). Copy to ~/.local/share/cura/machines.

#include <avr/sleep.h>
// const int com[4] = { 10, 13, 14, 4 };
// const int com[4] = { 4, 14, 13, 10 };
// const int dig[8] = { 11, 15, 6, 8, 9, 12, 5, 7 };
// const int dig[8] = { 13, 17, 4, 6, 7, 14, 3, 5 };
// const int num[10] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f };
// int nmd[10] = {};
// int nmb[10] = {};
#include <avr/interrupt.h>
#include <avr/io.h>
volatile uint8_t rotaryPosition = 0;
void __attribute__((constructor)) init_rotary()
{
EICRA |= _BV(ISC00); // enable interrupt on change INT0 (for rotary encoder)
EIMSK |= (1 << INT0); // enable INT0 (for rotary encoder)
DDRD &= ~(_BV(PORTD3) | _BV(PORTD4) | _BV(PORTD5)); // input mode (rotary encoder clk, dt, sw)
#!/usr/bin/env ruby
#
# Convert .PNG to rasterized SVG for laster etching. Save PNG at 50.8
# DPI (2 lines per mm) or adjust 'dots_per_mm' below for different
# DPI. Horizontal resolution is also locked to this DPI in this
# version.
require 'chunky_png'
require 'nokogiri'
set -exu
umount /mnt/boot || true
umount /mnt || true
parted -s /dev/sda mklabel gpt
parted -s /dev/sda mkpart ext2 1 3
parted -s /dev/sda -- mkpart ext4 3 -1
parted -s /dev/sda set 1 bios_grub
mkfs.ext4 /dev/sda2
mount /dev/sda2 /mnt
pacstrap /mnt base grub
@larsch
larsch / esp-open-sdk-environment.sh
Created May 3, 2015 09:40
Environment variables for building for ESP8266 using esp-open-sdk
export SDK_BASE=$HOME/esp-open-sdk/esp_iot_sdk_v1.0.1
export XTENSA_TOOLS_ROOT=$HOME/esp-open-sdk/xtensa-lx106-elf/bin
export ESPTOOL=$HOME/esp-open-sdk/esptool/esptool.py
export PATH=$HOME/esp-open-sdk/xtensa-lx106-elf/bin:$PATH