Skip to content

Instantly share code, notes, and snippets.

View mnemnion's full-sized avatar

Sam Atman mnemnion

  • Eastern Standard Tribe
View GitHub Profile
@mnemnion
mnemnion / sparse.lua
Last active February 17, 2021 17:55
Sparse multidimensional tables in Lua
local Sparse = {}
local function new(dimension)
local sparse = {}
sparse._dimension = dimension
return setmetatable(sparse, Sparse)
end
function Sparse.__index(sparse, key)
if sparse._dimension == 1 then
@mnemnion
mnemnion / git-move.sh
Last active January 28, 2020 14:25
Move files to a different repo with history
#! /bin/bash
# Usage:
# ./git-move.sh path1/ path2/... path/to/destination/repo
args=("$@")
# All but last argument:
paths=("${args[@]::${#args[@]}-1}")
# Last argument:
dest="${args[${#args[@]}-1]}"

Keybase proof

I hereby claim:

  • I am mnemnion on github.
  • I am atman (https://keybase.io/atman) on keybase.
  • I have a public key ASAWKn9EMHtlfAZz2a4lbuFStIGWdm56UzfAcl7--TsUwwo

To claim this, I am signing this object:

// instead of having to do this all the time:
let maybe_utf8 = match stream.fill_buf() {
Ok(filehandle) => filehandle,
Err(_) => return captures,
};
let phrase = match from_utf8(maybe_utf8) {
Ok(utf8) => String::from(utf8),
Err(_) => return captures,
};
@mnemnion
mnemnion / jump.sh
Last active July 16, 2016 02:30
The essential 'jump' family of bash functions
#Essential jump code
export MARKPATH=$HOME/.marks
#jump to a directory
function jump {
cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"
}
#mark the current directory as a jump destination
function mark {
@mnemnion
mnemnion / dt.sh
Created July 16, 2016 02:25
Simple Bash functions: file -> .file, and .file -> file
#lazyfuncs for dotting and undotting stuff
function dt {
for file in "$@"; do
if [[ ${file:0:1} != "." ]]
then mv $file ".$file"
else echo "$file is already dotted"
fi
done
}
package main
import "fmt"
import "github.com/pointlander/peg"
type pegger peg.Peg {
fmt.Printf("hi")
}
func main() {
@mnemnion
mnemnion / nilortwelve.lua
Created December 4, 2014 08:13
Inconsistent behavior between Lua 5.1 and LuaJit
function advise (adviceFn, ogFn)
return function (...) adviceFn(unpack(arg)) ogFn(unpack(arg)) end
end
function foo (x)
print ("foo")
print (x)
end
@mnemnion
mnemnion / constr.rs
Created December 3, 2014 17:42
Constants aren't literal?
use std::fmt;
const FORMATTER: &'static str = "{}" ;
fn main() {
let x = 5i;
println! (FORMATTER, x);
}
@mnemnion
mnemnion / warnme.rs
Created November 23, 2014 17:24
This should be at least warned against
type Cell = u32 ;
type Kilo = u32 ;
fn main() {
let x: Cell = 5 ;
let y: Kilo = 10 ;
let z = x + y ;
println!("Cell is {}, Kilo is {}, Nonsense is {}", x, y, z);
}