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
def realgroupby(it, key): | |
from itertools import groupby, chain | |
d = {} | |
for k, ii in groupby(it, key): | |
if k in d: | |
d[k] = chain(d[k], list(ii)) | |
else: | |
d[k] = list(ii) | |
return d |
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
", ".join(["%s: %s" % (k,v) for k,v in filter(lambda k,v: v, some_hash.items())]) |
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
def make_flatten(fl_types=None): | |
if fl_types is None: | |
fl_types = (list, tuple) | |
def flatten(x): | |
for i in x: | |
if isinstance(i, fl_types): | |
for a in flatten(i): | |
yield a | |
else: |
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
""" from range(1, 18) with 3 rows and 4 columns it's create like this: | |
4 columns | |
############# | |
1 4 7 10 # | |
2 5 8 11 # 3 rows | |
3 6 9 12 # | |
13 16 | |
14 17 | |
15 | |
""" |
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
(defn factors-sorted-by-product [start end] | |
(map rest (let [r (reverse (range start end))] | |
(reverse (sort-by first (for [x r y r :when (>= x y)] | |
(list (* x y) x y) | |
) | |
)) | |
) | |
)) | |
(defn get-diff-factors [vals] |
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 '(java.lang Math)) | |
(defn palindrome? [n] | |
(= (->> n str reverse (apply str)) | |
(str n))) | |
(defn test-for-products [n pmax pmin] | |
(some #(let [p (/ n %)] | |
(and (<= p pmax) (>= p pmin))) | |
(for [i (range pmin (inc pmax)) :let [m (mod n i)] :when (= m 0)] i))) |
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
POSTGRESQL_VERSION="9.2.1" | |
# Installing DB (one-time) | |
cd $OPENSHIFT_DATA_DIR | |
wget http://ftp.postgresql.org/pub/source/v${POSTGRESQL_VERSION}/postgresql-${POSTGRESQL_VERSION}.tar.gz | |
tar xf postgresql-${POSTGRESQL_VERSION}.tar.gz | |
rm postgresql-${POSTGRESQL_VERSION}.tar.gz |
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
# put into lib/arel_back.rb | |
module ArelBack | |
module ActiveRecord | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods |
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
(ns find-pin) | |
(defn ^String to-pin | |
[^Integer x] | |
(let [v (str x)] | |
(.concat (apply str (repeat (- 4 (count v)) 0)) v))) | |
(defn ^java.lang.Boolean valid-pin? | |
[^String v] | |
(and |
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
git log --shortstat --since "5 months ago" | gawk 'BEGIN { | |
printf "\n%-10s %-10s %-10s %-10s %-40s %-5%%s\n", "total", "insert", | |
"deleted", "changed f", "author", ""; | |
total_changed=0; | |
total_insert=0; | |
total_del=0 | |
} | |
$1 ~ /^Author:/ { | |
cur_author=substr($0, index($0,$2)) | |
} |
OlderNewer