Skip to content

Instantly share code, notes, and snippets.

View potix2's full-sized avatar
:octocat:

Katsunori Kanda potix2

:octocat:
View GitHub Profile
@potix2
potix2 / gist:1126865
Created August 5, 2011 03:32
screenrc
vbell off
autodetach on
startup_message off
defscrollback 1000
term xterm-256color
escape ^La
defbce on
hardstatus alwayslastline "[%02c] %`%-w%{=b bw}%n %t%{-}%+w"
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
export PATH="/usr/local/bin:$PATH"
#export PS1='\033k\033\\[\u@\h \W]\$ '
@potix2
potix2 / .zshrc
Created August 19, 2011 02:17
zshrc
autoload colors
colors
setopt auto_pushd
setopt noautoremoveslash
bindkey -e
autoload -U compinit
compinit
PROMPT='%39<...<%/%% '
PROMPT2="%_%% "
SPROMPT="%r is correct? [n,y,a,e]: "
@potix2
potix2 / gist:1218324
Created September 15, 2011 01:50
HSV to RGB
public function toRGB(h:Number, s:Number, v:Number):uint {
var hi:Number = Math.floor(h / 60) % 6;
var f:Number = h / 60 - hi;
var p:Number = v * ( 1.0 - s);
var q:Number = v * ( 1.0 - f * s);
var t:Number = v * ( 1.0 - (1.0 - f) * s);
var r:Number;
var g:Number;
var b:Number;
switch(hi) {
@potix2
potix2 / gist:1223873
Created September 17, 2011 12:00
Sudoku Solver (easy level)
function complete(data) {
var result = true;
var sum;
for ( var i = 0; i < 9; i++ ) {
sum = 0;
for ( var j = 0; j < 9; j++ ) {
sum += data[i * 9 + j];
}
if ( sum != 45 ) {
@potix2
potix2 / gist:1223935
Created September 17, 2011 13:29
numofbits
int numofbits5(long bits) {
bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}
@potix2
potix2 / gist:1257161
Created October 2, 2011 06:55
Sudoku Solver
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8" />
<title>Sudoku Solver</title>
<style type="text/css">
#content-table {
border: solid 1px #ccc;
border-collapse: collapse;
empty-cells: show;
@potix2
potix2 / gist:1265057
Created October 5, 2011 17:17
reversi assist
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Reversi Assistant</title>
<style type="text/css">
#content-table {
border: solid 1px #ccc;
border-collapse: collapse;
empty-cells: show;
@potix2
potix2 / gist:1274819
Created October 10, 2011 07:49
totient
//http://mathworld.wolfram.com/TotientFunction.html
//use (13) and (14)
int totient(int n) {
int ret = 1;
for ( int i = 2; n != 1; i++ ) {
if ( n % i == 0 ) {
int pow = 1;
while ( n % i == 0 ) {
n = n / i;
pow *= i;
@potix2
potix2 / gist:1275609
Created October 10, 2011 15:31
modpow
//a^b mod m
long long modpow(long long a, long long b, long long m) {
long long ret = 1;
long long mul = a;
for ( ; b > 0; b = b >> 1) {
if ( b&1 ) {
ret = (ret * mul) % m;
}
mul = (mul * mul) % m;
}