Skip to content

Instantly share code, notes, and snippets.

@pkkm
pkkm / main.c
Last active December 18, 2021 16:41
Criterion-like formatting of numbers
#define _POSIX_C_SOURCE 200809L // For strdup.
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h> // Remember to link with -lm.
#define ARRAY_LEN(array) (sizeof(array) / sizeof((array)[0]))
@pkkm
pkkm / competition.el
Created April 8, 2021 16:05
A simple minor mode for Google Code Jam and similar programming competitions
;;; A simple minor mode for programming competitions. -*- lexical-binding: t -*-
;; competition.el is free software: you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by the Free
;; Software Foundation, either version 3 of the License, or (at your option) any
;; later version.
;; Improvement ideas:
;;
;; * Add a keybinding that will prompt for a test name, e.g. `A-small', then
@pkkm
pkkm / git-ml.el
Created February 26, 2021 16:51
Asynchronous git modeline (rough prototype)
;;; Asynchronous detailed git modeline.
;; git-ml is free software: you can redistribute it and/or modify it under the
;; terms of the GNU General Public License as published by the Free Software
;; Foundation, either version 3 of the License, or (at your option) any later
;; version.
;; This is a rough sketch. Things to do before publishing it as a package:
;;
;; * Consider doing the checks per git directory instead of per buffer, then
@pkkm
pkkm / git-quick.py
Created November 23, 2019 04:48
Script for automatically committing, pushing and pulling with git
#!/usr/bin/env python3
# Shortcuts for quick-and-dirty Git usage. Useful when you need backups and sync but not a pretty history.
import argparse
import os
import subprocess
import sys
@pkkm
pkkm / analyze.R
Created April 16, 2018 21:37
Testing the reliability of various statistics in the Criterion library.
#!/usr/bin/env Rscript
library(ggplot2)
library(reshape2)
library(pander)
data <- read.csv("results/results.csv", check.names=FALSE)
# Reorder columns for readability.
col_order <- c("Least-squares slope", "Theil-Sen slope",
@pkkm
pkkm / pyqt_example.py
Created December 15, 2013 14:07
PyQt and matplotlib example.
#!/usr/bin/env python
import sys, random
from PyQt4 import QtGui, QtCore
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
class MplCanvas(FigureCanvas):
@pkkm
pkkm / package.el
Created August 29, 2013 15:26
Package init.
(package-initialize) ; Load package.el and all packages now. This normally happens after loading the init file.
(setq package-enable-at-startup nil) ; Don't load the packages the second time after the init file.
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("melpa" . "http://melpa.milkbox.net/packages/")))
;; To update installed packages, use M-x package-list-packages RET U x.
;; Or delete the elpa/ directory and launch Emacs for it to be recreated.
(defun package-ensure-installed (package)
@pkkm
pkkm / rename-this-buffer-and-file.el
Created August 29, 2013 11:41
Rename the current file and buffer.
(defun rename-this-buffer-and-file ()
"Renames the current buffer and the file it is visiting (after saving it)."
(interactive)
(save-buffer)
(let ((filename (buffer-file-name)))
(unless filename
(error "Not visiting a file"))
(unless (file-exists-p filename)
(error "File \"%s\" doesn't exist" filename))
(let ((new-name
@pkkm
pkkm / smartparens.el
Created July 25, 2013 13:05
My bindings for smartparens.
;;; Bindings.
(define-key sp-keymap (kbd "C-M-f") 'sp-forward-sexp)
(define-key sp-keymap (kbd "C-M-b") 'sp-backward-sexp)
(define-key sp-keymap (kbd "C-M-d") 'sp-down-sexp)
(define-key sp-keymap (kbd "C-M-a") 'sp-backward-down-sexp)
(define-key sp-keymap (kbd "C-S-a") 'sp-beginning-of-sexp)
(define-key sp-keymap (kbd "C-S-d") 'sp-end-of-sexp)
@pkkm
pkkm / vim-dvorak.el
Created May 12, 2013 11:56
Vim motions for the Dvorak keyboard.
;;; Remap basic motions to [htns] (for a Dvorak keyboard).
;;; Also remap some related keys.
(require 'conf/evil)
;; Left, down, up, right: [htns] (previously: [hjkl]).
(define-key evil-motion-state-map "h" 'evil-backward-char)
(define-key evil-motion-state-map "t" 'evil-next-line)
(define-key evil-motion-state-map "n" 'evil-previous-line)
(define-key evil-motion-state-map "s" 'evil-forward-char) (define-key evil-normal-state-map "s" nil)