Skip to content

Instantly share code, notes, and snippets.

@MagicSword
MagicSword / 256colors.py
Created December 7, 2011 06:59
256colors.py
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# FILE: "/home/joze/colors.py"
# LAST MODIFICATION: "Di, 21 Mär 2006 17:02:41 CET (joze)"
# Copyright (C) 2006 by Johannes Zellner, <[EMAIL PROTECTED]>
# $Id:$
import sys
import os
@MagicSword
MagicSword / doc-watch.py
Created January 27, 2012 01:42 — forked from vsajip/doc-watch.py
Sphinx HTML documentation watcher
#!/usr/bin/env python
#
# Copyright (C) 2012 Vinay Sajip. Licensed under the MIT license.
#
# Based on Roberto Alsina's 128-line web browser, see
#
# http://lateral.netmanagers.com.ar/weblog/posts/BB948.html
#
import json
import os
@MagicSword
MagicSword / fetch_pyvideo.py
Created March 16, 2012 17:34 — forked from codeinthehole/fetch_pyvideo.py
Fetch PyCon videos from pyvideo.org and convert them to M4V so they can be synced to your iPhone
# Hacky script for downloading videos from PyVideo and converting them to m4v
# format so they can be synced onto your apple device. Useful if you
# want to see everything that happened at PyCon while commuting.
#
# Requirements:
# * pip install requests BeautifulSoup
# * youtube-dl (from https://github.com/rg3/youtube-dl/) - add this to the
# directory where this script runs and ensure its execute bit is set.
# This was the only YouTube downloader I found that worked. It doesn't
# really have a good Python API so I call it through os.system.

Task list of What

  • Pick the flowers
  • Call John 9303032332
  • Cancel cable subscription
  • Book the flight tickets
@MagicSword
MagicSword / Number2Hans.py.md
Last active April 19, 2018 12:37
利用動態繼承將字串數字轉換成國字 by froce

利用動態繼承將字串數字轉換成國字 by froce

看了這篇手癢,也來寫寫看。 順便練習python的物件導向。(因為我很少用) 目標,將一個字串轉換成 Hans 物件,利用 hans 屬性存取,將字串中的數字轉成正楷國字,並保有 str 的方法。

# Hans物件,繼承str,並初始化。
class Hans(str):
	def __init__(self, string=""):
@MagicSword
MagicSword / jieba-default-mode.py
Created November 4, 2019 19:10
jieba 斷詞 Hello World
#encoding=utf-8
import jieba
sentence = "鼓,可以傳遞訊息、也是一種節奏樂器,在台灣無論是神將團、八家將、官將首、布袋戲這些傳統藝陣技藝項目,還是紅白喜事民俗活動,鼓聲都是不可或缺的重要元素,今天咱們要
跟著祖傳三代的製鼓世家來「講鼓」,講「鼓」早的故事、製鼓的辛苦,聽鼓聲傳千里,振作精神勇往直前!"
print("Input:", sentence)
words = jieba.cut(sentence, cut_all=False)
print("Output 精確模式 Full Mode:")
for word in words:
print(word)
@MagicSword
MagicSword / histogram_gradient_color.py
Created December 9, 2019 13:17
How to set histogram color as a gradient?
# https://stackoverflow.com/questions/59231945/how-to-set-histogram-color-as-a-gradient
def pretty_hist(data, bins, n_loops=8, alpha=1, base_color=[0.121569, 0.466667, 0.705882]):
N, bins, patches = plt.hist(data, bins=bins, density=True)
bm = bins.max()
bins_norm = bins / bm
bc = base_color
for bin_norm, patch in zip(bins_norm, patches):
grad = np.sin(np.pi * n_loops * bin_norm) / 15 + .04