Skip to content

Instantly share code, notes, and snippets.

View olejorgenb's full-sized avatar

Ole Jørgen Brønner olejorgenb

View GitHub Profile
@olejorgenb
olejorgenb / nix-defexpr.zsh
Created June 25, 2016 00:46
nix-env "default nix expression" / "active nix expression" / top-level
_nix_build_defexpr () {
local -a result
local -a queue=($1)
setopt local_options null_glob
while [[ ${#queue} > 0 ]]; do
local current=$queue[1]
shift queue
if [[ -e $current/default.nix ]]; then
result+=($current)
else
@olejorgenb
olejorgenb / propagatedPython.nix
Created August 12, 2016 00:15
Find python packages that are likely to fail when used through "nix-shell -p"
with builtins;
let
# evaluate expr, returning default on error
tryDefault = expr: default:
let res = (tryEval expr);
in if res.success then res.value else default;
isPython = pkg: pkg?name && (parseDrvName pkg.name).name == "python";
hasPropagatedPython = pkg:
@olejorgenb
olejorgenb / main.js
Created November 25, 2016 07:30
Simple webextension to include the show/movie title in the netflix tab title
function expectOne(array) {
if(array.length === 1)
return array[0];
else
throw new Error("Expected one element, got " + array.length);
}
function findMediaTitle() {
var bag = expectOne(document.getElementsByClassName("playback-longpause-container"));
@olejorgenb
olejorgenb / render_giza_alignments.py
Last active November 25, 2016 07:43
Messy code that renders GIZA+ word alignments to latex
#!/usr/bin/env python3
# Requires the following preamble:
preamle = r"""
\usepackage{rotating} %% rotated column labels
\usepackage{colortbl} %% Colored cells
\usepackage{hhline} %% Borders that play nice with colortbl
\definecolor{lightgray}{gray}{0.8}
"""
@olejorgenb
olejorgenb / snippet.el
Created November 26, 2016 22:04
Highlight symbol at point on mouse click (emacs)
;; Only tested with spacemacs
(defvar my-current-focus-symbol nil)
(make-variable-buffer-local 'my-current-focus-symbol)
(defvar my-focus-symbol-face 'hi-yellow)
(defun mouse-set-point-and-hl-symbol (event)
(interactive "e")
(mouse-set-point event)
;; Evil workaround crap (without this every other click visual state is activated...)
@olejorgenb
olejorgenb / configure-thinkpad-pointer.zsh
Created December 24, 2016 15:34
Thinkpad trackpoint configuration
#!/usr/bin/env zsh
#
### Thinkpad x220 config
xinput disable "SynPS/2 Synaptics TouchPad"
# Doc: https://www.x.org/wiki/Development/Documentation/PointerAcceleration/
TP="TPPS/2 IBM TrackPoint"
@olejorgenb
olejorgenb / nix-shell-env.el
Last active January 30, 2017 23:09
Misc code for using emacsclient with nix-shell
(defun nix-shell-c-system-header-paths ()
"Extract header search paths from the NIX_CFLAGS_COMPILE env variable"
(cl-labels ((every-other (li &optional pick)
(when li
(if pick
(cons (car li) (every-other (cdr li)))
(every-other (cdr li) (not pick))))
))
(let* ((cflags (getenv "NIX_CFLAGS_COMPILE")))
@olejorgenb
olejorgenb / pnix-shell.sh
Last active September 13, 2018 07:16 — forked from aherrmann/pnix-shell.sh
Fully persistent Nix shell
#!/usr/bin/env bash
# This is free and unencumbered software released into the public domain.
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
@olejorgenb
olejorgenb / nix-package-search
Last active July 4, 2022 15:22
nix-package-search
@olejorgenb
olejorgenb / merge-repo-to-subdir.sh
Created July 16, 2017 04:41 — forked from andsens/merge-repo-to-subdir.sh
Merges a repo into a subdirectory of another repo (useful when making a submodule part of a parent repo)
#!/bin/bash -e
function merge_repo_to_subdir {
local url=$1
local commit=$2
local module_path=$3
if [[ -z $url || -z $commit || -z $module_path ]]; then
echo "Usage: merge-repo-to-subdir.sh URL BRANCH PATH" >&2
exit 1