Skip to content

Instantly share code, notes, and snippets.

@warabanshi
warabanshi / regex-api.py
Last active August 1, 2019 15:41
run `$ python3 regex-api.py` and `$ python3 -m http.server 8080`
#!/usr/bin/python
import re
from urllib import parse
from wsgiref import simple_server
def application(env, start_response):
start_response('200 OK', [
('Content-type', 'text/plain'),
('Access-Control-Allow-Origin', 'http://localhost:8080')
@warabanshi
warabanshi / time.sh
Created July 24, 2019 01:55
just `time` runs internal command of bash. need to input path of time command `/usr/bin/time`
$ /usr/bin/time -f "Memory:%M KB time:%E" ls -alh
...
Memory:3568 KB time:0:00.01
let obj1 = {'key1': 10, 'key2': 20, 'key3': 30, 'key4': 40}
let obj2 = {'key1': 10, 'key3': 30, 'key4': 40}
if (['key1', 'key3', 'key4'].every(key => obj1[key] === obj2[key])) {
console.log('all specified values are same');
} else {
console.log('different values were found');
}
// all specified values are same
class A(NamedTuple):
a1: int
a2: str
a3: str
a4: int
class B(NamedTuple):
a1: int
a3: str
import functools
import operator
r = functools.reduce(operator.mul, range(1,5))
# r = 24
def convert_one_hot(val, vocab_size):
if isinstance(val, (list, )):
return [convert_one_hot(v, vocab_size) for v in val]
base = [0] * vocab_size
base[val] = 1
return base
@warabanshi
warabanshi / simple_server.py
Last active July 26, 2019 04:49
simple python script server
#---------- python2 ----------
#!/usr/bin/python
from wsgiref import simple_server
def application(env, start_response):
start_response('200 OK', [('Content-type', 'text/plain')])
s = ''
@warabanshi
warabanshi / 20170204-dmesg.log
Created February 4, 2017 01:41
raspberrypi3 opensuse Tumbleweed 20161015-Build6.1 dmesg
[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
[ 0.000000] Linux version 4.4.24-3-default (geeko@buildhost) (gcc version 6.2.1 20160830 [gcc-6-branch revision 239856] (SUSE Linux) ) #1 SMP Wed Oct 12 14:23:39 UTC 2016 (1288c77)
[ 0.000000] Boot CPU: AArch64 Processor [410fd034]
[ 0.000000] Getting EFI parameters from FDT:
[ 0.000000] EFI v2.05 by Das U-boot
[ 0.000000] efi: efi: SMBIOS=0x35b14000 efi:
[ 0.000000] No NUMA configuration found
@warabanshi
warabanshi / A.php
Created February 10, 2015 07:47
class dispatching
<?php
class A {
public function response() {
echo "this is class A", "\n";
}
}
class Succ {
public static void main(String[] argv) {
int a = 1;
int b = 3;
System.out.println(a+b);
System.out.println(succ(a));
}
private static int succ(int x) {
return x + 1;