Skip to content

Instantly share code, notes, and snippets.

@zdway10
zdway10 / letters-to-100.py
Created March 17, 2020 15:25 — forked from xiaolai/letters-to-100.py
Find English words whose letter values add up to 100
#!/usr/bin/env python
# encoding: utf-8
"""
letters-to-100.py
"""
import string
letter_values = dict((l, i) for i, l in enumerate(string.lowercase, start=1))
english_dict = open('/usr/share/dict/words', 'rU')
@zdway10
zdway10 / Personal Library.md
Created March 17, 2020 15:26 — forked from xiaolai/Personal Library.md
My own library
  1. Download and pin books at https://read.amazon.com, and use epubor KCR converter to convert them into epubs.
  2. Download audio books at https://audible.com, with aax format.
  3. Obtain your activation bytes with the instruction of this post.
  4. Install ffmpeg with brew.
  5. Install audible-converter with npm. (File name will be extended automatically)
audible-converter "*.aax" -a <your-activation-bytes>
  1. Install atomicparsley with brew. (to add artwork to converted m4a files) Bash script to add artworks to m4a files:
@zdway10
zdway10 / gist:742699146fb45b929245782964653543
Created March 17, 2020 15:27 — forked from xiaolai/gist:2ffe003b05eb3a2f7ba933858d353d7d
search and replace all mal-rendered emphasized text in github markdown
search regex:
~*(?:^|[^~])(~~(\\w+(\\s\\w+)*)~~)
# replace with (attention: there's a white space at the end)
**$1**
@zdway10
zdway10 / Style.css
Created March 17, 2020 15:27 — forked from xiaolai/Style.css
vscode markdown github preview custom style
.vscode-body .markdown-body {
font-family: "PingFang SC"
}
.vscode-body strong {color:#6392BF;}
.vscode-body em {color: #A9312A; font-style: normal !important;}
.vscode-body table {font-size: 95% !important;}
.vscode-body .CodeMirror, .vscode-body pre {font-size: 90%;}
.vscode-body pre {
@zdway10
zdway10 / jupyter-as-a-desktop-app.md
Created March 17, 2020 15:28 — forked from xiaolai/jupyter-as-a-desktop-app.md
Run Jupterlab as an desktop app

How to run Jupyterlab as a desktop app on Mac OSX

Tiered of opening terminal to launch Jupyterlab, and having to leave it opened all the time? Try to run Jupyterlab as a desktop app:

nativefier-jupyterlab

One of a benefits is avoiding the annoying accident: "closed Jupyterlab when quitting the browser".

1. Install Anaconda for mac

Run in Terminal

# install anaconda
jupyter-lab --generate-config
edit ~/.jupyter/jupyter_notebook_config.py, add lines:
c.NotebookApp.token = '' #you can set password here.
#https://github.com/jiahaog/nativefier
npm install nativefier -g
nativefier "http://localhost:8888"
@zdway10
zdway10 / mc-pi.rb
Created March 17, 2020 15:30 — forked from xiaolai/mc-pi.rb
compute pi by Monte-Carlo method.
=begin
Find pi by the Monte-Carlo method.
area of a circle = pi r^2
area of a square = (2r)^2 = 4 r^2
Perform random uniform sampling between -1 and 1.
The proportion of points in the unit circle is:
p = (pi r^2) / (4r^2)
@zdway10
zdway10 / mpipypi.py
Created March 17, 2020 15:30 — forked from xiaolai/mpipypi.py
Compute Pi using Python and MPI4PY
"""
This code computes pi. It's not the first python
pi computation tool that I've written. This program
is a good test of the mpi4py library, which is
essentially a python wrapper to the C MPI library.
To execute this code:
mpiexec -np NUMBER_OF_PROCESSES -f NODES_FILE python mpipypi.py
@zdway10
zdway10 / brew.md
Created March 17, 2020 22:52 — forked from xiaolai/brew.md
homebrew upstream repo for China
# 替换brew.git:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git

# 替换homebrew-core.git:
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git

# 替换homebrew-bottles:
@zdway10
zdway10 / pi_mp.py
Created March 17, 2020 22:53 — forked from xiaolai/pi_mp.py
Parallel Pi Calculation using Python's multiprocessing module
''' listing 6: pi_mp.py
Multiprocessing based code to estimate the value of PI
using monte carlo sampling
Ref: http://math.fullerton.edu/mathews/n2003/montecarlopimod.html
Uses workers:
http://docs.python.org/library/multiprocessing.html#module-multiprocessing.pool
'''
import random