Skip to content

Instantly share code, notes, and snippets.

@wwwins
wwwins / app.py
Created November 7, 2017 06:50
simple flask server for api.ai
import json
from random import randint
from flask import Flask
from flask import request
from flask import make_response
app = Flask(__name__)
@wwwins
wwwins / s3upload.py
Created May 24, 2017 09:10
python boto3 upload files to aws s3
# -*- coding: utf-8 -*-
"""
Usage:
python s3upload.py -b bucket -i image.jpg
python s3upload.py -b bucket -f images -i image.jpg
python s3upload.py -b bucket -f images -i image.jpg -t img.jpg
python s3upload.py -p tokyo -b bucket -i image.jpg
"""
from argparse import ArgumentParser
@wwwins
wwwins / detectface.py
Created May 24, 2017 06:30
aws rekognition detect faces api
#!/usr/bin/env python
"""
Usage:
python detectface.py -i image.jpg
"""
from argparse import ArgumentParser
import boto3
from pprint import pprint
@wwwins
wwwins / avi2webm.sh
Created May 12, 2017 01:15
avi2webm
# https://trac.ffmpeg.org/wiki/Encode/VP9
# audio: libvorbis
# brew install ffmpeg --with-libvpx --with-libvorbis
# lossless and without audio
ffmpeg -i test.avi -lossless 1 -an output.webm
# Variable Bitrate: 1 MBit/s
ffmpeg -i test.avi -c:v libvpx-vp9 -b:v 1M -an output.webm
@wwwins
wwwins / imagefont.py
Created April 20, 2017 04:55
PIL image font
# -*- coding: utf-8 -*-
#
# imagefont.py
#
from PIL import Image, ImageDraw, ImageFont
# image = Image.open('cats.png')
# width, height = image.size
image = Image.new("RGBA",(500,1000),(0,0,0,255))
width, height = image.size
@wwwins
wwwins / isobard.py
Created April 14, 2017 04:24
A small daemon for rfid reader
# isobard.py
# read rfid -> pkill -> get user info -> exec face detecter
#
# connect to it with:
# echo -n "0001864282 edith"|nc -w 0 localhost 5555
#
from socket import *
from time import sleep
import subprocess
@wwwins
wwwins / opencvd.py
Last active April 14, 2017 04:25
opencv + socket server
#!/usr/bin/env python
import cv2
import gevent
import time
from ticket import ticket
from socket import *
from gevent import Greenlet
from gevent.threadpool import ThreadPool
from gevent.select import select as gselect
@wwwins
wwwins / queue.py
Created March 31, 2017 04:39
gevent example
# -*- coding: utf-8 -*-
import gevent
from gevent.queue import Queue
from urllib2 import urlopen
from gevent.threadpool import ThreadPool
def worker(n):
while not tasks.empty():
task = tasks.get()
print('Worker %s got task %s' % (n, task))
@wwwins
wwwins / imgcat
Created March 27, 2017 07:45
imgcat for tmux
#!/bin/bash
# tmux requires unrecognized OSC sequences to be wrapped with DCS tmux;
# <sequence> ST, and for all ESCs in <sequence> to be replaced with ESC ESC. It
# only accepts ESC backslash for ST.
function print_osc() {
if [[ $TERM == screen* ]] ; then
printf "\033Ptmux;\033\033]"
else
printf "\033]"
@wwwins
wwwins / ScanCardReader.py
Last active September 20, 2018 05:42
raspberry pi + usb rfid card reader
# ScanCardReader.py
# -*- coding: utf-8 -*-
# scanning usb rfid card reader.
import evdev
from evdev import InputDevice, categorize, ecodes
from select import select
input = evdev.InputDevice('/dev/input/event0')