Skip to content

Instantly share code, notes, and snippets.

@kei-sato
kei-sato / install-gm-w-librvg.sh
Created March 2, 2017 10:05 — forked from thenadz/install-gm-w-librvg.sh
Installs ImageMagick --with-librsvg on Amazon Linux
export PKG_CONFIG_PATH=/usr/lib64/pkgconfig:/usr/lib/pkgconfig
export PATH=/usr/bin:$PATH
export LDFLAGS=-L/usr/lib64:/usr/lib
export LD_LIBRARY_PATH=/usr/lib64:/usr/lib
export CPPFLAGS=-I/usr/include
PREFIX=/usr
sudo yum-config-manager --enable epel
sudo yum -y update && sudo yum -y upgrade
@kei-sato
kei-sato / fermat_binom.py
Created February 4, 2017 12:01 — forked from fishi0x01/fermat_binom.py
Calculating large binomial coefficients modulo prime / non-prime numbers (nCk mod m). Code for blog post http://fishi.devtail.io/weblog/B/
#!/usr/bin/env python3
"""
Using Fermat's little theorem to calculate nCk mod m, for k < m and m is prime
Two versions:
1. Pre-Compute factorials and multiplicative inverses in O(n*logn) --> later lookup in O(1)
2. Compute directly --> no lookup --> each time O(n)
"""
#!/usr/bin/env node
/*
# Usage
```
: list objects
node aws-sdk-tips.js -b bucket-name -k path/to/dir
# : how to create key pair which is used to ssh login to ec2 instances
# keypair_name=mykey1
# ssh-keygen -t rsa -f ~/.ssh/${keypair_name}
# aws ec2 import-key-pair --key-name ${keypair_name} --public-key-material file://$HOME/.ssh/${keypair_name}.pub
# : modify these variables to fit your situation
# StackName=ec2-run-instance
# yaml2json > /tmp/parameters.json << 'EOF'
# - ParameterKey: KeyName
# ParameterValue: mykey1
server {
listen 80;
charset utf-8;
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
location / {
root /usr/share/nginx/html;
index index.html;
@kei-sato
kei-sato / config.yml
Created April 1, 2016 07:47
config to use s3 as its storage with docker registry version 2
# https://github.com/docker/distribution/blob/master/docs/configuration.md
# https://github.com/docker/distribution/blob/master/cmd/registry/config-example.yml
# usage:
# docker run -d -p 5000:5000 --name registry \
# -v /path/to/this/config.yml:/etc/docker/registry/config.yml \
# -e REGISTRY_STORAGE_S3_ACCESSKEY= \
# -e REGISTRY_STORAGE_S3_SECRETKEY= \
# -e REGISTRY_STORAGE_S3_REGION= \
# -e REGISTRY_STORAGE_S3_BUCKET= \
@kei-sato
kei-sato / netmask-bit-count
Created February 12, 2016 02:47
example: 0xffffff00 => 24
#!/usr/bin/env bash
# read from argument or stdin
mask="$1"; [[ -z "$mask" ]] && read -r mask < /dev/stdin
# remove 0x
mask="${mask##0x}"
count=0
while [ "$mask" != "" ]; do
#!/usr/bin/env ruby
# https://goo.gl/JJ8BaU
class Integer
def prime?
n = self.abs()
return true if n == 2
return false if n == 1 || n & 1 == 0
d = n-1 # nは奇数だからdは偶数
d >>= 1 while d & 1 == 0 # n-1 = d * 2^s
@kei-sato
kei-sato / rarp
Last active January 25, 2016 07:15
#!/usr/bin/env bash
# reverse arp
USAGE='
Example:
rarp 00:0a:95:9d:68:16
=> 192.168.0.253
'
abort() {
@kei-sato
kei-sato / addevent
Last active November 13, 2017 04:42
addevent - command to add events to Calendar (previously called iCal)
#!/usr/bin/env bash
set -e
abort() { echo "$@" 1>&2; exit 1; }
USAGE="
Usage: $0 [-xhn] [-c CAL_NUMBER] [-i INTERVAL] [-t DURATION] (-D DATETIME | -S SECONDS | -M MINUTES | -H HOURS | -d DAYS) TITLE
-x) Debug (show all commands)
-h) help