Skip to content

Instantly share code, notes, and snippets.

function sitegen
cd /home/public
rm *.html
cd /home/public/posts
set posts (ls)
ser webdir /home/public
set header $webdir/conf/header.html
set footer $webdir/conf/footer.html
for post in $posts
if test (echo $post | sed "s/.*\.//") = md
@wdkrnls
wdkrnls / startrekreg.py
Created December 28, 2010 10:13
Practice with regular expressions
pattern = """
\b # new word boundary
NCC # Match NCC
( ?-? ?) # Match '-'
([0-9][0-9]+) # Match registry number
( ?-? ?) # Match optional '-'
([A-Z]?) # Match optional suffix
\b # end word boundary
"""
@wdkrnls
wdkrnls / org-syntax-cheatsheet.org
Created March 7, 2012 03:54
Org-mode Syntax Cheat sheet

Markup Cheat sheet for Org-mode

Heading 1

Heading 2: Set a deadline and a schedule

[66%] Heading 3: a list with checkboxes

  1. [X] task 1
  2. [X] task 2
  3. [ ] task 3
#lang racket
(provide
(contract-out
[make-coinage (-> (listof positive-integer?) list?)]))
(define (positive-integer? x)
(and (positive? x)
(integer? x)))
@wdkrnls
wdkrnls / .conkerorrc
Created November 9, 2014 01:09
load_paths.unshift("chrome://conkeror-contrib/content/"); // require("mode-line-buttons.js"); // mode_line_add_buttons(standard_mode_line_buttons, true); define_webjump("codesearch", "http://www.google.com/codesearch?q=%s"); define_webjump("cpan", "http://search.cpan.org/search?query=%s&mode=all"); define_webjump("imdb", "http://imdb.com/find?q=%s
require("clicks-in-new-buffer.js");
require("page-modes/google-search-results.js");
require("page-modes/wikipedia.js");
require("session.js");
require("block-content-focus-change.js");
require("favicon");
require("content-policy.js");
require("index-webjump.js");
xkcd_add_title = true;
#' Clever chunking algorithm into roughly equal parts
#' http://stackoverflow.com/questions/2130016/splitting-a-list-of-arbitrary-size-into-only-roughly-n-equal-parts
chunk <- function(x, k) {
n <- length(x)
q <- n %/% k
r <- n %% k
lapply(seq.int(1, k), function(i) {
x[seq(from = (i - 1)*q + min(i - 1, r) + 1, to = i * q + min(i, r))]
})
}
#' My function for doing cross validation (creating the splits before hand)
xvalidate <- function(f, formula, data, bin, ...) {
fold <- length(bin)
xs <- seq.int(1, fold)
lapply(xs, function(x) {
train <- data[unlist(bin[-x]),]
test <- data[bin[[x]],]
model <- f(formula, data = train, ...)
@wdkrnls
wdkrnls / on_circle
Last active January 17, 2017 03:50
on_circle_iter <- function(theta) {
if(theta < 2*pi) theta else on_circle(theta - 2*pi)
}
on_circle <- function(theta) Vectorize(on_circle_iter, SIMPLIFY = FALSE)
all(on_circle(pi*seq(0, 8, by = 2) == 0)
# all.equal does a lot, nearly_equal does little.
nearly_equal <- function(x, y, tol = sqrt(.Machine$double.eps)) y < x + tol & y > x - tol
# syntax can be confusing to beginners
which_is <- function(x, test) x[which(test)]
x <- seq(0, 2*pi, by = 0.01)
library(magrittr)
x %>% which_is(nearly_equal(sin(x), 0.5, tol = 0.005))
#!/usr/bin/env racket
#lang racket/base
(require racket/vector)
;; Capture the command line args sent to this script
(define args
(current-command-line-arguments))