Skip to content

Instantly share code, notes, and snippets.

View dboyliao's full-sized avatar

dboyliao dboyliao

View GitHub Profile
import sys
def main():
n = int(sys.argv[1])
to_ignore = set([])
nums = [j for j in range(n, 0, -1)]
nums += [j for j in range(2, n + 1)]
for i in range(1, n + 1):
to_print = [str(j) if j not in to_ignore else " " for j in nums]
@dboyliao
dboyliao / gist:9af0c929a9f254338941e443520f0d85
Created July 20, 2019 10:03 — forked from bessarabov/gist:674ea13c77fc8128f24b5e3f53b7f094
One-liner to generate data shown in post 'At what time of day does famous programmers work?' — https://ivan.bessarabov.com/blog/famous-programmers-work-time
git log --author="Linus Torvalds" --date=iso | perl -nalE 'if (/^Date:\s+[\d-]{10}\s(\d{2})/) { say $1+0 }' | sort | uniq -c|perl -MList::Util=max -nalE '$h{$F[1]} = $F[0]; }{ $m = max values %h; foreach (0..23) { $h{$_} = 0 if not exists $h{$_} } foreach (sort {$a <=> $b } keys %h) { say sprintf "%02d - %4d %s", $_, $h{$_}, "*"x ($h{$_} / $m * 50); }'
@dboyliao
dboyliao / pycairo_chinese.py
Created April 10, 2019 07:12 — forked from virus-warnning/pycairo_chinese.py
讓 pycairo 可以正常顯示中文的賤招,需要利用 wxPython
import subprocess
import cairo
import wx
import wx.lib.wxcairo
WIDTH = 400
HEIGHT = 300
surface = cairo.ImageSurface(
#!/usr/bin/env python
# a python copy of thanos JS (https://thanosjs.org/)
from __future__ import print_function
import importlib
import os
import random
import sys
@dboyliao
dboyliao / main.py
Last active August 29, 2018 14:52
argparse example part 2
#!/usr/bin/env python3
# coding: utf8
import sys
import subprocess
import argparse
from pathlib import Path
def ls(path, flags=None):
if not flags:
@dboyliao
dboyliao / python-closures.py
Created August 3, 2018 03:04 — forked from DmitrySoshnikov/python-closures.py
Understanding Python's closures
# "Understanding Python's closures".
#
# Tested in Python 3.1.2
#
# General points:
#
# 1. Closured lexical environments are stored
# in the property __closure__ of a function
#
# 2. If a function does not use free variables

Refined Code for Bryan's blog post

@dboyliao
dboyliao / .gitignore
Last active March 5, 2018 06:48
Pinkoi sharing material: Google Optimize and Bayesian estimation
*.pdf
private_*
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dboyliao
dboyliao / profile_callgrind.py
Last active December 31, 2017 07:17
profiling example with yap
#!/usr/bin/env python3
# -*- coding:utf8 -*-
import random
from collections import namedtuple
from itertools import combinations
from string import ascii_letters
import pandas as pd
import funcy as fy
import yappi