Skip to content

Instantly share code, notes, and snippets.

;; after list-buffers is called, switch to it
(defadvice list-buffers (after jc-switch-to-other-win)
(if (not (equalp (buffer-name (current-buffer))
"*Buffer List*"))
(other-window 1))
(goto-char (+ 4 (point))))
;; emacs24 doesn't recognize Buffer-menu-sort-column so we do this
;; nonsense: after list-buffers is called and we've switched to it,
;; check whether the buffer matches what's stored in
import codecs
import subprocess
import sys
teststr = u'This is a block character: \u2588'
#### try #1: reproduce the problem
# demonstration of http://bugs.python.org/issue6135
# rbx -Xprofile -Xprofiler.graph -Xprofiler.full_report read_csv.rb
Finished in 50.60307312011719s, at rate of 195.04744260435427 rows/sec
===== Thread 1 =====
Total running time: 50.874820736000004s
index % time self children called name
----------------------------------------------------------
[1] 100.0 0.00 50.87 1 Rubinius::Loader#script [1]
0.00 50.87 1 Rubinius::CodeLoader.load_script [2]
-------------------------------------------------------
0.00 50.87 1 Rubinius::Loader#script [1]
@codeforkjeff
codeforkjeff / sicp-2.5.lisp
Created April 14, 2012 15:49
Exercise 2.5 from SICP, in Common Lisp
;; Exercise 2.5 from SICP, in Common Lisp
(defun x-cons (a b)
(labels ((x-power (x n &optional acc)
(let ((acc (or acc x)))
(if (= n 1)
acc
(x-power x (- n 1) (* acc x))))))
(* (x-power 2 a) (x-power 3 b))))
@codeforkjeff
codeforkjeff / fizzbuzz.lisp
Created April 21, 2012 14:17
fizzbuzz in Common Lisp
;; Discovered via http://www.adampetersen.se/articles/fizzbuzz.htm
;; “Write a program that prints the numbers from 1 to 100. But for
;; multiples of three print “Fizz” instead of the number and for the
;; multiples of five print “Buzz”. For numbers which are multiples of
;; both three and five print “FizzBuzz”.”
(defun is-mult-p (n multiple)
(= (rem n multiple) 0))
(defun fizzbuzz (&optional n)
@codeforkjeff
codeforkjeff / intersect.py
Created December 3, 2012 19:01
Comparison of performance of python lists and sets
# Compare the performance of python lists and sets when doing
# intersections.
#
# No real surprises here. Sets are faster than lists, and generating
# sets on-the-fly from lists is slightly slower than using sets to
# begin with.
import timeit
import random
(defun mask-ssn (num)
(save-match-data
(concat "XXX-XX-" (nth 2 (split-string num "-")))))
(replace-regexp-in-string "[0-9]\\{3\\}-[0-9]\\{2\\}-[0-9]\\{4\\}"
'mask-ssn
"Here's a number: 999-22-1111. Here's another: 222-11-9999.")
;; evaluates to "Here's a number: XXX-XX-1111. Here's another: XXX-XX-9999."
;; Hooray!
(defun mask-ssn (num)
(concat "XXX-XX-" (substring num 7)))
(replace-regexp-in-string "[0-9]\\{3\\}-[0-9]\\{2\\}-[0-9]\\{4\\}"
'mask-ssn
"Here's a number: 999-22-1111. Here's another: 222-11-9999.")
;; evaluates to "Here's a number: XXX-XX-1111. Here's another: XXX-XX-9999."
(defun mask-ssn (num)
(concat "XXX-XX-" (nth 2 (split-string num "-"))))
(replace-regexp-in-string "[0-9]\\{3\\}-[0-9]\\{2\\}-[0-9]\\{4\\}"
'mask-ssn
"Here's a number: 999-22-1111. Here's another: 222-11-9999.")
;; evaluates to "Here's a number: 999-22XXX-XX-11111111. Here's another: 222-11XXX-XX-99999999."
(defun my-replace (regex rep str &optional start)
"Replace matches of regex in str with the result of applying
rep function to the match.
This exists because of a quirk in replace-regexp-in-string:
because it calls the REP function in a while loop that uses
string-match and replace-match, the REP function can't use
string-match without messing up the match state in the loop.
If rep returns nil, an empty string is used as the