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 / dijkstra.rb
Created February 3, 2012 13:58
Dijkstra Shortest Path Algorithm in Ruby
#!/usr/bin/ruby1.9.1 -Kw
# -*- coding: utf-8 -*-
class Edge
attr_accessor :src, :dst, :length
def initialize(src, dst, length = 1)
@src = src
@dst = dst
@length = length
@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
@yaraki
yaraki / mrex.py
Created December 21, 2013 16:59
Simplest MonkeyRunner script that keeps on tapping the specified position every second
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
device = MonkeyRunner.waitForConnection()
while 1:
device.touch(540, 1560, MonkeyDevice.DOWN_AND_UP)
MonkeyRunner.sleep(1.0)
@yaraki
yaraki / pi.go
Created January 21, 2014 12:22
Ramanujan's formulas of pi in Go
package main
import (
"fmt"
"math"
)
func fact(n float64) float64 {
r := float64(1)
for 1 < n {
@yaraki
yaraki / pi.lisp
Created January 22, 2014 14:08
Ramanujan's formulas of pi in Common Lisp
(defun fact (n)
(let ((r 1))
(loop
for i from 2 to n
do (setf r (* i r))
finally (return r))))
(defun calc-pi-1 (max)
(/ 1
(* (/ (* 2 (sqrt 2.0d0)) (expt 99 2))
@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 / simplefind.c
Created July 3, 2014 13:26
Lists up all the subdirectories in the current directory recursively.
#include <stdio.h>
#include <string.h>
#include <dirent.h>
void list(const char *path)
{
DIR *dir;
struct dirent *entry;
char entry_path[PATH_MAX];
char *entry_name = entry_path;