Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View yaraki's full-sized avatar
🏠
Working from home

Yuichi Araki yaraki

🏠
Working from home
  • Google, Inc.
  • Tokyo
View GitHub Profile
@yaraki
yaraki / montyhall.go
Created April 27, 2014 04:09
Monty Hall Problem
package main
import (
"fmt"
"math/rand"
)
const doors = 3
const trials = 10000
const seed = 15
@yaraki
yaraki / DialogDemoActivity.java
Created April 27, 2014 13:03
How to create a dialog using DialogFragment and AlertDialog.
package yaraki.dialogdemo.app;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
@yaraki
yaraki / portals.csv
Created May 9, 2014 09:51
Sample POIs
35.6611302 139.7286663 ハートランド
35.6615196 139.7295036 メトロハット
35.6623 139.729618 サイゼ
35.6608595 139.728279 マクドナルド
36.951095 140.853685 いわきCC
36.951344 140.854934 泉神社
36.9526041 140.8543881 郵便局
36.950052 140.852266 幼稚園
38.259210 140.893322 NAViS
38.431639 141.309444 石巻道場
@yaraki
yaraki / lexer.cpp
Last active August 29, 2015 14:01
S-expression lexer in C++11
#include <iostream>
#include <sstream>
namespace ya {
void each_token(std::istream& input, void (*proc)(const std::string& token))
{
std::stringstream buffer;
auto send = [&buffer, &proc]() {
if (0 < buffer.tellp()) {
@yaraki
yaraki / minitest.cpp
Last active August 29, 2015 14:11
Minimal testing
// clang++ -o minitest minitest.cpp -std=c++1y -stdlib=libc++
#include <iostream>
#define TEST_PREDICATE(expr, oper) \
do { \
auto expr__ = (expr); \
if (!(expr__ oper)) { \
std::cout << __FILE__ << ":" << __LINE__ << " " \
<< "FAILED " << #expr << " " << #oper \
package com.arakitech.kotlisp
import java.util.HashMap
fun StringBuilder.clear() {
this.setLength(0)
}
class Tokenizer(val input: String) {
private var position = 0
@yaraki
yaraki / channel.cpp
Created February 17, 2015 15:11
Go-style channel in C++
#include <iostream>
#include <list>
#include <thread>
namespace ya {
template<class item_t>
class channel {
private:
@yaraki
yaraki / simple-sine.el
Created July 7, 2015 08:22
Simple sine calculation by taylor expansion
(defconst if3 (* 2 3))
(defconst if5 (* if3 4 5))
(defconst if7 (* if5 6 7))
(defconst if9 (* if7 8 9))
(defconst if11 (* if9 10 11))
(defun simple-sine (x)
(unless (eq 'float (type-of x))
(setf x (float x)))
(let* ((x2 (* x x))
@yaraki
yaraki / forth.lisp
Created September 12, 2015 13:28
Toy forth implementation in Common Lisp
(in-package :cl-user)
(defpackage forth
(:use :cl)
(:export :run
:clear
:create-context))
(in-package :forth)
(defstruct context
(dictionary (make-hash-table :test 'equal))
@yaraki
yaraki / andr
Last active December 22, 2015 01:39
A simple Ruby script for preparing resized drawable images for multiple DPIs on Android.
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
#
# Copyright (C) 2013 Yuichi Araki
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0