This file contains hidden or 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
# use this code to run any django script with django environment | |
import settings | |
from django.core.management import setup_environ | |
setup_environ(settings) | |
http://www.b-list.org/weblog/2007/sep/22/standalone-django-scripts/ |
This file contains hidden or 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
Repeating commands | |
This package defines a command that repeats the preceding command, whatever that was, including its arguments, whatever they were. This command is connected to the key C-x z. To repeat the previous command once, type C-x z. To repeat it a second time immediately after, type just z. By typing z again and again, you can repeat the command over and over. | |
http://stackoverflow.com/questions/6156286/emacs-lisp-call-function-with-prefix-argument-programmatically | |
Repeat Yank command | |
C-a C-k C-x ( C-y C-j C-x ) C-u 9 C-x e |
This file contains hidden or 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
#Command to list matching files in 2 folders. | |
find unittests -name *.java | xargs -L1 basename $1 | -xargs find ../../../Applications/iTrust/unittests/edu/ncsu/csc/itrust/ -name $1 |
This file contains hidden or 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
for i in `ls`; do x=`echo $i | sed "s/doku.php.*s:uc\([1-9]*\).*/uc\1/g"`; mv $i $x.txt ; done; |
This file contains hidden or 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
for i in `ls uc*`;do `sed -i .bckp -e '/textarea/,/textarea/!d' $i` ; done; |
This file contains hidden or 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
tr -cs 'A-Za-z0-9' '\n' < allwords.txt | sort | uniq -c | sort -n |
This file contains hidden or 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
;; Counting Coins | |
;; problem from "Coding for Interviews" news letter. | |
;; notes: switching to vector from raw list gave a tremendous performance boost | |
;; uses memoize as variant of Y-combinator. | |
(let | |
[coins (map read-string (clojure.string/split (read-line) #",")) | |
amt (read-string (read-line)) | |
change3 (fn [rec amt coins] | |
(cond |
This file contains hidden or 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
;;Computes all possible paths through a graph (DAG) | |
;;assumes the graph is a DAG | |
;; Clojure | |
(defn all-paths [g] | |
(let [walk (fn walk [g seen n] | |
(cond | |
(empty? (g n)) seen | |
:else (mapcat (fn [m] | |
(walk g (conj seen m) m)) (g n))))] |
This file contains hidden or 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
;;visit all nodes using reduce | |
;;clojure | |
;;store nodes in visited order. | |
(defn visit [g] | |
(let [walk (fn walk [g seen n] | |
(reduce (fn [seen, m] | |
(cond | |
(seen m) seen | |
:else (walk g (conj seen m) m) )) seen (g n)) |
This file contains hidden or 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
// does a product on two lists | |
h = [ 1: "a", 2:"b", 3:"c"] | |
j = [ 1: ["x", "p"], 2: ["z"], 3:["y"]] | |
h.entrySet().inject([]) { acc, h1 -> | |
acc + j.get(h1.key).inject([]) { acc1, it-> acc1 << [h1.value, it]} } |
OlderNewer