Skip to content

Instantly share code, notes, and snippets.

View ruohola's full-sized avatar

Eero Ruohola ruohola

View GitHub Profile
@ryandabler
ryandabler / Smallfuck.ts
Last active October 18, 2024 08:22
Smallfuck interpreter built using TypeScript's type system for this article: https://itnext.io/typescript-and-turing-completeness-ba8ded8f3de3
//
// ------- General utilities ---
//
type ArrayFromNumber<N extends number, A extends any[] = []> = A['length'] extends N ? A : ArrayFromNumber<N, [...A, any]>;
type Increment<T extends number> = [...ArrayFromNumber<T>, any]['length'];
type Decrement<T extends number> = ArrayFromNumber<T> extends [...(infer U), any] ? U['length'] : never;
type Rewind<Arr extends any[], I extends number, Depth extends number = 0> = Arr[I] extends '['
? Depth extends 0 ? I : Rewind<Arr, Decrement<I>, Decrement<Depth>>
@matangover
matangover / README.md
Last active August 13, 2024 11:23
Easily open files from Python tracebacks in iTerm2 directly in your editor
  1. In iTerm2, go to Settings -> Profiles -> Advanced -> Smart Selection -> Edit
  2. Click + to add a rule with the following values:
    • Notes: Python traceback
    • Regular Expression: File "(.+)", line ([0-9]+), in .+
    • Precision: Very High
  3. Click Edit Actions... and add an action to open in your editor. For example, if you use VS Code, add an action with the following values:
    • Title: Open in VS Code
    • Action: Run Command...
  • Parameter: /usr/local/bin/code -r -g "\1":\2
@nlohmann
nlohmann / remove_empty_elements.py
Created March 12, 2018 14:19
Remove empty arrays, objects or null elements from a JSON value
def remove_empty_elements(d):
"""recursively remove empty lists, empty dicts, or None elements from a dictionary"""
def empty(x):
return x is None or x == {} or x == []
if not isinstance(d, (dict, list)):
return d
elif isinstance(d, list):
return [v for v in (remove_empty_elements(v) for v in d) if not empty(v)]
@charlietran
charlietran / TerminalVim.scpt
Last active August 28, 2024 20:23
Open file in iTerm vim for MacOS Sierra
-- TerminalVim.app
-- This creates a shim Application that will enable you to open files from the Finder in vim using iTerm
-- To use this script:
-- 1. Open Automator and create a new Application
-- 2. Add the "Run Applescript" action
-- 3. Paste this script into the Run Applescript section
-- 4. Save the application as TerminalVim.app in your Applications folder
-- 5. In the Finder, right click on a file and select "Open With". In that window you can set TerminalVim as a default
@datagrok
datagrok / git-branch-simplify.md
Last active April 16, 2024 17:26
How to simplify the graph produced by git log --graph

Ideas for improvements to git log --graph

I will maybe someday get around to dusting off my C and making these changes myself unless someone else does it first.

Make the graph for --topo-order less wiggly

Imagine a long-running development branch periodically merges from master. The git log --graph --all --topo-order is not as simple as it could be, as of git version 1.7.10.4.

It doesn't seem like a big deal in this example, but when you're trying to follow the history trails in ASCII and you've got several different branches displayed at once, it gets difficult quickly.