Skip to content

Instantly share code, notes, and snippets.

View mckabi's full-sized avatar
😼
물거나 해칠 수 있습니다

McK KIM mckabi

😼
물거나 해칠 수 있습니다
View GitHub Profile
@mckabi
mckabi / locales.js
Last active April 11, 2024 07:06
Language names
/*
* Based cldr-44.1.0-json-modern
*
* - [Tags for Identifying Languages (BCP47)](https://www.ietf.org/rfc/bcp/bcp47.txt)
* - [List of ISO 639 language codes](https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes) (WikiPedia)
* - [Unicode CLDR Project](https://cldr.unicode.org/)
*/
/** @typedef {string} LocaleCode */
@mckabi
mckabi / dummy_server.py
Last active October 9, 2023 04:16
Dummy API Server with boom style error response
#!/usr/bin/env python3
import html
import json
import socketserver
import sys
from datetime import datetime
from http import HTTPStatus
from http.server import SimpleHTTPRequestHandler
from time import mktime
@mckabi
mckabi / LICENSE
Created April 20, 2021 23:53 — forked from wlib/LICENSE
Run a shell script with bash, line-by-line, prompted on each command. Useful for running unknown scripts or debugging. Not a secure substitute for understanding a script beforehand.
MIT License
Copyright (c) 2021 Daniel Ethridge
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@mckabi
mckabi / posthtml.config.js
Last active April 20, 2021 23:54
snowpack + posthtml
module.exports = (ctx) => {
return {
parser: ctx.ext ==='.sml' ? 'posthtml-sugarss' : false,
from: ctx.from,
to: ctx.to,
path: ctx.cwd || './src',
plugins: ctx.plugins || {},
}
}
#!/usr/bin/env python3
import contextlib
import gzip
import sys
from itertools import zip_longest
from urllib.parse import urlparse
import boto3
from botocore.exceptions import NoCredentialsError
def humanize_bytes(nbytes, output_format='%.2f %s%s', suffix=None):
if suffix is None:
suffix = 'iB'
basis = 1024.0 if suffix == 'iB' else 1000.0
for unit in ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z']:
if abs(nbytes) < basis:
return output_format % (nbytes, unit, suffix)
nbytes /= basis
return output_format % (nbytes, 'Y', suffix)
@mckabi
mckabi / drf_urls.py
Last active October 25, 2019 00:11
DRF router.register(CustomViewSet(parameters, …))
"""
Django REST Framework router + ViewSet + parameters
- https://www.django-rest-framework.org/api-guide/routers/
"""
class OriginViewSet(ModelViewSet):
...
@classmethod
def as_custom_viewset(cls, **kwargs):
class CustomViewSet(cls):
document.querySelectorAll("td[colspan=full]").forEach(td => {
const table = td.closest("table");
const columns = table.querySelector("tr").querySelectorAll("th, td");
const column_count = Array.from(columns).reduce((acc, cell) => acc + (cell.getAttribute('colspan') || 1), 0);
td.setAttribute('colspan', column_count);
});
document.querySelector('input[type=email]').addEventListener('keyup', event => {
const element = event.target;
const valueParts = element.value.split('@');
if (element.getAttribute('list') && document.getElementById(element.getAttribute('list'))) {
document.getElementById(element.getAttribute('list')).remove();
}
if (valueParts.length > 1 && valueParts[0] && valueParts[1]) {
const suggestionsId = (element.id || element.name) + 'Suggestion';
const suggestions = makeDatalist(suggestionsId, valueParts[0], valueParts[1]);
@mckabi
mckabi / Dockerfile
Created December 15, 2018 14:15
pipenv + docker
FROM python:3.7
RUN apt-get -qq update && \
apt-get -q -y upgrade && \
DEBIAN_FRONTEND=noninteractive apt-get install -y locales locales-all
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
#ENV PYTHONDONTWRITEBYTECODE 1