Skip to content

Instantly share code, notes, and snippets.

@naoyat
naoyat / cout.h
Created June 21, 2013 11:16
this header enables to feed { vector, list, deque, map, set, pair } variables to std::cout
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
@naoyat
naoyat / topcoder-template.cc
Created June 20, 2013 11:26
TopCoder Arena用コードテンプレート
#line $NEXTLINENUMBER$ "$FILENAME$"
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
@naoyat
naoyat / b2.cc
Last active December 17, 2015 06:19
Problem B #Round1C
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define repN(var,n) for(int var=1;var<=(n);var++)
@naoyat
naoyat / gist:4612899
Last active December 11, 2015 14:18
(asahi.comで)'PrImage'クラスのエレメントを非表示にしたい時に使う即席ブックマークレット。
javascript:Array.prototype.slice.call(document.getElementsByClassName('PrImage'),0).forEach(function(element,index,array){element.style.display='none';});
@naoyat
naoyat / buggy.scm
Last active December 10, 2015 01:58
[Gauche] 途中で xmin の値が変更されてしまう。mx, my の演算に有理数を使うとこの問題が発生しない所まで確認。(0.9.2, 0.9.3.3)
(define xmin 0)
(define xmax 0)
(define ymin 0)
(define ymax 0)
(define (f x0 y0 x1 y1 depth)
(when (>= depth 0)
(when (< x0 xmin) (set! xmin x0))
(when (< x1 xmin) (set! xmin x1))
(when (< xmax x0) (set! xmax x0))
@naoyat
naoyat / euler.scm
Last active December 9, 2015 22:39
Project EulerにGaucheで挑戦する話 ref: http://qiita.com/items/7c7bd54747676e3f1fb1
(use srfi-1)
(use util.combinations)
(use gauche.uvector)
(define pi 3.141592653589793238462643383279)
(define phi (/ (+ 1 (sqrt 5)) 2))
(define *log2* (log 2))
(define *log10* (log 10))
@naoyat
naoyat / base⠼⠋⠙.py
Created December 13, 2012 19:24
use braille patterns for base64, instead of alphanumerics. joke.
#!/usr/bin/env python
#coding:utf-8
import sys
def base64_encode_(in_data, padding=False):
in_len = len(in_data)
out_data = []
for i in range(0, in_len, 3):
out_data.append(in_data[i] >> 2)
@naoyat
naoyat / dvi-js-example.html
Last active October 13, 2015 21:58
An example of using dvi.js
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>dvi.js demo</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="http://naoyat.github.com/dvi.js/dvi.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://naoyat.github.com/dvi.js/texfonts.min.css"></style>
</head>
<body onload="dvi_load({out:'#out',file:'sample.dvi'});">
<div id="out"></div>
@naoyat
naoyat / mh1.matlab
Created December 1, 2012 14:24
Metropolis-Hastingsアルゴリズム ref: http://qiita.com/items/b9aa110b395d0a5b0b0a
1;
%
% 図11.9 Metropolisアルゴリズムを用いて2次元ガウス分布からサンプリングする例。
%
function plot_gauss2_contour(mu, Sigma)
cont = zeros(2,101);
D = chol(Sigma, "lower");
for j = 1:100
theta = pi*2/100 * (j-1);
@naoyat
naoyat / file0.txt
Created November 29, 2012 10:21
TeX記法ちょっと練習 ref: http://qiita.com/items/29e1fddf566a80a78525
1;
%
% コーシー分布 Cauthy distribution のpdf
%
function p = CauthyDistributionPDF(y)
p = arrayfun(@(x) 1.0/(pi*(1+x^2)), y);
endfunction
%
% コーシー分布に従う乱数