Skip to content

Instantly share code, notes, and snippets.

View houshuang's full-sized avatar

Stian Håklev houshuang

View GitHub Profile
@houshuang
houshuang / convert-tags.rb
Created January 27, 2014 15:43
Converting multi-line YAML tags to single-line for Hakyll
def transform(txt)
tags = txt.match(/tags:(.+?)---/m)[1].strip
taglines = tags.gsub("- ", "").split("\n")
txt.sub((/tags:(.+?)---/m), "tags: " + taglines.join(", ")+ "\n---")
end
Dir.glob("*.md").each do |f|
puts f
txt = File.read(f)
File.open(f, "w") {|f2| f2 << transform(txt)}
(defun org-skim-open (my-path)
(interactive)
(shell-command (concat "open " skim-pdf-path "/" (car (split-string my-path "#")) ".pdf"))
(skim-page-absolute (string-to-number (cdr (split-string my-path "#")))))
nth 1 (split-string my-path "#")))))
;;; -*- lexical-binding: t -*-
(setq skim-pdf-path "~/Bibdesk")
(org-add-link-type "bib" 'org-skim-open)
(defun skim-page (&optional offset)
(interactive)
(when (not offset) (setq offset 1))
(do-applescript (format "
tell document 1 of application \"Skim\" to set a to index of current page
(setq skim-pdf-path "~/Bibdesk")
(org-add-link-type "bib" 'org-skim-open)
(defun skim-page (&optional offset)
(interactive)
(when (not offset) (setq offset 1))
(do-applescript (format "
tell document 1 of application \"Skim\" to set a to index of current page
tell document 1 of application \"Skim\" to go to page (a + %d)
a" offset)))
@houshuang
houshuang / crit.hs
Created April 30, 2014 01:41
Experiment with benchmarking
import Criterion.Main
import qualified School as S
import qualified School2 as S2
list = [(1, ["Peter", "John", "Niels", "Adam", "Kris", "Pringle", "Bonus"])
,(2, ["Arun", "Gambas", "Pierre", "Donau", "Arielle", "Jonathan"])]
--addMany :: (Int -> String -> School -> School) -> School -> [(Int, [String])] -> School
addMany fn = foldr addgrade
where
import re
def getcase(l):
return(re.search(r"Case: (.+?),", l).groups()[0])
def splitcase(c):
return(c.split("-20"))
with open("/Users/Stian/Downloads/ExportedCases-20140508_share.csv") as f:
@houshuang
houshuang / Short-lambda
Last active August 29, 2015 14:02
Making lambdas much more dense through some ugly string manipulation + eval
fn <- function(x) {
if(class(x) == "function") return(x) else {
print(class(x))
# escape percentage marks within strings
x = gsub("'(.+)?%([1-9]?)(.+)?'","'\\1^^^\\2\\3'", x)
# if a single word, call one argument, otherwise analyze arguments
if(grepl("^[a-zA-Z.]*$", x)) { x = paste0(x,"(x1)")} else {
x = gsub("%([^1-9])", "%1\\1", x)
x = gsub("'", "\"", x)
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
---
output: html_document
---
# Report on first NAP survey
```{r echo=FALSE, message=FALSE, results='asis', prompt=FALSE}
library(knitr)
opts_chunk$set(echo=F, warning=F,message=F,results="asis", prompt=F, error=F)
setwd("/Users/Stian/Dropbox/NAP/Survey")
library(ggplot2)