Skip to content

Instantly share code, notes, and snippets.

View hirokiky's full-sized avatar

Hiroki Kiyohara hirokiky

View GitHub Profile
<script>
directives: {
'inner-height': {
bind: function() {
this.el.addEventListener('load', () => {
var doc = this.el.contentDocument || this.el.contentWindow.document;
this.el.style.height = doc.body.scrollHeight + 'px';
});
}
}
@hirokiky
hirokiky / phparray.py
Created July 15, 2017 01:47
Imitiating array of PHP by Python (just a joke)
from collections import OrderedDict
class PHPArray(OrderedDict):
def __init__(self):
super().__init__()
self.next_max_index = 0
def __setitem__(self, key, val):
if isinstance(key, int):
@hirokiky
hirokiky / wine.ipynb
Created August 1, 2017 09:06
wanted to know what makes high quality wines.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hirokiky
hirokiky / retry.py
Created October 29, 2017 14:36
retry.py
import functools
import time
def retry(exception, max_retry, sleep, err_handler):
""" Catching exception and retrying
"""
def dec(f):
@functools.wraps(f)
def _wrapped(*args, **kwargs):
@hirokiky
hirokiky / screenShotWindow.html
Created November 7, 2017 07:24
Taking Screen Shots of main window from child popup window.
<html>
<head>
<script src="/js/html2canvas.min.js"></script>
</head>
<body>
<button class="screen-shot">ScreenShot</button>
<script>
var btn = document.querySelector('.screen-shot');
btn.addEventListener("click", function() {
if (!window.opener || window.opener.closed) {
@hirokiky
hirokiky / plt.ipynb
Last active December 27, 2017 09:08
Importing matplotlib.pyplot and calling show() method won't work properly. Originally reported by @SaitoTsutomu
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hirokiky
hirokiky / custom.js
Created March 14, 2018 03:46
tried to inject Authorization header for each request, but couldn't.
// This way didn't work.
// Cause this custom.js or nbextensions files will be loaded after initializing JupyterNotebookApp.
// It means this code won't affect to it's initializing Ajax requests.
// Sending token on each XHRs too.
// Because Safari won't handle Cookie and localStorage
// on iframes.
// Jupyter Client expects it's cookie, so it will be forbidden
// Instead, sending "token" by manually on each XHRs.
@hirokiky
hirokiky / dirtydecector.py
Created April 26, 2018 05:44
Detecting changes of model field values.
""" Detect changes of Django Models.
"""
class ChangeDetector:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._dirty_fields = {f: False for f in self._get_field_names()}
self._inited = True
@hirokiky
hirokiky / recursiveClass.js
Last active February 4, 2019 11:27
experiment
> class F {
... constructor (a) {
..... if (a > 0) {
....... this.child = new F(a-1)
....... }
..... }
... }
undefined
> new F(3)
F { child: F { child: F { child: F {} } } }
@hirokiky
hirokiky / dataclass_model.py
Last active February 22, 2019 07:56
Model (for validators, ORM, form library) by using dataclass
from dataclasses import dataclass, field as dc_field
# Library
def field(default, verbose_name="", help_text=""):
return dc_field(
default=default,
metadata={