Skip to content

Instantly share code, notes, and snippets.

@nyango
nyango / solvepicross.scala
Created September 14, 2019 07:13
ピクロス(お絵かきロジック)を解くプログラム
object Main extends App {
def possibleSeq(baseSeq: Seq[Option[Boolean]]): Seq[Seq[Boolean]] =
baseSeq.foldLeft(Seq(Seq.empty[Boolean])) { (acc, ele) =>
ele match {
case Some(b) => acc.map(_ ++ Seq(b))
case None => acc.flatMap(s => Seq(s ++ Seq(true), s ++ Seq(false)))
}
}
@nyango
nyango / WildcardAllowedCORSFilterFactory.scala
Last active December 24, 2019 06:37
Play CORS Filter with wildcard origin matching
import javax.inject.{Inject, Singleton}
import akka.stream.Materializer
import play.api.Configuration
import play.filters.cors.CORSConfig.Origins.Matching
import play.filters.cors.{CORSConfig, CORSFilter}
import scala.concurrent.ExecutionContext
import scala.util.matching.Regex
@nyango
nyango / list_policies.sh
Created April 21, 2017 11:00
ユーザーに付与された管理ポリシー一覧を閲覧するシェルスクリプト
#!/bin/bash -eu
if [[ $# != 1 ]];
then
echo "第一引数にアカウント名を指定してください。"
echo ""
echo "e.g."
echo "$ ./list_policies.sh your_account_name"
exit 1
fi
@nyango
nyango / prime.py
Last active July 17, 2016 10:06 — forked from graph226/prime.py
Sieve of Eratosthenes by Python
import math
NUMBER = 100000000
def get_prime_list(limit):
limit_sqrt = int(math.ceil(math.sqrt(limit)))
prime_bool_list = [False] * 2 + [True] * (limit - 2)
for prime_cand in xrange(2,limit_sqrt):
if prime_bool_list[prime_cand]:
for composite in range(prime_cand ** 2, limit, prime_cand):
prime_bool_list[composite] = False
@nyango
nyango / parse_png.sh
Created December 30, 2015 08:39
PNGファイルを読み込み評価する
#!/bin/bash
set -eu
pngFile=$1
headPtr=0
if [ "89504E470D0A1A0A" != $(xxd -ps -u -s $headPtr -l 8 $pngFile) ]
then
echo "pngファイルではありません"
exit 1
fi
headPtr=$((headPtr+8))
@nyango
nyango / rm_duplication.sh
Last active August 29, 2015 14:08
md5sumを用いて重複ファイルを削除するスクリプトを書いた / Using md5sum, this script removes duplicated files
#!/bin/bash
# this script removes duplicated files
# using md5sum.
#
# $1 : target directory
#
tmptable=$(mktemp temp.XXXXX)
\ls -t ${1%/}/* | while read line
do
@nyango
nyango / file0.txt
Created November 3, 2014 15:35
Macで動画をアスキーアートに変換した話 ref: http://qiita.com/jamejammy/items/0c612731233ac763d069
brew install aalib
brew install libcaca
brew install mplayer --with-libcaca
@nyango
nyango / file0.txt
Last active August 29, 2015 14:08
CentOSにpyenvとrbenvをシステム全体にインストール ref: http://qiita.com/jamejammy/items/f227c259485fbd3c7c9c
sudo git clone git://github.com/yyuu/pyenv.git /usr/local/pyenv
sudo git clone git://github.com/yyuu/pyenv-virtualenv.git /usr/local/pyenv/plugins/pyenv-virtualenv
@nyango
nyango / file0.txt
Last active August 29, 2015 14:08
CentOS上でPythonとRubyの環境をpyenvとrbenvを用いてシステムに構築する ref: http://qiita.com/jamejammy/items/cd09694b938831eb8aa8
sudo git clone git://github.com/yyuu/pyenv-virtualenv.git /usr/local/pyenv
sudo git clone git://github.com/yyuu/pyenv-virtualenv.git /usr/local/pyenv/plugins/pyenv-virtualenv
@nyango
nyango / naivebayes.py
Last active August 29, 2015 14:07
naivebayes.py
import csv
trainReader = csv.reader(open('traindata.csv', 'rb'))
nya = []
for row in trainReader:
nya.append(row)
# train data
noarr = filter(lambda row: row[-1] == 'No', nya)
yesarr = filter(lambda row: row[-1] == 'Yes', nya)