Skip to content

Instantly share code, notes, and snippets.

View hirokiky's full-sized avatar

Hiroki Kiyohara hirokiky

View GitHub Profile
@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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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 / 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 / wine.ipynb
Created August 1, 2017 09:06
wanted to know what makes high quality wines.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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):
<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 / agg.py
Created April 28, 2017 05:13
List of dict => dict of dict aggregator.
import statistics
class Field:
def __init__(self, field, agg_func=lambda l: l[0]):
self.field = field
self.agg_func = agg_func
def aggregate(self, l):
return self.agg_func(l)
@hirokiky
hirokiky / backorbeginning.el
Last active March 17, 2017 02:58
back-or-beginning: C-a back to indentation, and then back to begining of lines.
;; Moving start line and start indend by C-a
(defun back-to-indentation-or-beginning () (interactive)
(if (= (point) (progn (back-to-indentation) (point)))
(beginning-of-line)))
(global-set-key "\C-a" 'back-to-indentation-or-beginning)
@hirokiky
hirokiky / jsonify.js
Created February 25, 2017 11:21
Jsonify tree objects
toJson() {
return JSON.stringify(this, (key, value) => {
if (key == 'parent') {
return value.id;
} else {
return value;
}
});
}
@hirokiky
hirokiky / customadmin.md
Created December 3, 2016 02:11
TokyoDjangoMeetup

models.py

class MyUser(AbstractUser):
    idstaff = models.CharField(max_length=255)

    class Meta:
        db_table = 'myuser'
        swappable = 'AUTH_USER_MODEL'