Skip to content

Instantly share code, notes, and snippets.

View nyuichi's full-sized avatar

Yuichi Nishiwaki nyuichi

View GitHub Profile
:- use_module(library(socket)).
write_atom(Stream,Atom) :-
atom_codes(Atom,Codes),
write_codes(Stream,Codes).
write_codes(_,[]) :- !.
write_codes(Stream,[Code|Tail]) :-
put_code(Stream,Code),
write_codes(Stream,Tail).
(*
OCaml translation of the ideas explained in http://fumieval.hatenablog.com/entry/2014/09/22/144401
To emulate the higher kinded polymorphism, the technique used explained in https://ocamllabs.github.io/higher/lightweight-higher-kinded-polymorphism.pdf
*)
module StateMonad = struct
type ('s, 'a) m = 's -> 's * 'a
@nyuichi
nyuichi / 1_.md
Created August 27, 2014 04:50 — forked from gakuzzzz/1_.md

Scala の省略ルール早覚え

このルールさえ押さえておけば、読んでいるコードが省略記法を使っていてもほぼ読めるようになります。

メソッド定義

def concatAsString(a: Int, b: Int): String = {
  val a_ = a.toString();
  val b_ = b.toString();

Reader Macros in Common Lisp

Reader macros are perhaps not as famous as ordinary macros. While macros are a great way to create your own DSL, reader macros provide even greater flexibility by allowing you to create entirely new syntax on top of Lisp.

Paul Graham explains them very well in [On Lisp][] (Chapter 17, Read-Macros):

The three big moments in a Lisp expression's life are read-time, compile-time, and runtime. Functions are in control at runtime. Macros give us a chance to perform transformations on programs at compile-time. ...read-macros... do their work at read-time.

Macros and read-macros see your program at different stages. Macros get hold of the program when it has already been parsed into Lisp objects by the reader, and read-macros operate on a program while it is still text. However, by invoking read on this text, a read-macro can, if it chooses, get parsed Lisp objects as well. Thus read-macros are at least as powerful as ordinary macros.

;;; twittering-stream.el --- Twitter stream extension.
;; Author: Masahiro Hayashi <mhayashi1120@gmail.com>
;; Keywords: twitter user stream
;; Emacs: GNU Emacs 22 or later
;; Version: 0.0.2
;; Package-Requires: ((json "1.2") (twittering-mode "2.0"))
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
@nyuichi
nyuichi / await.js
Created August 31, 2013 21:41 — forked from domenic/await.js
// Let `doAjax`, `fadeIn`, `fadeOut`, and `delay` be promise-returning functions.
// In all the following examples, `example` is meant to return a promise that is fulfilled when
// all operations are completed, or rejected if any of the steps fail.
// ES5
function example() {
return doAjax("data.json").then(function (data) {
document.getElementById("data").innerText = data;
// based on http://labs.cybozu.co.jp/blog/kazuho/archives/2007/05/coopthread.php
function get_all(urls) {
runnable(function (next) {
for (var i = 0; i < urls.length; i++) {
// build request
var xhr = new XMLHttpRequest();
xhr.open("get", urls[i], true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4)
next(xhr.responseText);