Skip to content

Instantly share code, notes, and snippets.

walktree :: Tree -> Counter Tree
walktree (Node left right) = do
left' <- walktree left
right' <- walktree right
return (Node left' right')
--walktree (Node left right) =
-- walktree left >>= \left' ->
-- walktree right >>= \right' ->
-- return (Node left' right')
walktree (NormalLeaf x) = return x
@BBBSnowball
BBBSnowball / espminiterm.py
Last active June 10, 2021 11:21
serial monitor for ESP8266, run "pio run -t upload" on ctrl-t ctrl-u, decode stacktraces, paths are hardcoded for platformio with nodemcuv2 board
import serial
from serial.tools import miniterm
import subprocess, sys, re, os
class ESPMiniterm(miniterm.Miniterm):
def handle_menu_key(self, c):
if c == '\x15': # ctrl-u
self.upload_file()
else:
super(ESPMiniterm, self).handle_menu_key(c)
@BBBSnowball
BBBSnowball / WifiDisplay.ino
Created August 4, 2016 08:48
ESP8266 plus 7segment display with MAX7219
/*
* Copyright (c) 2015, Majenko Technologies
* Copyright (c) 2016, Benjamin Koch
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
/indices/
/self-installs/
@BBBSnowball
BBBSnowball / fan
Created February 13, 2014 13:31
set fan level for Thinkpad
#!/bin/sh
#cat /proc/acpi/ibm/fan
echo "$*" >/proc/acpi/ibm/fan
head -n 3 /proc/acpi/ibm/fan
@BBBSnowball
BBBSnowball / git-find-big-commit.sh
Created November 15, 2013 12:07
Find big commits in git
#!/bin/sh
# http://stackoverflow.com/a/1557398
for sha in $(git rev-list --all --pretty=format:"" | sed "s/^commit //") ; do git diff-tree -r -c -M -C --no-commit-id $sha | awk '{print $4}' | git cat-file --batch-check 2>/dev/null | awk '{ sum+=$3 } END {printf "%010d %s\n", sum, "'"$sha"'"}' ; done | sort | tail
@BBBSnowball
BBBSnowball / test_constructor_exception.cc
Created October 13, 2013 00:56
Test program for exception thrown in constructor
#include <iostream>
#include <string>
using namespace std;
class PrintLifecycle {
string name;
public:
PrintLifecycle(string name) : name(name) {
cout << "constructor of " << name << endl;
@BBBSnowball
BBBSnowball / foo.cpp
Created October 13, 2013 00:52
Test program to show the difference of reference, pointer and copy
#include <iostream>
#include <memory>
class Foo {
std::string name;
public:
Foo(std::string name) : name(name) {
std::cout << "creating " << name << std::endl;
}