Skip to content

Instantly share code, notes, and snippets.

View vwrs's full-sized avatar
🏠
Working from home

Hideaki Kanehara vwrs

🏠
Working from home
View GitHub Profile
@vwrs
vwrs / 504.c
Last active February 23, 2016 15:15
Problem 504
#include <tgmath.h>
#include <stdio.h>
#include <stdlib.h>
// 20s
// Euclidean Algorithm
int gcd(int x, int y){
if(y < 1) exit(0); // error
int z;
@vwrs
vwrs / 002.rb
Last active February 23, 2016 15:17
Problem 002
# Problem 002
# 0.043[s]
# 0, 1, 1, 2, 3, 5, 8, ...
def fibo(n)
return n if n == 0 || n == 1
x, y, z, i = 1, 1, 1, 2
while i < n
@vwrs
vwrs / bb8.py
Created April 20, 2017 07:02
bb8(sphero) sample code
#!/usr/bin/env python
# BB-8 Python driver by Alistair Buxton <a.j.buxton@gmail.com>
from bluepy import btle
import time
class BB8(btle.DefaultDelegate):
def __init__(self, deviceAddress):
@vwrs
vwrs / jaccard.php
Last active July 30, 2018 05:15
calc Jaccard Index in PHP
<?php
/**
* Return the degree of similarity (Jaccard Index) for each product
*
* @param array $mat user-item matrix $mat[product_id][user_id] 1|null
* @param integer $product_id
* @author Hideaki Kanehara
* @return array key: product_id value: degree of similarity
*/
function jaccard($mat,$product_id)
@vwrs
vwrs / hmm.r
Created July 26, 2017 09:24
BTS
library(HMM)
outputS = c('A', 'B', 'C', 'D', 'E')
hiddenS = c('S01', 'S02', 'S13', 'S14', 'S15', 'S56', 'S26', 'S37', 'S48', 'S68', 'E')
startP = c(0.10, 0.10, 0.10, 0.10, 0.10, 0.10, 0.10, 0.10, 0.10, 0.10, 0.10)
transP = rbind(
t(c(0.00, 0.20, 0.20, 0.20, 0.20, 0.00, 0.00, 0.00, 0.00, 0.00, 0.20)),
t(c(0.33, 0.00, 0.00, 0.00, 0.00, 0.00, 0.33, 0.00, 0.00, 0.00, 0.34)),
t(c(0.20, 0.00, 0.00, 0.20, 0.20, 0.00, 0.00, 0.20, 0.00, 0.00, 0.20)),
t(c(0.20, 0.00, 0.20, 0.00, 0.20, 0.00, 0.00, 0.00, 0.20, 0.00, 0.20)),
@vwrs
vwrs / parallel_mv.sh
Last active August 10, 2017 04:32
parallelize mv by GNU parallel
ls /path/to/src/*.extension | parallel --no-notice mv -fv {} /path/to/dst
@vwrs
vwrs / userChrome.css
Last active February 1, 2018 16:24
~/Library/Application Support/Firefox/Profiles/xxxxxx.default/chrome/userChrome.css
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
/* to hide the native tabs */
/* #TabsToolbar {
visibility: collapse;
} */
/* to hide the sidebar header */
#sidebar-header {
visibility: collapse;
}
@vwrs
vwrs / download-disabled-dropbox.sh
Created April 9, 2018 13:46
download as pdf from Dropbox when the download option is disabled
#!/bin/bash -eu
# first, get the image URLs using such as Chrome DevTools
# The URLs is assumed to be "xxxxx?page={page number}"
URI=("https://path/to/file1" "https://path/to/file2")
PAGES=(10 20)
RED=""
GREEN=""
BLUE=""
NORMAL=""
@vwrs
vwrs / crawler-with-tor.py
Created May 22, 2018 13:43
NIPS paper downloader
import os
import wget
import requests
from bs4 import BeautifulSoup
# use Tor
local_proxy = 'socks5://127.1:9050'
socks_proxy = {
'http': local_proxy,
'https': local_proxy
@vwrs
vwrs / autodel.sh
Last active September 12, 2018 07:27
Delete old files in a folder automatically
#!/bin/bash -eu
# for crontab
FILEDIR=/path/to/dir
LOGFILE=/var/log/autodel.log
DAYS=200
PROCESSES=4
CHUNK=10
# delete files older than 200 days & parallelize