Skip to content

Instantly share code, notes, and snippets.

@haxney
haxney / lib.rs
Last active December 25, 2015 01:19
extern mod extra;
use extra::future::Future;
use std::num;
/**
* Speculatively execute consumer using the guessed value.
*/
pub fn spec<A: Eq + Send, B>(producer: ~fn() -> A,
predictor: ~fn() -> A,
@haxney
haxney / main.rs
Last active December 24, 2015 00:49
Benchmark giving result of zero seconds.
extern mod cssparser;
extern mod extra;
extern mod servo_style;
use std::io::file_reader;
use std::cell::Cell;
use std::task;
use cssparser::*;
use extra::time::precise_time_ns;
@haxney
haxney / systems.el
Created November 18, 2012 05:17
Better than "Understanding OOP"
(defvar systems '((usg-unix-v "UNIX" "good")
;; `string-equal' converts symbols to string automagically
((lambda (sys) (string-equal "gnu/linux" sys)) "UNIX" "good")
("^windows" "Windows" "bad")
(darwin "Mac OS" "far superior")))
(defun assoc-match (key alist)
"Return non-nil if KEY matches the `car' of an element of ALIST.
The `car' of each element of ALIST can be a:
@haxney
haxney / haxney.zsh-theme
Created September 30, 2012 01:43
My zsh theme (for now)
# Adapted from rkj
PROMPT=$'%{\e[0;34m%}%B┌─[%b%{\e[0m%}%{\e[1;32m%}%n%{\e[1;30m%}@%{\e[0m%}%{\e[0;36m%}%m%{\e[0;34m%}%B]%b%{\e[0m%} - %b%{\e[0;34m%}%B[%b%{\e[1;37m%}%~%{\e[0;34m%}%B]%b%{\e[0m%}
%{\e[0;34m%}%B└─%B[%{\e[1;35m%}%(!.#.$)%{\e[0;34m%}%B]%{\e[0m%}%b '
@haxney
haxney / manual-name.sh
Created September 29, 2012 20:21
Test gist.el language replacement
# Comment while saved under plain-text mode.
# Made entirely from within the web interface
# Commit 2. Edited from within Emacs
# Commit 3. Made from web interface, setting language to shell
# Commit 4. Now another edit in emacs. Only added this line of text and saved.
@haxney
haxney / geiser-package.sh
Created September 28, 2012 06:16
Turn Geiser into an ELPA package
#!/bin/bash
# This program 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, or (at
# your option) any later version.
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
@haxney
haxney / FunctionDefinitions.R
Created August 8, 2012 20:14
Hack xcms to read from a database
##' Select spectra based on the path of their associated raw file.
RAW_FILE_NAME_QUERY_TEMPLATE <- 'SELECT raw_file_path,
run_index, spectra.start_time, array_length, mz_array, intensity_array,
polarity, total_ion_current, lowest_observed_mz, highest_observed_mz
FROM runs LEFT JOIN spectra ON spectra.run_id = runs.id
WHERE runs.raw_file_path = \'%s\' AND ms_level = %d
%s /* Will be filled with TIME_RANGE_QUERY_TEMPLATE */
ORDER BY spectra.start_time ASC'
@haxney
haxney / ComplicatedDispatch.R
Created August 2, 2012 20:12
Dispatching on generic methods in R
## Reverse the order of the arguments.
foo <- function(iterVar, quux) {
UseMethod("foo", object=quux)
}
## Need to be reversed in the implementation as well
foo.myClass <- function(iterVar, quux) {
## `paste()` combines its arguments into a single string.
paste("within foo.myClass. quux:", quux, "iterVar:", iterVar)
}
@haxney
haxney / ChromatoGen.R
Created July 20, 2012 14:24
Testing speed improvement in R
#!/usr/bin/env Rscript
##' Generate a Selected Ion Chromatogram (SIC) from a run in a database.
##'
##' Retrieves spectra from a MySQL database and generates an SIC using the
##' specified parameters. Database connection information *must* be passed in
##' using the following environment variables:
##'
##' - MZDB_HOST: Computer on which the database is running.
##' - MZDB_USER: Username for authentication.
@haxney
haxney / gist:3055728
Last active February 19, 2023 18:45
List monospace fonts in Emacs
;; Display all the monospace fonts available to Emacs in a dedicated buffer
(defun font-is-mono-p (font-family)
;; with-selected-window
(let ((wind (selected-window))
m-width l-width)
(with-temp-buffer
(set-window-buffer (selected-window) (current-buffer))
(text-scale-set 4)
(insert (propertize "l l l l l" 'face `((:family ,font-family))))