Skip to content

Instantly share code, notes, and snippets.

@uranusjr
uranusjr / better-python-env.md
Last active June 8, 2023 14:11
Toward a better Python installation

Toward a better Python installation

Meta

想要的特質

  • 不會太污染 PATH
  • 盡可能避免要求 root/admin 權限
  • 可以同時安裝多個版本(只需要到 minor,不須 patch)
  • 可以輕鬆啟動任意一個版本的 Python,不須多餘設定,版本之間也不會互相衝突
* {
font-family: sans-serif;
}
h2 {
font-size: 200%;
margin-bottom: 4px;
text-align: center;
border-bottom: 1.4px solid;
padding-bottom: 8px;
}
@uranusjr
uranusjr / print_primes.md
Last active April 24, 2023 06:44
輸入一數字 n,印出 2 到 n 之間的質數。

知道一個數字是不是質數的方法是:

如果 n 不是質數,那麼 n 一定有一個小於等於 n 的因數。

所以我們可以用下面的程式判斷輸入的 n 是否為質數:

def is_prime(n):
    for i in range(2, n):
        if n % i == 0:  # 整除,i 是 n 的因數,所以 n 不是質數。
@uranusjr
uranusjr / rpi-qt5-cc.md
Last active May 7, 2019 14:35
在 Ubuntu 16.04 為 Raspbian Jessie 交叉編譯 Qt 5.6 桌面版

在 Ubuntu 16.04 為 Raspbian Jessie 交叉編譯 Qt 5.6 桌面版

筆記

Qt 在 Raspberry Pi 上可以跑兩種版本:

  • 桌面版。你平常在 Linux 發行版裡看到的會是這個,包含 Raspbian 在內。通常基於 X11,就是個普通的 GUI 框架。
  • 嵌入版。這個版本不需要鐘面系統,通常是直接走 framebuffer 直接把東西畫到螢幕上,適合一些嵌入式設備的應用。

這個教學會編譯桌面版,因為我對這個版本比較熟。我上次試的時候 OpenGL 在 embedded 版還有些問題,不過 Qt 在那之後有很多更新,狀況應該會好很多。Qt 官方 wiki 也有個相關的教學:

@uranusjr
uranusjr / mathjax-autonumbering.css
Created August 12, 2015 09:37
CSS-base auto-numbering for MathJax
body {
counter-reset: equation;
}
.MathJax_Display:after {
font-family: serif;
counter-increment: equation;
content: "(" counter(equation) ")";
position: absolute;
right: 0;
}
@uranusjr
uranusjr / README.md
Last active September 17, 2017 20:48
用 QTableView 與 QAbstractTableModel 與 Qt 的 Model-View 概念做出類似檔案總管的效果 https://www.ptt.cc/bbs/C_and_CPP/M.1435018167.A.85C.html

注意:需要用 Qt 5 跑。Qt 4 要稍微改一下 .pro 檔。

@uranusjr
uranusjr / raii.py
Last active August 29, 2015 14:23
Wrapper implementing RAII idiom for ctypes objects.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import weakref
__all__ = ['CObjectWrapper']
# Keeps a reference to all wrapper instances so that we can dealloc them when
# we need to.
@uranusjr
uranusjr / accountant.py
Created May 30, 2015 23:48
Starting point for the accountant project.
def _show_items(items):
template = '{name:20}{price:>5}'
if not items:
print("No items. Use 'add' to add some!")
return
print()
print(template.format(name='Item', price='Price'))
print('-' * 25)
for item in items:
print(template.format(
@uranusjr
uranusjr / api.py
Last active August 29, 2015 14:21 — forked from mrjohannchang/api.py
import functools
class Api:
def __init__(self):
self.apis = []
def register(self, f):
self.apis.append(f.__name__)
@uranusjr
uranusjr / create-env.vbs
Last active September 16, 2018 16:49
Django Girls Taipei 專用 Windows 環境設定程式。需要 Windows 7 以上。若你使用 Windows Vista 或更舊的版本,請聯絡助教。
' Requirements:
' * Windows 7 or later. (Might work on Vista and XP.)
' * Python 3 installation. (Will prompt for installation path.)
' The installation path should be both readable and *writable*.
' * msysGit installation.
Function GetPath(ByVal prompt)
' Collect path.
path = InputBox(prompt)