Skip to content

Instantly share code, notes, and snippets.

View elfsternberg's full-sized avatar
💭
Breathing

Ken "Elf" Mathieu Sternberg elfsternberg

💭
Breathing
View GitHub Profile
@elfsternberg
elfsternberg / Cakefile
Created May 23, 2012 17:29
Cakefile to find the Coffee/HAML/Less files in a Require.JS layout and pre-compile them into their JS/HTML/CSS forms .
fs = require 'fs'
{spawn, exec} = require 'child_process'
path = require 'path'
# Requires that you 'npm install findit'
findit = require 'findit'
SRCDIR="./src"
TGTDIR="./build"
#include <tuple>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <iterator>
/* This is an attempt to translate the Boost-oriented demo of C++14
from the O'Reilly handout "C++ Today: The Beast Is Back"
(http://www.oreilly.com/programming/free/files/c++-today.pdf) into
#include <iostream>
#include <functional>
typedef std::function<int(int)> Addable;
int addem(int start) {
std::cout << "Add: " << start << std::endl;
return start + 10;
}
#include <cstdlib>
#include <err.h>
#include <iostream>
#include <cstdint>
#include <sys/mman.h>
#include <sysexits.h>
#include <unistd.h>
/* Compiles with clang 3.9.
clang++ -std=c++11 -o babyjit babyjit.cc
; Macros for the '&' and '|' operators in Hy. The '&' and '|' symbols aren't very friendly to the Hy
; parser, and the operator version is a binary operator; extending it required a little macro magic,
; and it taught me a lot about Hy macros.
(import operator)
(defmacro/g! bwor (&rest args)
(let [[g!handler (fn [args]
(if (> (len args) 2)
`(operator.__or__ ~(car args) ~(g!handler (cdr args)))
#include <iostream>
/* An implementation of Bob Nystrom's "Baby's First Garbage Collector"
http://journal.stuffwithstuff.com/2013/12/08/babys-first-garbage-collector/,
only in C++, and with some educational stuff along the way about
the new Variant (automagical discriminated unions) coming in
Libstdc++ version 4, part of the C++ 2017 standard.
*/
/* Requires the mapbox header-only variant found at
@elfsternberg
elfsternberg / babyjit.rs
Last active April 7, 2017 16:41
Baby's first Just In Time Compiler, only now written in Rust!
/*
Baby's First JIT, Rust Edition
Example derived from Curtis McEnroe's Baby's first JIT, C Version:
https://cmcenroe.me/2016/10/13/babys-first-jit.html
Works with Rustc 1.15. No guarantees or warranties. License is CC-BY,
summary at the end.
You'll need these dependencies in your Cargo.toml. Then replace your
@elfsternberg
elfsternberg / arcade
Created November 29, 2017 03:38
A script for automatically starting up various arcade games from the Williams Arcade's Greatest Hits collection with Linux
#!/bin/bash
#
# This script automatically configures and runs various games found on
# the Official Williams Arcade Greatest Hits CD via the dosbox
# emulator. To use, run the INSTALL script for the script and install
# the contents somewhere reliable, then change ARCADE_HOME to point to
# the parent directory, presumably the root of your emulated C: drive.
#
# The embedded configuration file is currently set for the audio features
# of Ubuntu 16, and fullscreen emulation. It requires dosbox. It may
@elfsternberg
elfsternberg / describe_projects.py
Last active December 12, 2017 22:01
A short script to walk a working projects directory and dump the "description" line from from all README files.
#!/usr/bin/env python
# A small script that I use to keep track of what's currently in my "Projects" directory.
# Not a big deal, but maybe useful to someone. I have a fairly disciplined layout for
# my projects so this helps me keep track of my to-dos.
import os
PROJECTS = os.path.join(os.path.expanduser("~"), "Projects")
@elfsternberg
elfsternberg / markit.hy
Created December 12, 2017 22:10
Given a URL and an optional list of tags, write an Emacs ORG-mode bookmark and associated content to a bookmark repository.
#!/usr/bin/env hy
; This script requires `pip install slugify newspaper`. It runs on Hy 0.12 and Python 3.5.
; This is part of an (incomplete) xinetd-driven toolchain for managing local bookmarks.
(import sys os os.path [slugify [slugify]] [newspaper [Article]])
(def bookmark-index
(os.path.join (get os.environ "HOME") "Wiki" "Bookmarks" "Bookmarks.org"))