Skip to content

Instantly share code, notes, and snippets.

Avatar

Kotaro Terada kotarot

View GitHub Profile
View beam_window.py
import apache_beam as beam
from apache_beam.testing.test_stream import TestStream
from apache_beam.transforms.userstate import CombiningValueStateSpec
from apache_beam.transforms.window import TimestampedValue
# Stateful DoFn, based on:
# - https://beam.apache.org/blog/stateful-processing/
# - https://github.com/apache/beam/blob/30f9a607509940f78459e4fba847617399780246/sdks/python/apache_beam/transforms/userstate_test.py
class IndexAssigningStatefulDoFn(beam.DoFn):
View graph_cut.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View traveling_salesperson_problem.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View JMA_Tokyo_202010.csv
index datetime Pressure Sea-Level Pressure Precipitation Temperature Relative Humidity Sunlight Hours Day/Night
0 2020-10-01 00:10:00 1006.5 1009.3 19.6 82 Night
1 2020-10-01 00:20:00 1006.6 1009.4 19.5 82 Night
2 2020-10-01 00:30:00 1006.7 1009.5 19.6 81 Night
3 2020-10-01 00:40:00 1006.9 1009.7 19.6 82 Night
4 2020-10-01 00:50:00 1006.9 1009.7 19.7 82 Night
5 2020-10-01 01:00:00 1007.1 1009.9 19.5 83 Night
6 2020-10-01 01:10:00 1007.0 1009.8 19.5 83 Night
7 2020-10-01 01:20:00 1006.7 1009.5 19.2 84 Night
8 2020-10-01 01:30:00 1006.7 1009.5 19.2 84 Night
View TwoDimPackingClass.py
# 長方形詰め込み
class TwoDimPackingClass:
"""
2次元パッキング問題
ギロチンカットで元板からアイテムを切り出す(近似解法)
入力
width, height: 元板の大きさ
items: アイテムの(横,縦)のリスト
出力
容積率と入ったアイテムの(id,横,縦,x,y)のリスト
@kotarot
kotarot / birthday.c
Last active August 13, 2020 11:39
birthday.c -- for lecture
View birthday.c
#include <stdio.h>
#include <stdlib.h>
// Returns 1 if the given date exists, 0 if not.
// Ref: Leap year https://ja.wikipedia.org/wiki/%E9%96%8F%E5%B9%B4
int is_correct_day(int y, int m, int d) {
if (m == 2) {
if (d > 29) { // d = 30,31 is incorrect
return 0;
} else if (d == 29) {
@kotarot
kotarot / wca-regulations-finder-dom-test.html
Last active September 22, 2019 07:42
WCA Regulations Finder DOM test
View wca-regulations-finder-dom-test.html
<body>
<p>A1</p>
<p>A1 foo foo foo foo</p>
<p>A1 foo foo foo foo <span>bar bar</span></p>
<div>A1 foo foo foo foo <a>A2 bar bar</a></div>
</body>
@kotarot
kotarot / count_tree_nodes_3.py
Last active October 15, 2015 07:07
For my blog article "Fewest moves vs God's number" http://www.terabo.net/blog/fmc-vs-gods-number/
View count_tree_nodes_3.py
#!/usr/bin/env python
"""
This scripts counts number of nodes
in 3x3x3 search tree (3)
http://www.terabo.net/blog/fmc-vs-gods-number/
"""
ALL_POS = 43252003274489856000
print 'All possible positions: {0:,d}'.format(ALL_POS)
@kotarot
kotarot / count_tree_nodes_2.py
Last active October 15, 2015 07:07
For my blog article "Fewest moves vs God's number" http://www.terabo.net/blog/fmc-vs-gods-number/
View count_tree_nodes_2.py
#!/usr/bin/env python
"""
This scripts counts number of nodes
in 3x3x3 search tree (2)
http://www.terabo.net/blog/fmc-vs-gods-number/
"""
ALL_POS = 43252003274489856000
print 'All possible positions: {0:,d}'.format(ALL_POS)