Skip to content

Instantly share code, notes, and snippets.

View lukaskollmer's full-sized avatar
👻
procrastinating

Lukas Kollmer lukaskollmer

👻
procrastinating
View GitHub Profile
{
"ns": "yt",
"el": "detailpage",
"cpn": "5h4OmoNG1Ceh6QJo",
"docid": "7GCb0lldiiM",
"ver": 2,
"referrer": "https://www.youtube.com/watch?v=PQjt6vLd2qA",
"cmt": "234.956",
"plid": "AAVTW6FegC7Z_Zfh",
"ei": "uVlZWYeWLsiXcK31ktgL",
@lukaskollmer
lukaskollmer / yyyyyyy.html
Created October 16, 2016 21:46
yyyyyyy.info
<html><head>
<meta charset="utf-8">
<meta http-equiv="X-Frame-Options" content="deny">
<title>▅▆▇▆▅▄▃ `^^^^^~ ░ ui▀┳╲ ☺ .info ▓</title>
<meta name="Keywords" content="keywords, keys, words, wordkeys">
<link rel="shortcut icon" href="favicon.ico">
<link href="assets/layout.css" rel="stylesheet" type="text/css">
<link href="assets/styles.php" rel="stylesheet" type="text/css">
<script type="text/javascript" async="" defer="" src="//piwik.michaelguidetti.info/piwik.js"></script><script type="text/javascript" src="assets/scripts.js"></script>
</head>
@lukaskollmer
lukaskollmer / is2or3.py
Created May 13, 2016 20:54
Check if a script is running in Pythonista 2 or 3
import os
import sys
import plistlib
def get_bundle_identifier():
plist = plistlib.readPlist(os.path.abspath(os.path.join(sys.executable, '..', 'Info.plist')))
return '{CFBundleIdentifier}'.format(**plist)
def is_pythonista_3():
return get_bundle_identifier() == 'com.omz-software.Pythonista3'
@lukaskollmer
lukaskollmer / get_available_memory.py
Last active October 2, 2023 11:41
Get memory stats in Pythonista using ctypes
#!/usr/bin/env python3
# Copyright (c) 2016 Lukas Kollmer<lukas@kollmer.me>
from ctypes import *
from objc_util import ObjCClass
NSProcessInfo = ObjCClass('NSProcessInfo')
NSByteCountFormatter = ObjCClass('NSByteCountFormatter')
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)
}
// 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 20:13 — forked from wybiral/noscript-tracking.go
Tracking cursor position in real-time with remote monitoring (without JavaScript)
// Tracking cursor position in real-time without JavaScript
// Demo: https://twitter.com/davywtf/status/1124146339259002881
package main
import (
"fmt"
"net/http"
"strings"
)
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
; 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
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;