Skip to content

Instantly share code, notes, and snippets.

View kosugi's full-sized avatar

KOSUGI Tomo kosugi

  • tokyo.japan
View GitHub Profile
@kosugi
kosugi / enspeed.py
Created December 1, 2013 09:55
echo 深夜徘徊 | enspeed.py
#! /usr/bin/env python
from unicodedata import category
PREFIX = u'\u003D\u035E\u035F\u035F\u035E'
def do(istream, ostream):
for c in istream.read():
if category(c) not in ['Cc', 'Zs']:
ostream.write(PREFIX)
(defun frame-alpha-offset (d)
(let* ((a (frame-parameter nil 'alpha))
(b (+ d (if (integerp a) a 100)))
(c (cond ((< b 20) 20)
((> b 100) 100)
(t b))))
(set-frame-parameter nil 'alpha c)))
function! transparency#Shift(ofs)
let l:l = &g:transparency
if type(l:l) != 0
let l:l = 0
endif
let l:l += a:ofs
if l:l < 0
let l:l = 0
endif
if 80 < l:l
xs = '''
accounts.google.com
google.co.jp
mail.google.com
www.google.co.jp
www.youtube.com
youtube.com
'''.strip().split()
sorted(xs, key=lambda v:'.'.join(reversed(v.split('.'))))
(defun escape-shell-arg (x)
(concat "'" (replace-regexp-in-string "'" "'\\\\''" x) "'"))
@kosugi
kosugi / with-short-circuiting.el
Last active December 31, 2015 17:29
マクロに apply できない問題
(defun or/l (args)
(let ((r nil))
(while (and args (null r))
(setq r (or r (car args)))
(setq args (cdr args)))
r))
# -*- coding: utf-8 -*-
# http://www.checkio.org/mission/brackets/
# 普通こうでは!?
from itertools import dropwhile
pairs = '{} [] ()'.split()
def parse_term(s):
t = ''.join(dropwhile(str.isdigit, s))
from math import pi, sqrt, acos, asin
def vsub(a, b):
return (a[0] - b[0], a[1] - b[1])
def hit(a, b, c, p):
ab = vsub(b, a)
bp = vsub(p, b)
bc = vsub(c, b)
cp = vsub(p, c)
@kosugi
kosugi / angle.py
Last active August 29, 2015 13:56
from math import pi, sqrt, acos, asin, sin, cos
for n in range(0, 360+1, 10):
x = cos(pi * n / 180)
y = sin(pi * n / 180)
r = sqrt(x ** 2 + y ** 2)
th_cos = 180 * acos(x / r) / pi
th_sin = asin(y / r)
if th_sin < 0:
th_cos = 360 - th_cos
// g++ -std=c++11 RiverCrossing.cpp
#include <iostream>
#include <queue>
#include <vector>
#include <array>
#include <algorithm>
using namespace std;