Skip to content

Instantly share code, notes, and snippets.

# coding: utf-8
import re
regnum = re.compile(r'([0-9]+)')
def factory(units):
def flat(string):
"""minimize unit"""
string = string.replace(',', '')
@righ
righ / dircmp.py
Last active August 29, 2015 14:14
dircmp.py
# coding: utf-8
import os
import filecmp
class Break(Exception):
"""for break recursive function
"""
@righ
righ / only.py
Last active August 29, 2015 14:16
#!/usr/bin/env python
# coding: utf-8
import socket
import functools
def nop():
"""no operation"""
# coding: utf-8
import re
_02 = (lambda s: '{0:0>2}'.format(s))
_03 = (lambda s: '{0:0>3}'.format(s))
MAP = {
'%a': r'(Sun|Mon|Tue|Wed|Thu|Fri|Sat)',
'%A': r'(Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday)',
'%w': r'([0-6]{1})',
@righ
righ / s3.py
Last active April 6, 2016 08:15
# coding: utf-8
import os
from boto.s3 import (
connection as s3conn,
key as s3key,
)
from boto.exception import (
S3ResponseError,
#!/usr/bin/env python
# coding: utf-8
import sys
def format_timezones(timezones, descriptor=sys.stdout):
_tz = ()
for tz in sorted(t.split('/') for t in timezones):
for indent, region in enumerate(tz):
if len(_tz) > indent and _tz[indent] == tz[indent]:
@righ
righ / excel_column_converter.py
Created October 20, 2017 05:13
Excelの列名変換
from string import ascii_uppercase
def to_column(number):
"""
:param int number: 1以上の数値
"""
string = ''
while True:
number -= 1
@righ
righ / checkboxWidget.jsx
Last active July 12, 2018 12:56
React customized checkbox
import React from 'react'
import './checkboxWidget.styl'
let defaultStyle = {width: 22, height: 22}
const CheckBox = (props) => {
let onClick = () => !props.readonly && !props.disabled ? props.handleChange() : null
let borderColor = props.borderColor ? props.borderColor : '#aaa'
let backgroundColor = props.checked ? props.backgroundColor ? props.backgroundColor : '#transparent' : 'transparent'
let style = Object.assign({}, defaultStyle, props.style)
@righ
righ / escape.js
Created August 6, 2018 01:08
markdown_xss_test
const deniedTagCondition = /^<\/?(script|style|link|iframe|embed|object|html|head|meta|body|form|input|button)/i
const deniedAttrCondition = /^(on.+|style|href|action|id|class|data-.*)/i
const escape = (txt) => {
if (txt.match(deniedTagCondition) || txt.indexOf('<!') === 0 || txt.indexOf('<?') === 0 || txt.indexOf('<\\') === 0) { return '' }
if (txt.indexOf('</') === 0) { return txt }
let outer = document.createElement('div')
outer.innerHTML = txt
let el = outer.querySelector('*')
if (!el) {return ''}
import re
DEFAULT_MULTIPLIERS = {
'S': 1,
'M': 60,
'H': 60 * 60,
'd': 60 * 60 * 24,
}
def time_to_seconds(pattern, target, multipliers={}):