Skip to content

Instantly share code, notes, and snippets.

View tnoda's full-sized avatar

Takahiro Noda tnoda

View GitHub Profile
@tnoda
tnoda / sense-region.el
Last active June 24, 2021 19:58
sense-region.el
;;; sense-region.el --- minor mode to toggle region and rectangle.
;;; $Id: sense-region.el,v 1.9 2002/10/16 13:47:14 komatsu Exp $
;;;
;;; AUTHOR: Hiroyuki KOMATSU <komatsu@taiyaki.org>
;;; LICENSE: GPL2
;;; ORIGINAL-SOURCE: http://www.taiyaki.org/elisp/sense-region/ (in Japanese)
;;; Version: 1.9.0
;;;
;;; ------------------------------------------------------------
@tnoda
tnoda / union_find.py
Created June 24, 2014 08:34
Union-Find in Python
class UnionFind:
"""Weighted quick-union with path compression.
The original Java implementation is introduced at
https://www.cs.princeton.edu/~rs/AlgsDS07/01UnionFind.pdf
>>> uf = UnionFind(10)
>>> for (p, q) in [(3, 4), (4, 9), (8, 0), (2, 3), (5, 6), (5, 9),
... (7, 3), (4, 8), (6, 1)]:
... uf.union(p, q)
@tnoda
tnoda / e-stat_cities.csv
Created December 7, 2020 13:47
e-Stat から市区町村データをダウンロードして整形したときの記録
city_code prefecture city pop age working_age_pop daytime_pop
1100 北海道 札幌市 1952356 46.4 1235516 1959740
1202 北海道 函館市 265979 52.7 152154 273408
1203 北海道 小樽市 121924 56.5 65317 124293
1204 北海道 旭川市 339605 51.9 191423 341732
1205 北海道 室蘭市 88564 52.5 49005 96865
1206 北海道 釧路市 174742 51.4 101909 175733
1207 北海道 帯広市 169327 47.6 103890 175954
1208 北海道 北見市 121226 50.9 70781 121080
1209 北海道 夕張市 8843 64.4 4045 9104
@tnoda
tnoda / jp_cities_with_code.csv
Created December 7, 2020 12:59
日本の市区町村の標準地域コードの一覧が雑に欲しい
city_code prefecture city
1000 北海道 北海道
1100 北海道 札幌市
1101 北海道 中央区
1102 北海道 北区
1103 北海道 東区
1104 北海道 白石区
1105 北海道 豊平区
1106 北海道 南区
1107 北海道 西区
Coursera
coursera.com *
_ 1st-party script
_ cloudfront.net *
@tnoda
tnoda / naive-primes.clj
Created July 1, 2012 14:51
Sieve of Eratosthenes in Clojure
(defn prime? [n]
(every? #(pos? (rem n %)) (range 2 (Math/sqrt (inc n)))))
(defn naive-primes [n]
(filter prime? (range 2 (inc n))))
@tnoda
tnoda / problem_5.clj
Created December 11, 2012 14:50
Project Euler Problem 5 #mitori_clj
(ns tnoda.projecteuler.problem-5
(:import org.apache.commons.math.util.MathUtils) ; [org.apache.commons/commons-math "2.2"]
(:use clojure.test))
(defn- solver*
[n]
(reduce (fn [^long x ^long y] (MathUtils/lcm x y)) (range 1 (inc n))))
(def solver (partial solver* 20))
@tnoda
tnoda / admiral.clj
Last active December 27, 2015 20:29
Translating the `break` statement into Clojure.
(let [m (BattleMap. "Ironbottom Sound")
f (Fleet. "Center Fleet")]
(loop []
(doto f .repair .supply)
(when (and (.isFullyRepaired f)
(.isFullySupplied f)
(>= (.morale f) 40))
(.attack f m)
(if (-> m .gauges pos?)
(recur))))
(defun shibayu36/chomp (str)
(replace-regexp-in-string "[\n\r]+$" "" str))
(defun anything-git-project-project-dir ()
(shibayu36/chomp
(shell-command-to-string "git rev-parse --show-toplevel")))
(defun anything-c-sources-git-project-for ()
(loop for elt in
'(("Modified files (%s)" . "--modified")
@tnoda
tnoda / DrillOne.scala
Created April 3, 2013 10:46
[再帰ドリル](https://github.com/kazu-yamamoto/recursion-drill) を Scala で書いてみる.
package recfun
object DrillOne {
// sum of arithmetic progression
def soap(x: Int): Int =
if (x == 0) 0
else soap(x - 1) + x
// factorial
def fact(x: Int): Int =