Skip to content

Instantly share code, notes, and snippets.

View crowding's full-sized avatar

Peter Meilstrup crowding

View GitHub Profile
@crowding
crowding / gist:3184404
Created July 26, 2012 20:46
The ruler function
#include <math.h>
#include <stdio.h>
/* The ruler function corresponds to the number of ones at the end of the
* binary representation of numbers. */
int main(void) {
int i;
for (i = 1; i < 1000; i++) {
printf("%g ", log2( (i ^ (i-1)) + 1));
@crowding
crowding / README.md
Created August 2, 2012 03:18
bash arrays, removing one path component at a time

I had a problem with chmod not working. It seemed to be related to something in my path. I spent more time on this script to test removing individual path components than I would have done brute forcing it. And it didn't tell me the problem, as it was related to at least two path entries.

However, this script does demonstrate something or other about working with arrays in Bash. Mostly it demonstrates how awkward the exercise is.

@crowding
crowding / .gitignore
Created August 9, 2012 07:41
Periodic productivity reminder.
idler
*.elc
@crowding
crowding / gitolite_setup.md
Created August 22, 2012 06:43
Setting up gitolite on your server account without root or a special 'git' user

Setting up gitolite on your server account without root or a special 'git' user

gitolite is a tool for managing multi-user access to Git respoitories. Here's how I set them up on a shared server on which I don't have root access.

Prerequisites.

I'll presume you've played around a bit with Git repositories on your local machine. My favorite introduction is

@crowding
crowding / remote-emacs.sh
Created August 25, 2012 03:02 — forked from akheron/remote-emacs.sh
Use emacsclient for editing remote files by setting this script as EDITOR in the remote machine
#!/bin/sh
#
# Use this script as your EDITOR to allow editing remote files with emacsclient.
# Works by connecting to the Emacs machine with SSH and using a suitable tramp prefix.
# How to reach this machine from the one that's running Emacs
ME=user@remote-host
# How to reach the machine that's running Emacs from this machine
THEY=user@host-running-emacs
@crowding
crowding / migration.sh
Created August 26, 2012 09:05
Extract a list of SVN URLs to Git repos
#!/bin/bash -ex
#little script to migrate an SVN URL into a Git repo
#I have already prepared the list of FROM and TO, to be run with
#
#xargs -L 1 < migration.txt ./migration.sh
#
#I have made sure that the repos already exist and are empty, or else
#will be auto-created by Gitolite.
FROM=$1
@crowding
crowding / .bash_profile
Created September 10, 2012 21:56
Bash prompt for ADD types
#put this in your ~/.bash_profile
#
#If a long-running command terminates, ring the bell and float the
#(OSX Terminal) window.
LONG_RUNNING=20 #how long is long? Enough for me to get bored and tab away.
function popup_if_long {
last_command_time=$(HISTTIMEFORMAT="%s " history 1 | awk '{print $2}')
if (( $(date -u +"%s") - $last_command_time > $LONG_RUNNING ))
@crowding
crowding / extract.sh
Created September 20, 2012 06:18
Extracting a number of subdirectories into submodules
#!/bin/bash
set -v verbose
trap exit ERR
#I want to extract a number of submodules from a larger project.
#Also to preserve untracked files (e.g. lengthy data build products)
CWD=`pwd`
REPO_DIR="direction_discrimination_analysis"
SUBMODULES="mothballed_writing previous_draft newer_draft"
@crowding
crowding / unicode_ggplot2.R
Created October 23, 2012 09:32
Using Unicode plot symbols in ggplot2
#negative numbers for "symbol" will be interpreted as Unicode values.
#But you must use a fint that supprots the symbols you want.
dataset <- chain(1:16, expand.grid(x=., y=.), mutate(shape=seq_along(x)))
print(ggplot(dataset) + aes(x=x, y=y, shape=factor(shape))
+ geom_point()
+ discrete_scale("shape", "manual", name="shape", palette=function(x) -seq(0x25A0L, length=x))
+ theme(legend.position="none")
)
@crowding
crowding / flymake-r.el
Created October 31, 2012 04:58
Flymake support for R code
;; R flymake support (if Flymake is available) This will call a script
;; "rflymake" with the path given; make sure it is on emac's exec-path
;; or give a full path.
(when (require 'flymake nil)
(defun flymake-r-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))