This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder