This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import urllib.request | |
WEBHOOK_URL = "https://hooks.slack.com/services/XXXXXXXXXX/YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY" | |
MESSAGE_TEMPLATE = """<{url}|{message}>""" | |
def lambda_handler(event, context): | |
post(event) | |
return {"statusCode": 200} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { pbkdf2Sync } = require('crypto'); | |
export const validate = (raw, password, len=32) => { | |
const [method, iterations, salt, hash] = password.split('$'); | |
const digest = method.split("_")[1]; | |
return pbkdf2Sync(raw, salt, parseInt(iterations, 10), len, digest).toString('base64') === hash; | |
}; | |
export const make = (raw, iterations, digest="sha256", salt="", len=32) => { | |
if (salt === "") { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const range = (start: number, stop: number, step: number=1) => { | |
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from#Sequence_generator_(range) | |
return Array.from({ length: (stop - start - 1) / step + 1}, (_, i) => start + (i * step)); | |
} | |
export const all = (values: any[]) => { | |
for (let value of values) { | |
if (!value) { | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def zigzag_sorted(iterable, key=None): | |
"""It returns list sorted in zigzag. | |
:rtype: generator object (iterator) | |
>>> list(zigzag_sorted([1, 2, 3, 4, 5, 6, 7])) | |
[1, 7, 2, 6, 3, 5, 4] | |
""" | |
i = 0 | |
l = sorted(iterable, key=key) | |
n = len(l) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
DEFAULT_MULTIPLIERS = { | |
'S': 1, | |
'M': 60, | |
'H': 60 * 60, | |
'd': 60 * 60 * 24, | |
} | |
def time_to_seconds(pattern, target, multipliers={}): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ''} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from string import ascii_uppercase | |
def to_column(number): | |
""" | |
:param int number: 1以上の数値 | |
""" | |
string = '' | |
while True: | |
number -= 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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})', |
NewerOlder