Skip to content

Instantly share code, notes, and snippets.

@utgwkk
utgwkk / namecard.py
Last active August 29, 2015 14:27
画像ファイルを名刺印刷用の形式にするやつ
from PIL import Image
cols, rows = 2, 4
linewidth = 10
img = Image.open("input.png")
width, height = img.size
size = width*cols+linewidth, height*rows+(rows-1)*linewidth
output = Image.new("RGB", size, (0, 0, 0))
for y in range(rows):
h = (height+linewidth)*y
@utgwkk
utgwkk / setsunanomikiri.py
Created August 19, 2015 04:06
刹那の見切り
import os
import random
import time
t = random.randint(200,500)
dur = 0
bang = """
____
| |
| |
@utgwkk
utgwkk / blackjack.cpp
Last active August 29, 2015 14:28
Blackjack-like game. Requires C++11. >g++ -std=gnu++11 -o blackjack ./blackjack.cpp
#include <cstdio>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#define FOR(i,m,n) for(int i=m;i<(int)(n);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using namespace std;
@utgwkk
utgwkk / tabletotsv.py
Created August 24, 2015 16:35
Convert <TABLE> to TSV.
# coding: utf-8
from html.parser import HTMLParser
import sys
text = sys.stdin.read()
output = ''
class TableToTSV(HTMLParser):
def initialize(self):
self.cols = []
@utgwkk
utgwkk / gyazo_upload.py
Created August 24, 2015 19:52
Gyazoに画像upするやつのテスト
YOUR_ACCESS_TOKEN = 'INSERT YOUR ACCESS TOKEN'
import requests
import sys
if len(sys.argv) == 1:
print('ファイル名を指定してください')
sys.exit()
url = "https://upload.gyazo.com/api/upload"
@utgwkk
utgwkk / generate_trace.py
Created September 10, 2015 11:06
Generates the trace from the log file generated by Piet on Go.
#!/usr/bin/env python
from PIL import Image, ImageDraw
import sys
import re
sourcefilename = sys.argv[1]
if len(sys.argv) > 2:
codelsize = int(sys.argv[2])
else:
codelsize = 1
@utgwkk
utgwkk / goftest.go
Created September 26, 2015 03:32
Goで関数内関数・グローバル変数に近いもの
package main
import "fmt"
func main() {
var c int = 10
hoge := func (a, b int) int {
return a + b + c
}
fmt.Println(hoge(2,3)) // 15
@utgwkk
utgwkk / stream.suruyatu.py
Created October 9, 2015 16:53
Posts a URL of the tweet you favorite to a Slack channel if it has a media.
import tweepy
import requests
token = ""
slackURL = "https://slack.com/api/"
params = {'token': token, 'channel': '#random', 'text': '', 'as_user': 'true'}
CONSUMER_KEY = ""
CONSUMER_SECRET = ""
ACCESS_TOKEN = ""
ACCESS_TOKEN_SECRET = ""
@utgwkk
utgwkk / image_collector.py
Last active October 18, 2015 18:42
ふぁぼった画像付きツイートの画像を保存する Python スクリプト
#!/usr/bin/python3
import os
import tweepy
from traceback import print_exc, format_exc
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)
me = api.me().screen_name
@utgwkk
utgwkk / mandel.py
Last active October 23, 2015 11:23 — forked from firstspring1845/mandel.py
draw Mandelbrot set / requires PIL
import itertools
from PIL import Image
result = Image.new("L", (6400, 6400))
for r, i in itertools.product(range(6400), repeat=2):
c = complex(r / 1600.0 - 2.0, i / 1600.0 - 2.0)
z = 0
print(c)