Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#define N 9
#define B 3 //square root of N
int canBePlaced(int board[], int pos, int x)
{
int row=pos/N;
int col=pos%N;
int i, j, topLeft;
@taroyabuki
taroyabuki / clustering_test_data.csv
Created February 10, 2013 10:45
MathematicaのAgglomerateのバグ http://blog.unfindable.net/archives/5504 MathematicaのAgglomerateのバグ http://blog.unfindable.net/archives/5556
0 0 0 0 0 0 7 0 0 0 0 0
2 2 0 0 0 0 0 0 0 0 2 4
0 0 10 0 0 0 0 0 0 0 0 0
0 0 0 0 5 0 0 0 0 0 0 0
0 0 0 0 0 0 2 0 0 0 4 0
0 0 0 0 0 0 0 0 3 0 0 0
0 0 6 0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 0 2 0
0 0 0 0 0 3 0 0 0 0 0 0
9 0 0 0 0 0 0 0 0 0 0 0
@taroyabuki
taroyabuki / bug_in_findclusters.m
Last active December 12, 2015 09:09
Bug in FindClusters of Mathematica 8.0.4, 9.0.0, and 9.0.1.
data = Import["https://gist.github.com/taroyabuki/4749183/raw/ffc84dbc4a3499ddef4a8c4f689b56c2948225bd/clustering_test_data.csv"];
(* This returns no result *)
FindClusters[data, DistanceFunction -> CosineDistance,
Method -> {"Agglomerate", "Linkage" -> "Complete"}]
(* Shuffled data can be clustered. *)
FindClusters[RandomSample@data, DistanceFunction -> CosineDistance,
Method -> {"Agglomerate", "Linkage" -> "Complete"}]
install.packages("RCurl")
install.packages("lsa")
library(RCurl)
url <- getURL("https://gist.github.com/taroyabuki/4749183/raw/ffc84dbc4a3499ddef4a8c4f689b56c2948225bd/clustering_test_data.csv", ssl.verifypeer = F)
data <- read.csv(textConnection(url), header = F)
library(lsa)
d <- dist(1 - cosine(t(as.matrix(data))))
hr <- hclust(d, method = "complete")
samples <- data.frame(
x = c(3, 7, 10),
y = c(7, 1, 8),
row.names = c("A", "B", "C"))
plot(samples, type = "n")
text(samples[,1], samples[,2], row.names(samples))
d <- dist(samples)
@taroyabuki
taroyabuki / bug_in_agglomerate.m
Last active December 13, 2015 23:59
Bug in Agglomerate of Mathematica 8.0.4 and 9.0.1.
Needs["HierarchicalClustering`"]
data = Import["https://gist.github.com/taroyabuki/4749183/raw/ffc84dbc4a3499ddef4a8c4f689b56c2948225bd/clustering_test_data.csv"];
clusters = Agglomerate[data, DistanceFunction -> CosineDistance, Linkage -> "Complete"];
On[Assert];
Assert[Length@ClusterFlatten@clusters == Length@data]
{Length@ClusterFlatten@clusters, Length@data}
@taroyabuki
taroyabuki / clustering_test_data2.csv
Created February 20, 2013 14:54
MathematicaのClusteringComponentsの困ったところ http://blog.unfindable.net/archives/7727
0.07832604499879574 0. 0. 0. 0.2170723815877265 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.6432675209026769 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0.5601120336112039 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.20965696734438366 0.24253562503633297
0. 0. 0.5312532024908597 0.23791547571544325 0. 0. 0. 0. 0. 0. 0. 0.
0. 0.15961737689352443 0. 0.15861031714362883 0. 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0.5360562674188974 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. 0. 0.42008402520840293 0. 0. 0.
0. 0. 0. 0.4758309514308865 0. 0. 0. 0. 0. 0. 0. 0.
0.15665208999759148 0.15961737689352443 0. 0. 0. 0. 0. 0. 0. 0. 0.20965696734438366 0.48507125007266594
<?php
session_start();
$oauth = new OAuth($_SESSION['consumer_key'], $_SESSION['consumer_secret'], OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
if (substr(PHP_OS, 0, 3) == 'WIN') {
$caPath = 'C:/xampp/perl/vendor/lib/Mozilla/CA/';
$caInfo = "${caPath}cacert.pem";
$oauth->setCAPath($caPath, $caInfo);
}
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Twitter OAuth Post</title>
</head>
<body>
<?php
session_start();
<?php
session_start();
session_destroy();
?>
<!doctype html>
<html>
<head>
<title>Logout</title>
</head>
<body>