Skip to content

Instantly share code, notes, and snippets.

View xiaolai's full-sized avatar
🎯
Focusing

xiaolai xiaolai

🎯
Focusing
View GitHub Profile
@xiaolai
xiaolai / gist:3817378
Created October 2, 2012 08:35
add utf-8 support to rspec.rb file
# encoding: UTF-8
require 'spec_helper'
// Node.js CheatSheet.
// Download the Node.js source code or a pre-built installer for your platform, and start developing today.
// Download: http://nodejs.org/download/
// More: http://nodejs.org/api/all.html
// 0. Synopsis.
// http://nodejs.org/api/synopsis.html
@xiaolai
xiaolai / iterm2 changing font-size
Created June 3, 2016 13:49
iTerm2 changing font-size between 18-24
cd ~/Library/Preferences/
open com.googlecode.iterm2.plist
@xiaolai
xiaolai / letters-to-100.py
Created October 21, 2017 06:22 — forked from peterjmag/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')
@xiaolai
xiaolai / gist:2ffe003b05eb3a2f7ba933858d353d7d
Created February 6, 2020 12:00
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**
@xiaolai
xiaolai / gist:cef9c92caa9c252fe6aaa3f43cecb102
Created February 2, 2019 04:04
Run Jupterlab as an desktop app
# 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"
@xiaolai
xiaolai / mc-pi.rb
Created October 19, 2017 01:48 — forked from shitsyndrome/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)
@xiaolai
xiaolai / mpipypi.py
Created October 19, 2017 01:48 — forked from jcchurch/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
@xiaolai
xiaolai / brew.md
Created March 16, 2020 17:23
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:
@xiaolai
xiaolai / pi_mp.py
Created October 19, 2017 01:48 — forked from amitsaha/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