Skip to content

Instantly share code, notes, and snippets.

Avatar

zato uiur

View GitHub Profile
@uiur
uiur / 0.py
Created Aug 2, 2016
stack images
View 0.py
size = (10, 10)
imgs = imgs[:size[0] * size[1]].reshape(size[0], size[1], 28, 28)
result = np.vstack(tuple([np.hstack(tuple(img)) for img in imgs]))
imsave('a.png', result)
@uiur
uiur / mser.py
Created Jul 4, 2016
extract regions and save by MSER
View mser.py
import sys
import numpy as np
import cv2
def extract_region(img, region):
top_left = np.min(region, axis=0)
bottom_right = np.max(region, axis=0)
margin = 2
region_of_image = img.copy()[top_left[1]-margin:bottom_right[1]+margin, top_left[0]-margin:bottom_right[0]+margin]
@uiur
uiur / 0.sh
Created Jun 16, 2016
edit pdf using pdftk
View 0.sh
pdftk a.pdf dump_data_utf8 output data.txt
vi data.txt
pdftk a.pdf update_info_utf8 data.txt output b.pdf
View pi.py
def pi(n):
half_pi = 0
for k in range(n + 1):
m = 1.0
for i in range(1, k + 1):
m *= float(2 * i - 1) / (2 * i)
half_pi += m / (2 * k + 1)
return 2 * half_pi
@uiur
uiur / 0.go
Created Apr 8, 2016
go/scanner + goyacc sample
View 0.go
%{
package main
import (
"fmt"
"go/scanner"
"os"
"go/token"
)
@uiur
uiur / 0.sh
Last active Feb 17, 2016
show ruby ast
View 0.sh
cat app/models/comment.rb | ruby -r pp -r ripper -e 'pp Ripper.sexp(ARGF.read)'
@uiur
uiur / gist:3e05024bc7fbed09a9fa
Created Dec 16, 2015
apple script file path
View gist:3e05024bc7fbed09a9fa
set filePath to ""
tell application "QuickTime Player"
try
if file path of front document is not equal to missing value then
set filePath to file path of front document
end if
end try
try
if path of front document is not equal to missing value then
set filePath to path of front document
@uiur
uiur / 0.rb
Created Dec 11, 2015
[[k, v] ...] -> tsv and copy
View 0.rb
`echo "#{CSV.generate(col_sep: "\t") {|r| a.to_a[1..-1].each{|ar| r << ar} }}" | pbcopy`
@uiur
uiur / topic.py
Created Nov 7, 2015
lda livedoor news
View topic.py
# coding: utf-8
import glob
import MeCab
import gensim
from gensim import corpora, matutils
import numpy as np
import codecs
import sys
sys.stdout = codecs.getwriter('utf_8')(sys.stdout)
View private.xml
<?xml version="1.0"?>
<root>
<vkopenurldef>
<name>KeyCode::VK_OPEN_URL_GYAZO</name>
<url type="shell">
<![CDATA[ /usr/sbin/screencapture /tmp/gyazo-fullscreen.png; /Applications/Gyazo.app/Contents/MacOS/Gyazo /tmp/gyazo-fullscreen.png ]]>
</url>
</vkopenurldef>
<list>