Skip to content

Instantly share code, notes, and snippets.

@adrusi
adrusi / petri.py
Created Oct 6, 2011
Simulates the population and growth of bacterial colonies. Requires a 256 color terminal.
View petri.py
from random import *
# from colors import *
import os
import math
import sys
import time
def gen_row(min, max):
return [randint(min, max) if random() <= 0.4 else 0 for i in range(0, 50)]
@adrusi
adrusi / gist:1905351
Created Feb 25, 2012
TCO in CoffeeScript
View gist:1905351
tco = (fn) -> (args...) ->
if @recured? or @args? or @recur?
unless arguments.callee.noWarn
# here we are taking precautionary measures to make sure we don't
# accidentally overwrite some important properties in the context named
# "recured", "args" or "recur". The warnings can be disabled by setting
# the `noWarn` property of the function to true
throw new Error """
calling a tail-recursive function in this context will overwrite the
properties "recured", "args" and "recur".
@adrusi
adrusi / styles.less
Created Jul 8, 2014
Gnome 3 (adwaita) scroll bars for the Atom text editor.
View styles.less
@scrollbar-background-color: #d6d6d6;
@scrollbar-color: #9b9d9e;
.scrollbars-visible-always {
::-webkit-scrollbar {
width: 13px;
height: 13px;
}
::-webkit-scrollbar-track,
View keybase.md

Keybase proof

I hereby claim:

  • I am adrusi on github.
  • I am adrusi (https://keybase.io/adrusi) on keybase.
  • I have a public key whose fingerprint is F4C0 564A 2C88 DA3F 7F5D B0C6 B611 CA38 220B 5E16

To claim this, I am signing this object:

@adrusi
adrusi / generator.zig
Last active Jul 9, 2022
Generators in Zig 0.6.0
View generator.zig
const std = @import("std");
const debug = std.debug;
const builtin = @import("builtin");
const TypeInfo = builtin.TypeInfo;
const TypeId = builtin.TypeId;
/// Iterator based on async functions. Equivalent to generators in Python,
/// Javascript, etc.
///
@adrusi
adrusi / closure.zig
Created Jun 15, 2020
Userland implementation of closures in Zig
View closure.zig
const std = @import("std");
const assert = std.debug.assert;
pub fn closure(bindings: var) ClosureInternal(@TypeOf(bindings)) {
return ClosureInternal(@TypeOf(bindings)) { .ctx = bindings };
}
fn ClosureInternal(comptime Spec: type) type {
comptime {
const spec_tinfo = @typeInfo(Spec);
@adrusi
adrusi / async_generators.zig
Last active Jun 21, 2020
Async generators in Zig 0.6.0
View async_generators.zig
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const expect = std.testing.expect;
const tuples = @import("tuples.zig");
const Tuple = tuples.Tuple;
const tuple = tuples.tuple;
const comptime_utils = @import("comptime_utils.zig");
@adrusi
adrusi / comptime_utils.zig
Created Jun 21, 2020
Tuples in Zig 0.6.0
View comptime_utils.zig
const std = @import("std");
const bufFmt = std.fmt.bufPrint;
pub fn compileErrorFmt(comptime fmt: []const u8, comptime args: var) void {
comptime {
var buf: [4096]u8 = undefined;
@compileError(@as([]const u8, bufFmt(&buf, fmt, args) catch |_| {
@compileError("compileFmt: output is too long. Cannot output @compileLogs longer than 4096 bytes");
}));
}
@adrusi
adrusi / example.sh
Last active Apr 3, 2022
Full-featured argument parsing in non-forking POSIX shell
View example.sh
#!/bin/sh
source parse_args.inc.sh
arg_alias() {
case "$1" in
h) printf help;;
m) printf monitor;;
w) printf wait;;
r) printf rate; false;;
@adrusi
adrusi / kak.inc.sh
Last active Apr 10, 2022
andreyorst/powerline.kak: resize modeline dynamically base on window size
View kak.inc.sh
kakquote() {
out=
for text; do
out=$out"'"
while :; do
case "$text" in
*\'*)
out=$out${text%%\'*}\'\'
text=${text#*\'}
;;