Skip to content

Instantly share code, notes, and snippets.

View kogai's full-sized avatar
👁️
Watching you

Shinichi Kogai kogai

👁️
Watching you
View GitHub Profile
const script = document.createElement('script');
script.type = 'text/javascript';
script.innerHTML = 'throw new Error("テスト")';
document.body.appendChild(script);
const assert = require('assert');
const deepEqual = assert.deepEqual;
const isFizz = x => x % 3 === 0;
const isBuzz = x => x % 5 === 0;
const isFizzBuzz = x => isFizz(x) && isBuzz(x);
const match = x => {
if (isFizzBuzz(x)) return 'FizzBuzz';
#![feature(no_std)]
#![feature(conservative_impl_trait)]
pub trait Foo {
fn get_foo(&self) -> i32;
}
struct ImplFoo(i32);
impl Foo for ImplFoo {
fn main() {
let foo = "bar"; // 変数束縛(≠ 代入 関数型言語の束縛とも違う)
let foo_1: i32 = 100; // 静的型付け
// 関数宣言
fn bar(x: i32) -> i32 {
x + 100 // ブロックの最後の行がreturnされる
}
pub fn use_after_move() {
let v = vec![1, 2, 3];
let v2 = v;
println!("{:?}", v);
}
pub fn use_after_copy() {
let v = 0;
let v2 = v;
println!("{:?}", v2);
@kogai
kogai / some_dynamic_trait.rs
Last active May 12, 2017 05:53
RUSTFLAGS="--emit asm" cargo build
// #![no_std]
pub trait Foo {
fn sum(&self, x: i32, y: i32) -> i32;
}
struct FooInstance;
impl Foo for FooInstance {
fn sum(&self, x: i32, y: i32) -> i32 {
@kogai
kogai / some_trait.rs
Last active May 12, 2017 05:53
RUSTFLAGS="--emit asm" cargo build
#![no_std]
pub trait Foo {
fn sum(&self, x: i32, y: i32) -> i32;
}
struct FooInstance;
impl Foo for FooInstance {
fn sum(&self, x: i32, y: i32) -> i32 {
@kogai
kogai / file1.txt
Created April 29, 2017 07:36
the description for this gist
String file contents
// @flow
type FlowFn<T> = (x: T) => T;
const pipe = <T>(...fns: FlowFn<T>[]) => (seed: T): T => fns.reduce((acc, fn) => fn(acc), seed);
const multiply = (x: number) => x * 2;
const piped = pipe(
multiply,
multiply,
import { CurriedFunction2 } from 'ramda';
declare module 'ramda-fantasy' {
declare interface IFuture<E, A> {
fork(reject: (v: E) => void, resolve: (v: A) => void): void;
ap(f: any): any;
map<A2>(fb: (e: A) => A2): IFuture<E, A2>;
bimap<E2, A2>(errFn: (value: E) => E2, successFn: (value: A) => A2): IFuture<E2, A2>;
chain<A2>(fn: (v: A) => IFuture<E, A2>): IFuture<E, A2>;
chainReject<A2>(fn: (value: E) => IFuture<E, A2>): IFuture<E, A2>;