Skip to content

Instantly share code, notes, and snippets.

(System.Reflection.Assembly/LoadWithPartialName "System.Xml.Linq")
(ns linq.xml
(:import [System.Xml.Linq XDocument XElement XAttribute XNode])
(:import [System.IO MemoryStream StreamReader])
(:import [System.Text Encoding])
(:gen-class))
(defmacro ^:private local-name [node]
`(.. ~node Name LocalName))
#lang racket
(provide mycompose1
mycompose)
(define-syntax mycompose1
(syntax-rules ()
((_) values)
((_ f1 f2 ...)
(lambda arglist (mycompose1$ arglist f1 f2 ...)))))
@mnzk
mnzk / spnz.js
Last active August 29, 2015 14:14
// spinoza for Nashorn shell (jjs)
// original code => https://github.com/kenokabe/spinoza
// [usage example]
//
// > jjs
// jjs> load("spnz.js")
// ===== spinoza =====
// jjs> world = $(1)(2)(3)(out)
// world-> 1,2,3
@mnzk
mnzk / racket-class-generic.rkt
Created January 29, 2015 15:59
send と send-generic
#lang racket
(define sprite<%> (interface () draw))
(define draw (generic sprite<%> draw))
(define pix%
(class* object% (sprite<%>)
(super-new)
(define/public (draw)
'pix-draw)))
@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;