Skip to content

Instantly share code, notes, and snippets.

View catb0t's full-sized avatar
💭
hmm

Cat Stevens catb0t

💭
hmm
View GitHub Profile
@catb0t
catb0t / minunit.h
Created February 12, 2016 02:14 — forked from sam159/minunit.h
minunit header for unit testing c code
/*
* File: minunit.h
* Author: Zed. A. Shaw, Sam
*
* @see http://c.learncodethehardway.org/book/ex30.html
*
* Created on 27 August 2014, 22:14
*/
#ifndef MINUNIT_H
@catb0t
catb0t / Assert.js
Last active February 27, 2016 22:58
var Assert = function () {
"use strict";
var AssertionError = function (msg) {
var final = "Assertion failed: " + msg;
console.error(final);
};
var args = arguments;
var res = true;
@catb0t
catb0t / signal.c
Created February 28, 2016 20:32 — forked from aspyct/signal.c
Unix signal handling example in C, SIGINT, SIGALRM, SIGHUP...
/**
* More info?
* a.dotreppe@aspyct.org
* http://aspyct.org
* @aspyct (twitter)
*
* Hope it helps :)
*/
#include <stdio.h>
@catb0t
catb0t / rands.c
Last active March 24, 2016 14:35
/*
* rands.c -- cat stevens
* compile with your compiler's equivalent to:
* gcc -Wextra -Wfloat-equal -Wundef -fverbose-asm -Wshadow -Wpointer-arith -Wcast-align -Wstrict-prototypes -Wstrict-overflow=5 -Wwrite-strings -Wconversion --pedantic -std=c11
* OR
* gcc -Wall -Wextra -Wfloat-equal -Wundef -Werror -fverbose-asm -Wshadow -Wpointer-arith -Wcast-align -Wstrict-prototypes -Wstrict-overflow=5 -Wwrite-strings -Wconversion --pedantic -std=c11
* if you drop the trigraph.
*/
#include <stdlib.h>
@catb0t
catb0t / find_even_bins.py
Created March 29, 2016 16:53
simple tool to find even numbers in a list of binary numbers (basic, simplistic solution that doesn't even look at the bits)
def find_even(binlist):
nums = list(map(lambda c: int(c, 2), binlist))
evens = list(map(lambda i: not i % 2, nums))
listof = list(zip(evens, nums, binlist))
return {i[1]:i[2] for i in list(filter(lambda g: g[0], listof))}
# >>> # copied directly from the google form
# >>> bins = """10101101
# 00000001
# 11100111
@catb0t
catb0t / T_attribute_lookups.py
Last active April 3, 2016 17:07
Proof `hasattr` is faster than exception handling in the general case
#!/usr/bin/env python3
def T_lookup(obj, name):
"looking up the attribute"
return True if name in (*dir(obj), *(obj.__dict__.keys())) else False
def T_catch_getattr(obj, name):
"using getattr and catching exceptions"
try:
return bool(getattr(obj, name))

I was browsing my mental list of interesting programming languages, and I decided to do a little research about the language to use if I wanted to, perhaps, implement a platform-independent UI for a menu / order-placing application, that looks and works the same on my computer and your computer and my phone and Richard Stallman's computer.

My first go-to was Factor, because it allows an expression of algorithmic intent alongside cool semantics and infinitely extensible syntax (think Forth plus Haskell plus LISP plus combinatorial logic and term rewriting) that makes me want to use it all day. Unfortunately, at least right now, Factor's UI toolkit is only for Linux (GTK), WIndows and Mac OSX. :(

Next, I thought about LambdaNative, a dialect of Scheme (R5RS) that attempts to target iOS, Android and the Big Three desktop platforms all at once. Unfortunately, Scheme is a very simple, tiny little useless language, and every implementation adds its own twists to make it "usable". I like Racket, with its interesti

@catb0t
catb0t / LICENSE.txt
Created May 2, 2016 18:00 — forked from jed/LICENSE.txt
generate random UUIDs
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@catb0t
catb0t / iter_preliminary.c
Last active May 15, 2016 12:07
[finished?] My first non-trivial C program, with (mostly) functional string processing.
#include <assert.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
@catb0t
catb0t / serve.js
Created May 30, 2016 15:02
super simple socket server
var http = require('http');
var url = require('url');
var fs = require('fs');
var path = require('path');
var port = (process.argv[2] || 1337);
var baseDir = __dirname;
(http.createServer(function(request,response) {
return (function() {
try {
var reqUrl = url.parse(request.url);