Skip to content

Instantly share code, notes, and snippets.

open System
#r "System.ComponentModel.DataAnnotations"
open System.ComponentModel.DataAnnotations
open System.Collections.Generic
type Person() =
let mutable name = ""
let mutable phone = ""
let mutable age = 0
@masaedw
masaedw / gist:880742
Created March 22, 2011 03:52
Slice & Split
static class ExtentionMethods
{
/// <summary>
/// sequenceをn要素のリストに分割する。
/// sequenceの要素数がnで割り切れない場合は最後のリストの要素数はn個より少なくなる。
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="list"></param>
/// <param name="n"></param>
/// <returns></returns>
/// <summary>
/// コンテナのキー等で型の別名を定義したいときに使うクラス
/// </summary>
/// <typeparam name="T"></typeparam>
public class NewType<T> : IEquatable<NewType<T>>
{
/// <summary>
/// 生の値を取得します
/// </summary>
public T Value { get; private set; }
(require '[clojure.contrib.io :as io])
(defmacro with-out-string
[& body]
`(let [writer# (java.io.StringWriter.)]
(io/with-out-writer writer#
~@body)
(-> writer# .toString)))
;; 39
(fn [as bs] (mapcat list as bs))
;; 40
(fn interpose- [i l]
(let [[x & xs] l]
(if (nil? xs)
(list x)
(lazy-seq
(cons x
(cons i (interpose- i xs)))))))
趣旨
簡単なプログラムを通じて、
Clojureの基本的なライブラリを探訪しよう
www.4clojure.com
(= __ (.toUpperCase "hello world"))
=> "HELLO WORLD"
@masaedw
masaedw / gist:956407
Created May 5, 2011 02:12
xml->hiccup
(defn xml->hiccup [xml]
(cond
(string? xml) xml
(map? xml)
(let [{:keys [tag attrs content]} xml]
(-> [tag]
(#(if (nil? attrs) % (conj % attrs)))
(#(if (empty? content) % ((comp vec concat) % (map xml->hiccup content))))))
))
(defn my-encode-params
"Turn a map of parameters into a urlencoded string."
[params]
(letfn [(encode [s] (URLEncoder/encode (as-str s) "UTF-8"))]
(str-join "&"
(for [[k v] params]
(str (encode k) "=" (encode v))))))
(alter-var-root (var encode-params) (fn [_] my-encode-params))
@masaedw
masaedw / gist:966393
Created May 11, 2011 12:46
もともとインストールされてたgem
actionmailer (2.3.2)
actionpack (2.3.2)
activerecord (2.3.2)
activeresource (2.3.2)
activesupport (2.3.2)
hoe (2.0.0, 1.7.0)
hpricot (0.6.161)
mechanize (0.7.8)
rails (2.3.2)
rake (0.8.7)