Skip to content

Instantly share code, notes, and snippets.

@mnzk
mnzk / uselambda.py
Created June 16, 2011 13:41
functional(?) randomPasswordGenerator
#see https://gist.github.com/1023982 (donotuse.py)
randomPasswordGenerator = (
lambda repeat, choice, partial, digits, letters:
partial(lambda map_join, n:
map_join(choice, repeat(digits+letters, n)),
lambda f, lis: ''.join(map(f, lis))))(
__import__('itertools').repeat,
__import__('random').choice,
__import__('functools').partial,
@mnzk
mnzk / gist:1250074
Created September 29, 2011 05:51
drop-start-same
(defn drop-start-same
[ss]
(->> (loop [ss ss]
(if (apply = (map first ss))
(recur (map rest ss))
ss))
(map (partial apply str))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@mnzk
mnzk / gist:1250574
Created September 29, 2011 11:34
Infinity sieve of Eratosthene. Ver.1
(defn- diff-seq
"Returns a lazy seq of numbers in s1 but not in s2.
Both of s1 and s2 must be increasing monotonically and infinite sequence."
[s1 s2]
(let [x1 (first s1), x2 (first s2)]
(cond
(= x1 x2) (recur (rest s1) (rest s2))
(> x1 x2) (recur s1 (drop-while (partial > x1) s2))
(< x1 x2) (let [[s1a s1b] (split-with (partial > x2) s1)]
(lazy-cat s1a (diff-seq s1b s2))))))
@mnzk
mnzk / gist:1255850
Created October 1, 2011 10:30
Infinity sieve of Eratosthenes . Ver.2
(defn- diff-seq
"Returns a lazy seq of numbers in s1 but not in s2.
Both of s1 and s2 must be increasing monotonically and infinite sequence."
[s1 s2]
(let [x1 (first s1), x2 (first s2)]
(cond
(= x1 x2) (recur (rest s1) (rest s2))
(> x1 x2) (recur s1 (drop-while (partial > x1) s2))
(< x1 x2) (let [[s1a s1b] (split-with (partial > x2) s1)]
(lazy-cat s1a (diff-seq s1b s2))))))
@mnzk
mnzk / gist:1277349
Created October 11, 2011 05:23
t-sql カラム説明表示
select
sys.tables.name as table_name,
sys.extended_properties.value as discription,
sys.columns.name as column_name,
sys.columns.*
from sys.columns
left outer join sys.tables on (sys.columns.object_id=sys.tables.object_id)
left outer join sys.extended_properties on (major_id=sys.columns.object_id and minor_id=sys.columns.column_id)
where sys.tables.name is not null
order by table_name, sys.columns.column_id
@mnzk
mnzk / gist:1290403
Created October 16, 2011 01:38
gimpxx で三項演算子が爆発した
// gmpxx : mpz_class で三項演算子が使えない(解決した)
#include <iostream>
#include <gmpxx.h>
// これなら OK
// mpz_class next_collatz(const mpz_class &n){
// if(n % 2 == 0){
// return n >> 1;
// }else{
// return n * 3 + 1;
@mnzk
mnzk / NtoA1.clj
Created October 25, 2011 14:39
Excel A1 Converter
(def alpha "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
(def alen (count alpha))
(defn freq-alpha [n]
(mapcat (partial repeat n) alpha))
(defn fun [[xss m]]
[(map cons (freq-alpha m) (cycle xss)), (* m alen)])
@mnzk
mnzk / NtoA1-2.clj
Created October 26, 2011 14:43
Excel A1 Converter 2
(defn N->A [n]
(let [za "0ABCDEFGHIJKLMNOPQRSTUVWXYZ"
alen (dec (count za))
iter (fn [[n xs]] [(int (/ n alen))
(cons (nth za (rem n alen)), xs)])]
(->> (iterate iter [n '()])
(drop-while (comp not zero? first))
first second
(apply str))))
@mnzk
mnzk / fs-mono.el
Created November 23, 2011 09:30
A Helper of fsharp-mode (v0.3) for Mono
;;; fs-mono.el --- A Helper of fsharp-mode (v0.3) for Mono
(require 'cl)
(add-to-list 'load-path "~/.emacs.d/site-lisp/fsharp-mode")
(add-to-list 'auto-mode-alist '("\\.fs[iylx]?$" . fsharp-mode))
(require 'fsharp)
(autoload 'run-fsharp "inf-fsharp" "Run an inferior F# process." t)
@mnzk
mnzk / euler18.fs
Created November 26, 2011 14:49
Project Euler 18
#light
type System.String with
member s.split (sep : char) = s.Split([|sep|]) |> Array.toList
let parseNumbersPyramid (s : string) =
[for x in (s.split '\n') -> x.Trim().split ' ' |> List.map int]
let greaters xs =
Seq.map2 max xs (List.tail xs)