Skip to content

Instantly share code, notes, and snippets.

View kotarot's full-sized avatar

Kotaro Terada kotarot

View GitHub Profile
@kotarot
kotarot / wcadb_example.php
Created December 7, 2014 16:24
For my blog article.
<?php
// Definitions by the user.
define('MYSQL_HOST', 'localhost');
define('MYSQL_USER', '********');
define('MYSQL_PASS', '********');
define('MYSQL_DB', '********');
// DB connection without error handlings.
$link = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS);
@kotarot
kotarot / wca_my_record.php
Created March 8, 2015 08:49
Getting personal records from WCA database. This file is for my blog article at: http://www.terabo.net/blog/practical-wcadb/
<?php
// DB connection
try {
$pdo = new PDO(
'mysql:dbname=xxxx;host=localhost;charset=utf8',
'xxxx',
'xxxxxxxx',
$options = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
@kotarot
kotarot / MyFirstGist.txt
Last active October 9, 2015 02:58
This is my first gist.
This
This is
This is my
This is my first
This is my first gist.
This is very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long line.
@kotarot
kotarot / count_tree_nodes_1.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/
#!/usr/bin/env python
"""
This scripts counts number of nodes
in 3x3x3 search tree (1)
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/
#!/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)
@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/
#!/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 / wca_importer.php
Last active June 21, 2016 02:49
A simple automatic WCA database importer. ** Newer version: https://github.com/kotarot/wca-importer ** This file is for my blog article at: http://www.terabo.net/blog/import-wcadb-automatically/
<?php
define('WCA_EXPORT_DIR', 'https://www.worldcubeassociation.org/results/misc/');
define('WCA_EXPORT_HTML', 'export.html');
define('MYSQL_HOST', 'localhost');
define('MYSQL_USER', '********');
define('MYSQL_PASS', '********');
define('MYSQL_DB', '********');
@kotarot
kotarot / wca-regulations-finder-dom-test.html
Last active September 22, 2019 07:42
WCA Regulations Finder DOM test
<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 / birthday.c
Last active August 13, 2020 11:39
birthday.c -- for lecture
#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) {
# 長方形詰め込み
class TwoDimPackingClass:
"""
2次元パッキング問題
ギロチンカットで元板からアイテムを切り出す(近似解法)
入力
width, height: 元板の大きさ
items: アイテムの(横,縦)のリスト
出力
容積率と入ったアイテムの(id,横,縦,x,y)のリスト