Skip to content

Instantly share code, notes, and snippets.

@zealinux
zealinux / openpyxl-utils.py
Last active December 5, 2019 04:15
python xlsx to csv
# https://www.studytonight.com/post/converting-xlsx-file-to-csv-file-using-python
# pip install openpyxl
## XLSX TO CSV
import openpyxl
filename = 'appending.xlsx'
## opening the xlsx file
xlsx = openpyxl.load_workbook(filename)
@zealinux
zealinux / change-text-font.py
Last active December 4, 2019 14:23
python-pptx-utils
# https://github.com/scanny/python-pptx/issues/281
paragraph = text_frame.paragraphs[0]
paragraph.text = text
font = paragraph.font
font.color.rgb = RGBColor(...)
@zealinux
zealinux / faraday.md
Created July 19, 2019 09:37 — forked from rummelonp/faraday.md
Ruby の HTTP クライアントライブラリ Faraday が便利そう

Ruby の HTTP クライアントライブラリ Faraday が便利そう

Ruby の HTTP クライアントライブラリ Faraday が便利そう

API ラッパの開発には [RestClient gem][rest_client_gem] だとか
OAuth の必要なものは [Net/HTTP][net_http] + [OAuth gem][oauth_gem] を使ってた

[Twitter gem][twitter_gem] や [Instagram gem][instagram_gem] など API ライブラリのソースを読んでみると
[Faraday gem][faraday_gem] というものがよく使われてた

@zealinux
zealinux / .git-commit-template.txt
Created June 14, 2019 07:24 — forked from jmaxhu/.git-commit-template.txt
一份建议的git commit模板
# <类型>: (类型的值见下面描述) <主题> (最多50个字)
# 解释为什么要做这些改动
# |<---- 请限制每行最多72个字 ---->|
# 提供相关文章和其它资源的链接和关键字
# 例如: Github issue #23
# --- 提交 结束 ---
# 类型值包含
@zealinux
zealinux / download_image.py
Created April 18, 2019 15:06 — forked from mjdietzx/download_image.py
Download image from url and save as file
import io
from PIL import Image # https://pillow.readthedocs.io/en/4.3.x/
import requests # http://docs.python-requests.org/en/master/
# example image url: https://m.media-amazon.com/images/S/aplus-media/vc/6a9569ab-cb8e-46d9-8aea-a7022e58c74a.jpg
def download_image(url, image_file_path):
r = requests.get(url, timeout=4.0)
if r.status_code != requests.codes.ok:
@zealinux
zealinux / pg_random_int_array.sql
Created April 10, 2019 02:01 — forked from ekho/pg_random_int_array.sql
Postgresql function for generating random integer array
CREATE OR REPLACE FUNCTION random_int_array(dim integer, min integer, max integer) RETURNS integer[] AS $BODY$
begin
return (select array_agg(round(random() * (max - min)) + min) from generate_series (0, dim));
end
$BODY$ LANGUAGE plpgsql;
-- usage example
select random_int_array(15, 6, 40);
-- return example
@zealinux
zealinux / gist:5c69e978b316473a9abe2d4ef7630b5a
Created March 26, 2019 08:55 — forked from newhouseb/gist:1620133
MySQL vs PostgreSQL Schema changes benchmarks
The basic idea here is to substantiate the claims made by this square post:
http://corner.squareup.com/2011/06/postgresql-data-is-important.html
In PostgreSQL, and MySQL (MyISAM and InnoDB) I create millions of rows and then add
and remove columns and add and remove indexes. For columns without defaults this is
basically free in PostgreSQL and O(n) in MySQL. For adding indexes its at best O(n)
everywhere, but with PostgreSQL it claims not to do any locking that would otherwise
prevent table interaction.
Also, PostgreSQL has _awsome_ documentation (it has real examples!). I always get
@zealinux
zealinux / org-mode-reference-in.org
Created March 22, 2019 03:42 — forked from drj42/org-mode-reference-in.org
This is a cheat sheet for Emacs org-mode... in org-mode format!
@zealinux
zealinux / tmux-cheatsheet.markdown
Created February 28, 2019 10:16 — forked from ryerh/tmux-cheatsheet.markdown
Tmux 快捷键 & 速查表

注意:本文内容适用于 Tmux 2.3 及以上的版本,但是绝大部分的特性低版本也都适用,鼠标支持、VI 模式、插件管理在低版本可能会与本文不兼容。

Tmux 快捷键 & 速查表

启动新会话:

tmux [new -s 会话名 -n 窗口名]

恢复会话:

@zealinux
zealinux / dict_utils.py
Last active January 11, 2019 08:49
Such as merge two or more dicts to one
def merge_dicts(*dict_args):
"""
Given any number of dicts, shallow copy and merge into a new dict,
precedence goes to key value pairs in latter dicts.
"""
result = {}
for dictionary in dict_args:
result.update(dictionary)
return result