Skip to content

Instantly share code, notes, and snippets.

import itertools
import re
org_str = '2ABACBDEDFDFDFDCBACDAFB2'
candidates = ['0', '3', '4', '5', '6', '7', '8', '9']
operators = ['+', '-', '*', '/', '=']
candidates.extend(operators)
simple_op_check = re.compile(r'[*+-/=][*+-/=0]')
@niyaton
niyaton / import_ss_from_vnc.sh
Last active December 15, 2015 03:58
VNCのスクリーンショットを変化があった時だけ作成するスクリプト.cronに仕込んで使う.
#!/bin/bash -
new_filename=`date +\%Y\%m\%d\%H\%M\%S`.jpg
old_filename=`ls *.jpg | tail -n 1`
old_md5=`md5sum $old_filename | cut -d ' ' -f 1`
DISPLAY=":1.0" import -w root $new_filename
new_md5=`md5sum $new_filename | cut -d ' ' -f 1`
if [ $old_md5 = $new_md5 ]; then
rm $new_filename
fi
@niyaton
niyaton / msdn_keys_converter.py
Last active December 15, 2015 09:58
MSDNの大量のプロダクトキーをどうにかするアレ
import sys
from lxml import etree
from itertools import count, izip
if len(sys.argv) < 2:
print 'Usage: %s filename' % ( sys.argv[0] )
exit()
doc = etree.parse(sys.argv[1])
@niyaton
niyaton / prime.cpp
Last active December 18, 2015 16:49
割とお手軽で高速な素数計算プログラムの決定版?
#include <stdio.h>
#define MAX 1000000
int is_prime(int n){
for(int i = 6; (i-1) * (i-1) <= n; i+=6){
if( n % (i-1) == 0 || n %(i+1) == 0)
return 0;
}
return 1;
}
@niyaton
niyaton / fizzbuzz.py
Created June 19, 2013 13:50
なんとなくFizzBuzz書いてみた.
def gen_fizz_buzz(n):
for i in xrange(1,n):
str = ""
if i % 3 == 0:
str += "Fizz"
if i % 5 == 0:
str += "Buzz"
yield str if str else i
for i in gen_fizz_buzz(100):
@niyaton
niyaton / rbenv_init.zsh
Created August 19, 2013 04:29
eval (rbenv init -) とか重いんですよ.
# Initialize rbenv.
# "eval rbenv init -" is much heavy. use cached script.
if [ -n "$(printenv TMUX)" ]; then
source $ZSHHOME/rbenv.init-no-rehash
else
source $ZSHHOME/rbenv.init
fi
check_rbenv_init() {
rbenv init - | diff - $ZSHHOME/rbenv.init
@niyaton
niyaton / hello.c
Created October 9, 2013 21:21
Hello World
#include <stdio.h>
int main(){
printf("Hello World!");
return 0;
}
int a[10]; //配列には適切な値が入っていると仮定する
int tmp; // 一時的に利用する変数.(temporaryの略でtmp)
// a[0]とa[3]を交換する.
tmp = a[0]
a[0] = a[3]; //a[0] = tmpでもよい
a[3] = tmp;
#include <stdio.h>
int main(){
int n;
printf("配列のサイズを入力してください");
scanf("%d", &n);
int array[n];
int i;
# Checking whther zplug is installed
if [[ ! -d ~/.zplug ]]; then
git clone https://github.com/zplug/zplug ~/.zplug
fi
cat <<EOT > ~/.zshrc
# Essential
source ~/.zplug/init.zsh
# zplug check returns true if all packages are installed