Skip to content

Instantly share code, notes, and snippets.

View oshinko's full-sized avatar

Oshinko oshinko

View GitHub Profile
@oshinko
oshinko / MainActivity.java
Last active April 17, 2017 05:32
リクエストヘッダを指定してブラウザを開く
package activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Browser;
import android.support.v7.app.AppCompatActivity;
import BuildConfig;
import R;
@oshinko
oshinko / bots.py
Last active June 28, 2017 17:03
Coroutine Event Loops for UDP in Python 3.
# python3 bots.py localhost 8080 100 4 1
import random
import select
import socket
import sys
import time
from datetime import datetime
eventmask = select.POLLIN | select.POLLPRI | select.POLLHUP | select.POLLERR
import csv
from easydict import EasyDict
default_reader = csv.DictReader
def load_tsv(path, reader=default_reader):
return load_csv(path, delimiter='\t', reader=reader)
import json
import re
import sys
def repl(match):
return ':"{0}"{1}'.format(
match.group(1),
match.group(2))
text = re.sub(r':([0-9A-Za-z]+)([,}])', repl, sys.stdin.readline())
@oshinko
oshinko / install-opencv-on-debian.sh
Created August 5, 2017 03:04
Install OpenCV on Debian
sudo apt-get -y install libopencv-dev python-opencv
@oshinko
oshinko / install-vertx.sh
Created April 8, 2016 00:43
Install vert.x.
export TARGET_VERTX_VERSION='3.2.1'
cd $HOME
curl -L -O https://bintray.com/artifact/download/vertx/downloads/vert.x-$TARGET_VERTX_VERSION.tar.gz
tar zxvf vert.x-$TARGET_VERTX_VERSION.tar.gz
rm vert.x-$TARGET_VERTX_VERSION.tar.gz
export PATH=$HOME/vertx/bin:$PATH
echo 'Ready for running!'
vertx --version
@oshinko
oshinko / uitest.py
Last active August 6, 2017 04:35
Automated GUI Testing with OpenCV.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from cvwrapper import AndroidAgent, Image
# Create agent
agent = AndroidAgent()
# Capture image
image = agent.capture()
@oshinko
oshinko / redis_snowflake.py
Last active October 14, 2017 04:03
Redis Snowflake for Python.
import redis
import time
def snowflake(redis, epoch=0):
return redis.register_script(f"""
local node = tonumber(redis.call('HGET', 'globals', 'node')) % 1024
local seq = tonumber(redis.call('HINCRBY', 'globals', 'sequence', 1)) % 4096
local time = redis.call('TIME')
local time41 = ((tonumber(time[1]) * 1000) + (tonumber(time[2]) / 1000)) - {epoch}
@oshinko
oshinko / hmac_web_token_example.py
Last active January 30, 2018 02:43
HMAC Web Token Example
import hmac
from datetime import datetime, timedelta
from hashlib import sha256
class Session:
secret = b'Please enter your desired passphrase'
def __init__(self, *, user=None, token=None):
if user:
# -*- coding: utf-8 -*-
import multiprocessing
import subprocess
import sys
import time
class Job:
done = False