Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# Create animated gif by rotating a GIF
ORIG=$1
i=100
for deg in `seq 0 30 330 | xargs`; do
i=`expr $i + 1`
convert ${ORIG} \( +clone -background none -rotate $deg \) -gravity center -compose Src -composite loading_$i.gif
done
@felixr
felixr / rtags.awk
Created July 31, 2012 19:34
Generate ctags for R scripts
function addtag(name, lnum, line, kind)
{
# Change all occurences of "/" to "\/" and "\" to "\\"
gsub(/\\/,"\\\\",line)
gsub(/\//,"\\/",line)
tag[name] = FILENAME "\t/^" line "$/;\"\t" kind "\tline:" lnum
}
@felixr
felixr / lwpr-rdyncall.r
Created May 12, 2013 21:06
Locally Weighted Projection Regression (LWPR) using rdyncall and the LWPR C library
library(rdyncall)
dynbind("lwpr", "
lwpr_init_model(*<LWPR_Model>iiZ)i;
lwpr_duplicate_mode(*<LWPR_Model>*<LWPR_Model>)i;
lwpr_set_init_alpha(*<LWPR_Model>d)i;
lwpr_set_init_D(*<LWPR_Model>*dd)i;
lwpr_set_init_D_diagonal(*<LWPR_Model>*d)i;
lwpr_set_init_D_spherical(*<LWPR_Model>d)i;
lwpr_update(*<LWPR_Model>*d*d*d*d)i;
@felixr
felixr / generate_search_index.js
Created December 10, 2020 17:10
Generate searchIndex entries for janet docset
function dtype(t) { return t=="function" ? "Function" : (t=="macro" ? "Macro": "Builtin");}
let s = "";
for (let b of document.querySelectorAll('.binding')) {
s += `INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ("${b.firstChild.id}","${dtype(b.children[1].innerText)}","api/index.html#${b.firstChild.id}");\n`;
}
s
@felixr
felixr / debug.janet
Last active December 19, 2020 18:59
Debug macro for janet
(defmacro dbg! [form]
(let [func (first form)
args (drop 1 form)]
(var accum @['do])
(var syms @[])
(each arg args
(let [sym (gensym)]
(array/push accum (tuple 'def sym arg))
(array/push syms [arg sym])))
(defn insertion-sort [arr left right]
(for i (+ left 1) (+ right 1)
(def temp (in arr i))
(var j (- i 1))
(while (and (>= j left) (> (in arr j) temp))
(set (arr (+ j 1)) (in arr j))
(-- j))
(set (arr (+ j 1)) temp))
arr)

Intro

This describes an adaptive, stable, natural mergesort, modestly called timsort (hey, I earned it ). It has supernatural performance on many kinds of partially ordered arrays (less than lg(N!) comparisons needed, and as few as N-1), yet as fast as Python's previous highly tuned samplesort hybrid on random arrays.

In a nutshell, the main routine marches over the array once, left to right, alternately identifying the next run, then merging it into the previous

@felixr
felixr / background.js
Last active January 1, 2021 16:15
Proof of concept chrome extension to listen to all tab events
function handleEvent(name, payload) {
fetch('http://localhost:8118/report?'+JSON.stringify({name, payload}));
}
chrome.tabs.onActivated.addListener(
(tabId, windowId) => handleEvent("activated", {tabId, windowId}));
chrome.tabs.onActiveChanged.addListener(
(tabId, selectInfo) => handleEvent("activeChanged", {tabId, selectInfo}));
@felixr
felixr / rm_lines.ksy
Created November 27, 2020 18:20
reMarkable lines format (v3 and v5)
meta:
id: remarkable_lines
file-extension: rm
endian: le
seq:
- id: header
type: header
- id: page
type: page
enums:
@felixr
felixr / janet_repos.md
Last active September 28, 2021 01:58
janet repos
URL Stars Created
http://github.com/ahungry/ahungry-janet 3 2020-05-29 02:54:07
http://github.com/ahungry/ahungry-janet-user 0 2020-05-29 04:28:45
http://github.com/ahungry/janet-code 8 2019-07-28 05:10:59
http://github.com/ahungry/janet-p99-map 1 2020-05-10 04:13:27
http://github.com/ahungry/janet-pobox 7 2020-05-27 04:36:08
http://github.com/ahungry/janet-xbuild 2 2020-05-28 14:17:09
http://github.com/ahungry/puny-gui 83 2020-04-24 02:52:59
http://github.com/ahungry/puny-server 1 2020-04-23 01:42:38