Skip to content

Instantly share code, notes, and snippets.

@nyango
nyango / solvepicross.scala
Created Sep 14, 2019
ピクロス(お絵かきロジック)を解くプログラム
View solvepicross.scala
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 Dec 24, 2019
Play CORS Filter with wildcard origin matching
View WildcardAllowedCORSFilterFactory.scala
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 Apr 21, 2017
ユーザーに付与された管理ポリシー一覧を閲覧するシェルスクリプト
View list_policies.sh
#!/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 Jul 17, 2016 — forked from graph226/prime.py
Sieve of Eratosthenes by Python
View prime.py
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 Dec 30, 2015
PNGファイルを読み込み評価する
View parse_png.sh
#!/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 Aug 29, 2015
md5sumを用いて重複ファイルを削除するスクリプトを書いた / Using md5sum, this script removes duplicated files
View rm_duplication.sh
#!/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 Nov 3, 2014
Macで動画をアスキーアートに変換した話 ref: http://qiita.com/jamejammy/items/0c612731233ac763d069
View file0.txt
brew install aalib
brew install libcaca
brew install mplayer --with-libcaca
@nyango
nyango / file0.txt
Last active Aug 29, 2015
CentOSにpyenvとrbenvをシステム全体にインストール ref: http://qiita.com/jamejammy/items/f227c259485fbd3c7c9c
View file0.txt
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 Aug 29, 2015
CentOS上でPythonとRubyの環境をpyenvとrbenvを用いてシステムに構築する ref: http://qiita.com/jamejammy/items/cd09694b938831eb8aa8
View file0.txt
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 Aug 29, 2015
naivebayes.py
View 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)