Skip to content

Instantly share code, notes, and snippets.

Avatar
👻
procrastinating

Lukas Kollmer lukaskollmer

👻
procrastinating
View GitHub Profile
View forceUnwrap.swift
func privateHelperFunctionThatMayOrMayNotBeSemanticallyEquivalentToTheForceUnwrapOperator<T>(_ arg: T?) -> T {
let oof = { fatalError("OH MY GOD it was null all along") }
if MemoryLayout<T?>.size == MemoryLayout<T>.size { // zero abstraction optional?
if withUnsafeBytes(of: arg, { $0.allSatisfy { $0 == 0 } }) {
oof()
}
return unsafeBitCast(arg, to: T.self)
}
View fib.cc
// run w/ `CXX -DX=VAL`, where VAL is the input value
// https://godbolt.org/z/KgRth3
template <int N>
struct Fib {
enum {
value = Fib<N-1>::value + Fib<N-2>::value
};
};
@lukaskollmer
lukaskollmer / noscript-tracking.go
Created May 7, 2019 — forked from wybiral/noscript-tracking.go
Tracking cursor position in real-time with remote monitoring (without JavaScript)
View noscript-tracking.go
// Tracking cursor position in real-time without JavaScript
// Demo: https://twitter.com/davywtf/status/1124146339259002881
package main
import (
"fmt"
"net/http"
"strings"
)
View fib.S
fib:
(__TEXT,__text) section
_main:
0000000100000f30 pushq %rax
0000000100000f31 movq 0x8(%rsi), %rdi
0000000100000f35 callq 0x100000f88 ## symbol stub for: _atoi
0000000100000f3a movl %eax, %edi
0000000100000f3c callq __F3fibii
0000000100000f41 movl %eax, 0x4(%rsp)
0000000100000f45 movl 0x4(%rsp), %eax
View fib.ll
; ModuleID = 'main'
source_filename = "main"
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-darwin18.5.0"
declare i32 @atoi(i8*)
define i32 @main(i32 %argc, i8** %argv) {
entry:
%0 = alloca i32
View fib.js
const fib_it = n => {
let [a, b] = [0, 1];
while (n-- > 0) {
[a, b] = [b, a + b];
}
return a;
}
const fib_rec = n => {
if (n < 2) return n;
@lukaskollmer
lukaskollmer / gpa.ml
Created Mar 18, 2019
An OCaml program to calculate your TUM CS GPA
View gpa.ml
#!/usr/bin/env ocaml
(*
gpa.ml
An OCaml program to calculate your TUM CS GPA
Made by Lukas Kollmer (lukas.kollmer@gmail.com)
*)
@lukaskollmer
lukaskollmer / count_homebrew_cleanup.ml
Created Feb 3, 2019
OCaml program to count the total amount of space freed up when running `brew cleanup`
View count_homebrew_cleanup.ml
(*
OCaml program to count the total amount of space freed up when running `brew cleanup`
Usage:
brew cleanup | ocaml count_homebrew_cleanup.ml
Author: Lukas Kollmer <lukas.kollmer@gmail.com>
Date: 2019-02-03
License: MIT
*)
View ffi.swift
/*
do {
let libobjc = dlopen("/usr/lib/libobjc.A.dylib", RTLD_LAZY)!
let _objc_getClass = FFIFunctionInvocation(symbol: "objc_getClass", handle: libobjc, returnType: .pointer, parameterTypes: [.pointer])
var text = "NSProcessInfo".utf8CString
var arg: UnsafePointer<CChar>!
View tum_anal_hw1.3.c.py
def f(x, y):
return (x-y, x+y)
def test(x, y):
(x_, y_) = f(x, y)
print(f"f({x}, {y}) = ({x_}, {y_})")