Skip to content

Instantly share code, notes, and snippets.

View ksoda's full-sized avatar
👯‍♀️
I may be slow to respond.

Ken Sonoda ksoda

👯‍♀️
I may be slow to respond.
  • Tokyo
View GitHub Profile
@ksoda
ksoda / mask.py
Created May 4, 2016 14:57
OpenCV
import cv2, matplotlib
import numpy as np
import matplotlib.pyplot as plt
bgr_img = cv2.imread('images/landscape.jpg')
img = cv2.cvtColor(bgr_img, cv2.COLOR_BGR2HSV)
blue_min = np.array([100, 0, 0], np.uint8)
blue_max = np.array([140, 255, 255], np.uint8)
wh_min = np.array([0, 0, 180], np.uint8)
wh_max = np.array([180, 60, 255], np.uint8)
@ksoda
ksoda / ffmpeg.sh
Created October 30, 2016 03:38
trim a bunch of audio files that have silence at the beginnings and ends automatically
ffmpeg -i audio.m4a -filter 'silenceremove=0:0:0:-1:3:-90dB' tmp.m4a
@ksoda
ksoda / fn_pointer.c
Last active October 30, 2016 14:39
C lang samples
#include <stdio.h>
#include <stdbool.h>
typedef int (*Operator)(int a, int b);
int add(int a, int b) {
return(a + b);
}
int mult(int a, int b) {
@ksoda
ksoda / jis2sun.ahk
Last active December 9, 2016 13:52
Sun Type3 keyboard layout
; maps layout JIS -> Sun Type3
; https://autohotkey.com/download/ahk-install.exe
; The keyboard hook monitors keystrokes for the purpose of activating hotstrings
; and any keyboard hotkeys not supported by RegisterHotkey
; (which is a function built into the operating system).
; It also supports a few other features such as the Input command.
#UseHook
sc03a::
@ksoda
ksoda / download.rb
Created February 1, 2018 14:03
Web scraping sample 青空文庫
require 'rubygems'
require 'bundler'
Bundler.require
require 'open-uri'
aozora_uri = 'http://www.aozora.gr.jp/cards/000148/files/789_14547.html'
file = 'sample.txt'
unless File.exist?(file)
html = open(aozora_uri, 'r:Shift_JIS').read.encode('utf-8', universal_newline: true)
text = Oga.parse_html(html).css('.main_text').text.gsub(/(.*?)/, '')
@ksoda
ksoda / main.tf
Last active November 28, 2018 12:24
variable "db_username" {}
variable "db_password" {}
variable "aws_key_name" {}
provider "aws" {
region = "ap-northeast-1"
shared_credentials_file = "$HOME/.aws/credentials"
profile = "default"
}
@ksoda
ksoda / recognition.js
Last active December 9, 2018 10:40
Echo using Web Speech API
[
"audioend",
"audiostart",
"end",
"error",
"nomatch",
"result",
"soundend",
"soundstart",
"speechend",
(def alt-from-char {\U 1 \D -1})
(defn ending-valley? [step alt]
(and (= alt -1) (= step \U)))
(defn countingValleys [n s]
(:cnt
(reduce
(fn [acc step]
(let [{:keys [cnt alt]} acc]
@ksoda
ksoda / record.bash
Last active August 25, 2019 12:09
Record terminal
#!/bin/bash -eu
# Dependencies:
# npm install -g svg-term-cli
# pip3 install asciinema
cast_filename=$(mktemp -u)
asciinema rec ${cast_filename}
out_filename=$(mktemp -u)
svg-term --in ${cast_filename} --out ${out_filename}.svg
var _require = function _require(cond) {
if (!cond) {
factor(-Infinity);
}
}
// Class attendance model.
var attendance = function(i_pl, i_stats, busy) {
var attendance = function (interest, busy) {
if (interest) {