Skip to content

Instantly share code, notes, and snippets.

@luisgerhorst
luisgerhorst / linux-ebpf-overview-tikz.tex
Created August 28, 2024 07:36
Overview of eBPF: Bytecode -> Verifier -> JIT -> Execution
# License: CC BY-SA 4.0 (Creative Commons Attribution-ShareAlike 4.0 International), Copyright 2024 Luis Gerhorst
\usepackage{tikz}
\usetikzlibrary{arrows, calc, positioning, patterns}
\usepackage{marvosym}
\usepackage{xcolor}
\definecolor{nBlue}{RGB}{144, 167, 198}
\definecolor{nLightBlue}{RGB}{221, 229, 240}
@luisgerhorst
luisgerhorst / rdio_api_access_tokens.erl
Last active August 29, 2015 14:20
Generate Rdio access tokens for a user with Erlang oauth lib.
-define(CONSUMER, {"APPLICATION_KEY", "APPLICATION_SHARED_SECRET", hmac_sha1}).
-define(REQUEST_TOKEN_URL, "http://api.rdio.com/oauth/request_token").
-define(ACCESS_TOKEN_URL, "http://api.rdio.com/oauth/access_token").
access_tokens() ->
application:start(crypto),
application:start(inets),
{ok, RequestTokenResponse} = oauth:post(?REQUEST_TOKEN_URL, [{"oauth_callback", "oob"}], ?CONSUMER),
RequestTokenParams = oauth:params_decode(RequestTokenResponse),
RequestToken = oauth:token(RequestTokenParams),
@luisgerhorst
luisgerhorst / README.md
Last active August 29, 2015 14:15
Emacs: Make paredit work with erlang-mode (or any other non-lisp mode)

When you want to use awesome paredit with erlang-mode or any other non-lisp language there's a problem when you want to insert a pair of parenthesis for a function call.

Say you have typed myFunction and now type (, paredit assumes you're in a lisp and creates myFunction () instead of myFunction().

The snippet prevents paredit from inserting a space before parentheses by locally resetting the predicate functions used to determine if a space should be inserted before a pair of parentheses. By changing the hook used you could also make this work in any other mode for non-lisp languages. For exampe for js2-mode replace erlang-mode-hook in line 1 with js2-mode-hook.

@luisgerhorst
luisgerhorst / ido-find-file-in-finder-dir.el
Created January 20, 2015 17:11
Emacs: Find file in directory currently open in OS X Finder.
;; ido-find-file-in-dir but start in directory currently open in Finder.
(defun ido-find-file-in-finder-dir ()
(interactive)
(let ((finder-dir (do-applescript "tell application \"Finder\"\nreturn POSIX path of (target of window 1 as alias)\nend tell")))
(ido-find-file-in-dir finder-dir)))
;; Bind to C-x C-o
(global-set-key (kbd "C-x C-o") 'ido-find-file-in-finder-dir)
@luisgerhorst
luisgerhorst / graphics-compared.md
Created December 3, 2014 19:16
Xbench results of iMac 5K from late 2014 base model and iMac 21.5" from mid 2011 compared

Format

Test Name 		Xbench Score		Measured Values

Apple iMac "Core i5" 2.5 21.5-Inch (Mid-2011)

Base configuration (AMD Radeon HD 6750M 512MB). Full specs at Everymac.

@luisgerhorst
luisgerhorst / bookmarklet.js
Last active August 29, 2015 14:01
Pinboard bookmarklet to automatically open Pushpin app on iOS and regular popup on Mac.
javascript:if(/(iPad|iPhone|iPod)/g.test(navigator.userAgent)){window.location="pushpin://x-callback-url/add?url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title)}else{q=location.href;if(document.getSelection){d=document.getSelection()}else{d=""}p=document.title;void open("https://pinboard.in/add?url="+encodeURIComponent(q)+"&description="+encodeURIComponent(d)+"&title="+encodeURIComponent(p),"Pinboard","toolbar=no,width=700,height=350")}
@luisgerhorst
luisgerhorst / game.hs
Created May 2, 2014 20:09
2048 in Haskell
import Data.List
import System.Random
import System.Environment
import Control.Parallel.Strategies
-- run with "./game TREEDEPTH" and it outputs a game tree of a specific depth
-- see below for more specific functions
main = do
[depthString] <- getArgs
@luisgerhorst
luisgerhorst / dijkstra.hs
Created April 21, 2014 20:21
Improved dijkstra algorithm in Haskell.
{-
Command-line: ./dijkstra graph.txt startNode endNode
Haskell: dijkstra startNode endNode aGraph
Works with any directed edge-weighted graph.
Graph File Structure:
Node ConnectedNode DistanceToConnectedNode ConnectedNode DistanceToConnectedNode ...
@luisgerhorst
luisgerhorst / dijkstra.hs
Created April 13, 2014 22:18
Dijkstra algorithm in Haskell.
type Node = String
type Length = Int
type Path = [Node]
data Way = Way Path | Visited | Unknown
type Ways = [(Node, Way)]
type Connection = (Node, Length)
type Connections = [Connection]
@luisgerhorst
luisgerhorst / 2048.clj
Created March 30, 2014 18:10
2048 in Clojure
(def grid (insert [[nil nil nil nil]
[nil nil nil nil]
[nil nil nil nil]
[nil nil nil nil]]))
;; Grid functions.
(defn move
"Moves all field to the choosen direction, merges fields and inserts field value for random free location. Returns nil if game is over. Returns same grid if move doesn't change the grid."
[grid direction]