Skip to content

Instantly share code, notes, and snippets.

@kei-sato
kei-sato / usdex
Last active August 29, 2015 14:24
Exchange usd to any currency, or any currency to usd
#!/usr/bin/env python
#coding:utf-8
# Exchange usd to any currency, or any currency to usd
# help: python convert_usd.py -h
import os.path
from datetime import date, datetime
import argparse
import urllib
@kei-sato
kei-sato / clustering-lance-williams.coffee
Last active November 9, 2015 18:18
Clustering with Lance-Williams updating formula
# Clustering with Lance-Williams updating formula
# http://ibisforest.org/index.php?Lance-Williams%20updating%20formula
calcSquare = (n) -> n * n
haversine = (lat1, lng1, lat2, lng2) ->
6371000 * 2 * Math.asin(Math.sqrt(Math.pow(Math.sin((lat1 - Math.abs(lat2)) * Math.PI / 180 / 2), 2) + Math.cos(Math.abs(lat1) * Math.PI / 180 ) * Math.cos(Math.abs(lat2) * Math.PI / 180) * Math.pow(Math.sin((lng1 - lng2) * Math.PI / 180 / 2), 2) ))
##
# calculate distance between 2 numbers
@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
@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() {
#!/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 / 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
@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= \
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;
# : 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
#!/usr/bin/env node
/*
# Usage
```
: list objects
node aws-sdk-tips.js -b bucket-name -k path/to/dir