Skip to content

Instantly share code, notes, and snippets.

cohama cohama

Block or report user

Report or block cohama

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View cps2.rs
fn main() {
repeat_cps(10, "hello", Box::new(|r| {
println!("{:?}", r)
}))
}
fn repeat_cps<'a, A, B>(n: i32, x: A, k: Box<Fn(A) -> B + 'a>) -> B
{
if n == 0 {
k(x)
View takewhile.rs
fn main() {
println!("{:?}", take_while(&[1, 2, 3, 4, 5], |&x| x < 3));
}
fn take_while<T, F>(xs: &[T], f: F) -> &[T]
where F: Fn(&T) -> bool
{
let mut i = 0;
while f(&xs[i]) {
i += 1;
View treebuilder.js
/* eslint no-console: "off", no-unused-vars: "off" */
var xs = [
{id: 'A', pid: '', name: 'aaa'},
{id: 'B', pid: '', name: 'bbb'},
{id: 'C', pid: '', name: 'ccc'},
{id: 'A-a', pid: 'A', name: 'aaa-aaa'},
{id: 'A-b', pid: 'A', name: 'aaa-bbb'},
{id: 'B-a', pid: 'B', name: 'bbb-aaa'},
{id: 'B-b', pid: 'B', name: 'bbb-bbb'},
{id: 'C-a', pid: 'C', name: 'ccc-aaa'},
View genericDivide.hs
{-# LANGUAGE FlexibleInstances, UndecidableInstances #-}
import Data.Ratio
class (Num a) => Dividable a where
divide :: a -> a -> a
instance {-# INCOHERENT #-} (Integral a) => Dividable a where
divide = div
instance Dividable Double where
View IrrefutablePatterns.hs
fn :: [String] -> Int -> String
fn ~(h:t) n = if n == 0
then "oops."
else h ++ ":" ++ show t
main :: IO ()
main = putStrLn $ fn [] 0
View lambda.js
"use strict"
const ZERO = f => x => x
const ONE = f => x => f(x)
const TWO = f => x => f(f(x))
const THREE = f => x => f(f(f(x)))
const FOUR = f => x => f(f(f(f(x))))
const FIVE = f => x => f(f(f(f(f(x)))))
const SUCC = n => f => x => n(f)(f(x))
View twettermonad.md

Twitter クライアントを作る

準備

git clone git://github.com/cohama/twittermonad
cd twittermonad
cabal sandbox init
cabal install --only-dependencies
cabal configure
View t.rb
describe "hoge" do
let (:hoge) {1}
it "first" do
expect(1).to eq hoge
end
describe "child" do
View t.js
var assert = require('assert');
describe('hoge', function() {
beforeEach(function() {
this.foo = 1;
this.bar = 5;
THIS = this;
});
it('first', function() {
View gist:98b1eeaedc0f3cd636a2
let g:Maybe = {"v": []}
function! g:MaybeReturn(v)
let maybe = deepcopy(g:Maybe)
let maybe.v = [a:v]
return maybe
endfunction
function! Just(x)
return MaybeReturn(a:x)
You can’t perform that action at this time.