Other articles

  1. ATmega32 Bare Metal JTAG - Part 2: Signalling and Initialization

    Today's post is a group effort. The code and electronic design comes from yesterday's AUGH, and was authored by Rob Crowther (weilawei), Anthony Russell-Smith, and Luke Dyson (massspec). We set ourselves a goal to wire up the ATmega32 for a full set of JTAG signals and to bitbang the necessary …

    read more
  2. ATmega32 Bare Metal JTAG - Part 1: External Interrupt Handling and TCK

    This example expands on the code from previous examples running code on the ATmega32. Note that this code is building towards interrogating other devices using JTAG, not demonstrating the internal JTAG features of the ATmega32 specifically.

    I started by cleaning up the driver for the status LED on PORTB0. This …

    read more
  3. Spring Cleaning Changelog

    After seven years on the previous platform (using Jekyll on Heroku), I've decided to migrate the whole shebang to the ijsbeer.org server instead of pointing the old subdomain (longchute.ijsbeer.org) at it. The Heroku platform worked well for long time, but maintaining Jekyll on their stack as they …

    read more
  4. Resistor Quiz

    This is a simple resistor quiz for both color bands to values and values to color bands. I wrote it because I couldn't find a quiz generator which worked in both directions. All values are in ohms. The list common_values can be altered to change the list of values from …

    read more
  5. OpenBSD 5.5 Installation Notes

    The OpenBSD FAQ is a tremendously useful document, but it requires you to jump around in order to find all the necessary information for installation and configuration. Often, you are given all the possible ways of doing something at once, mixed together. These notes are meant to be followed in …

    read more
  6. Arrow BeMicro CV Notes

    The BeMicro CV comes with 1 giga_bit_ of RAM, not 1 giga_byte_. This was originally specified incorrectly on Arrow's website but appears to be fixed now. The major gotcha here is that you need to use Altera's hard IP memory controller--which only functions untethered for 1 hour unless you pay …

    read more
  7. Toy Genetic Algorithm, Part 2

    This builds on the last example by using the simulate function of a Circuit to drive a circuit simulator (Ahkab) with a Population of random Circuits made of random Components (Resistor, Inductor. and Capacitor) representing low-pass filters. It runs an AC analysis and minimizes the maximum attenuation in …

    read more
  8. Lock-Free Multiprocess Shared Memory Counter (Atomic CAS) in C

    This C code forks a number of processes (children) which each contribute a per_child number of increments to a globally shared counter. The parent process does not wait for the children to exit. Each child sleeps for a random number of nanoseconds between reading the shared counter and attemping to …

    read more
  9. Multipattern Search

    This is a simple multipattern search algorithm. It isn't particularly speedy (grep -Ff words target which uses Aho-Corasick will outperform this algorithm) but it is quick to implement . It reads a list of words, sorts them into sublists grouped by length, and converts each sublist into a trie. Then, for …

    read more
  10. ATmega32 Bare Metal Boot

    Bare metal boot in AVR assembly without avr-libc. Demonstrates interrupt vectors, enabling the stack, the watchdog timer, and blinking an LED connected to PORTB, pin 0.

    On boot, the LED will cycle three times quickly, then begin blinking. After approximately 2.2 seconds, it will be reset by the Watchdog …

    read more
  11. Quick'n'Dirty DNS Swapper

    NOTE: This isn't plug-and-play production software—it illustrates a quick and dirty way to swap between OpenDNS and TorDNS using a locally installed copy of Dnsmasq. Tested with Python 2.7.5 on Debian jessie.

    Caveats: The script's owner (weilawei), group (defaults to the owner), home directory (/home/weilawei/code …

    read more
  12. Simple XOR Hash

    NOTE: I originally posted this on Snipplr.

    This is a simple hash that pads its input to the block size and XORs every block together. Output is in hexadecimal octets. Probability of collisions is extremely high and they are easy to calculate, although the function is one-way, so this is …

    read more
  13. ARC4

    NOTE: I originally posted this on Snipplr.

    This is a pure Python implementation of ARC4 as a generator to highlight its nature as a stream cipher. Several improvements can be made, for instance, it could take a nonce, use multiple state spaces (parallelizable), automatically discard the first 4K of the …

    read more
  14. HMAC

    NOTE: I originally posted this on Snipplr.

    To HMAC, pass a hash from Crypto.Hash in PyCrypto. Key should be a bytes object. Returns a bytearray.

    def pad_key(a_hash, a_key):
        block_size = a_hash.digest_size
        if (len(a_key) > block_size):
            a_hasher = a_hash.new()
            return a_hasher.digest()
        elif (len(a_key) < block_size …
    read more
  15. Chunk Data For Streaming

    NOTE: I originally posted this on Snipplr.

    Chunks data into block_size blocks for streaming, adds null padding.

    import math
    is_debug = False
    def chunk(data, block_size, padding=b'\x00'):
        data_size       = len(data)
        padding_size    = block_size - (data_size % block_size) if (data_size > block_size) else (block_size - data_size)
        is_padded       = (padding_size > 0) and (padding_size != block_size)
        total_blocks    = math.ceil …
    read more
  16. k-d Tree

    NOTE: I originally posted this on Snipplr.

    make-kd-node [median left right]: Creates a node in a kd-tree.

    make-kd-tree [k depth points]: Creates a kd-tree of kd-nodes. TODO: Not stack safe. Use loop/recur.

    kd-nearest-neighbor [a-point kd-tree]: Returns the nearest neighboring point to a given point, using a kd-tree.

    (ns kd-tree …
    read more
  17. Axis-Aligned Bounding Box

    NOTE: I originally posted this on Snipplr.

    make-aabb [a-point b-point] [a-point b-point]: Creates a 3D Axis-Aligned Bounding Box (AABB).

    aabb-contains? [a-box a-point]: Returns true if a 3D AABB contains a given point.

    (ns aabb)
    (defn ^{
        :doc "Creates a 3D Axis-Aligned Bounding Box (AABB)."
    } make-aabb [a-point b-point] [a-point b-point])
    (defn ^{
        :doc …
    read more