over 5 years ago

Wise words from Abraham J. Twerski:https://www.youtube.com/watch?v=vn2twFwjNQE


  • we are not going to always make the right decision
  • Decisions have to be made with integrity
  • Our desires color our decisions (most desires come from animalistic traits), the first thing you should think is why you should not do it
  • Not making a decision is a decision (which is the worst becauses others will decide for you which will not be in your interest)
  • Getting the best possible information, having self-confidence, pray, not to be shaken if the decision does not turn out to be right, not to see it as a horrible failure on our part
  • Our decisions are good or bad are determined by how we made them not what the consequences were.
over 5 years ago
  1. 如果你的电脑没有蓝牙接收器,购买一个USB蓝牙接收器
  2. 保证Airpods在充电盒内,打开盖子,长按盒子后面的按钮,看到指示灯是白色的闪烁状态
  3. 下载这个蓝牙驱动(否则连接上后无法通过Airpod说话,只能听声音):https://download.lenovo.com/ibmdl/pub/pc/pccbbs/mobiles/h1bn01ww.exe
  4. 在Windows设置里找到 设备 》 蓝牙 , 然后右键点击Airppods选择连接
  5. 连接成功后在Windows开始栏右下角的喇叭上点击左键,然后在下拉菜单里选择 “耳机(蓝牙音频)”,这个时候调试声音大小就应该可以从Airpods里听到声音了
  6. 右键点击Windows开始栏右下角的喇叭,选择“录音设备”,应该可以看到 “耳机式麦克风”有个绿色的对勾,在它上面点击右键 》 配置语音识别 》 设置麦克风 》 头戴式麦克风 》 下一步 》 阅读一段话调整音量 (不做这个设置的话,你直接去录音应用里可能会听不到声音)
  7. 完成
almost 6 years ago

选择Ubutu 14.04版本。配置完youtube可以保证720p。

1) 更新OS:

sudo apt-get update && sudo apt-get upgrade -y

2) 安装SS

apt-get install python-pip
pip install shadowsocks

3) 创建SS的配置文件, 该文件可以放在任何地方,一般放在 /etc/ 这个文件夹下,所以执行下列命令

cd /etc
nano shadowsocks.json


    "local_address": "",
    "fast_open": true

4) 安装谷歌BBR:

wget --no-check-certificate https://github.com/teddysun/across/raw/master/bbr.sh
chmod +x bbr.sh

5) 更新sysctl.config文件(/etc/sysctl.conf),在底部增加下列选项:

fs.file-max = 51200
net.core.rmem_max = 67108864
net.core.wmem_max = 67108864
net.core.netdev_max_backlog = 250000
net.core.somaxconn = 4096
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.ip_local_port_range = 10000 65000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_fastopen = 3
net.ipv4.tcp_mem = 25600 51200 102400
net.ipv4.tcp_rmem = 4096 87380 67108864
net.ipv4.tcp_wmem = 4096 65536 67108864
net.ipv4.tcp_mtu_probing = 1


sysctl -p

6) 更新rc.local 确保哪怕重启fast tcp open也有效:

nano /etc/rc.local


echo 3 > /proc/sys/net/ipv4/tcp_fastopen

7) 开启SS服务:

sudo ssserver -c /etc/shadowsocks.json -d start


sudo ssserver -c /etc/shadowsocks.json -d stop
about 6 years ago
  1. Download from .DMG file from the official MySQL site

  2. Doulbe click the .DMG file and follow the install instruction, at the end of the installation, take note of the pop up window that shows your root password

  3. Once installed, open System Preferences

  4. Find MySQL and click on Start MySQL Server

  5. open Terminal, and enter mysql see if it gives you an error, if it did, enter the following:

ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
  1. In Terminal, type mysql -u root -p, press enter, then enter the default password you wrote down in step #2

  2. Once you are in the mysql command prompt, enter the following to change your default password for the root account and prevent it from expiring:

ALTER USER `root`@`localhost` IDENTIFIED BY 'new_password', `root`@`localhost` PASSWORD EXPIRE NEVER;
  1. still in the mysql command prompt, create a database so that you can play with:
create database_name;
use database_name;


P.S. If you prefer to use a GUI to interact with MySQL on MacOS, download Sequel Pro (it is FREE)

Thanks to the following SO posts:

over 6 years ago

The behavior of passing an integer, string, slicing, list of integers, list of strings to a DataFrame:

df[0] # error

df['col_0'] # A Series of col_0

# The following behaviors are downright confusing

df[0:1] # A DataFrame of row 0

df[[0]] # A DataFrame of col 0

df[['col_0']] # A DataFrame of col 0


  • If a slicing or a list is passed, a DataFrame object is returned

    • If a slicing is passed, a DataFrame of rows are returned
    • If a list is passed, a DataFrame of cols are turned
  • If a String is passed, a Series of a column is returned

almost 7 years ago

I was trying to do this in Python 3:

t = {'1': 1, '2':2}

#Trying to sort the dictionary t by its value

       key=lambda (k,v): v,  # the left bracket raises syntax error, it works in python 2 but not 3


It turns out that in Python 3, tuple parameter unpacking is not supported anymore.

So if more than one parameter is passed into a lambda function, we have to access it like a list:

lambda parameters: parameters[0], parameters[1], parameters[2]

So for the issues I have, the correct code would be:

       key=lambda k_v: k_v[1],  
about 7 years ago

When I was trying to use Chinese characters for a chart's title, matplotlib displayed a bunch of squares. Here are the steps to solve it.

Step 1: Find matplotlibrc

I am using virtualenv, so for me the path is:


The key part is /lib/python3.5/site-packages/matplotlib/mpl-data

Step 2: Modify matplotlibrc

Uncomment font.family and font.sans-serif, then add the following fonts before Bitstream Vera Sans:

PingFang SC, Hiragino Sans GB, Microsoft YaHei,

It should look like this:

font.sans-serif     : PingFang SC, Hiragino Sans GB, Microsoft YaHei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif

If you have a ipyton notebook open, you have to close and reopen it to make this change effective. Otherwise this is it :D

about 7 years ago

Install Python3

  1. Install brew: http://brew.sh/
  2. Install Python3 via brew: brew install python3
  3. Vertify Python3 is installed: which python3 (should be located at: /usr/local/Cellar/python3/)

Install virtualenv and virtualenvwrapper

  1. pip3 install virtualenv virtualenvwrapper
  2. create a fold to store all of the virtual environments:
cd ~
mkdir .envs

`3. setup virtualenvwrapper by putting the following into .bash_profile:

export WORKON_HOME=~/.envs # point to the .envs fold created above
export VIRTUALENVWRAPPER_PYTHON=/usr/local/Cellar/python3/3.5.2_1/bin/python3   # make sure this is the python version you want to point to
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh

Then run .bash_profile to reflect the chagnes:

. ~/.bash_profile

Now everythiing should be set to go:

mkvirtualenv env_name


about 7 years ago

I have actually found a bug in Django:

Here is the issue: You cannot have a cookie which key contains either the character '[' or ']'

I discovered the solution following @Todor's link, then I found out about this SO post. Basically there was a bug in python 2.7.x that does not parse cookies with ']' in the value. The bug was fixed in 2.7.10.

I thought it would be good to just confirm this issue. So I dug through all of the cookies and found one with the following key/value:

key: BDRCVFR[feWj1Vr5u3D]
val: I67x6TjHwwYf0

So I inserted the following cookie locally and submitted to the server:

key: test
val: BDRCVFR[feWj1Vr5u3D]

The login page worked, which means 2.7.10 indeed fixed the bug.

But then I realized that the square brackets are actually in the key name not in the value, so I did the following tests:

key: [
val: I67x6TjHwwYf0


val: I67x6TjHwwYf0

Both cookies break the login process and django displays:

CSRF cookie not set

If a invalid cookie comes before the csrftoken cookie in the Cookie field of the http request header, then Django will ignore everything after the invalid cookie, which makes Django think that the CSRF cookie is not set

I filed a bug report to Django. This bug is fixed in version 1.10 so make sure you update Django when 1.10 is released.

about 7 years ago

Found a great SO post on this topic:

When the [[Construct]] property for a Function object F is called, the following steps are taken:

  1. Create a new native ECMAScript object.
  2. Set the [[Class]] property of Result(1) to "Object".
  3. Get the value of the prototype property of F.
  4. If Result(3) is an object, set the [[Prototype]] property of Result(1) to Result(3).
  5. If Result(3) is not an object, set the [[Prototype]] property of Result(1) to the originalObject` prototype object as described in
  6. Invoke the [[Call]] property of F, providing Result(1) as the this value and providing the argument list passed into [[Construct]] as the argument values.
  7. If Type(Result(6)) is Object then return Result(6).
  8. Return Result(1).

Let me translate that into code:

function Person() {}
var p1 = new Person();

//step 1

var newObj = {}

//step 2: I don't know what [[Class]] property is and I cannot find any reference so I will skip this step

//step 3:

var functionProto = Person.prototype;

if (typeof functionProto === 'object'){
    //step 4:

    newObj.__proto__ = functionProto;
} else {
    //step 5:

    newObj.__proto = Object.prototype;

//step 6:

Person.call(newObj, arguments);

if (typeof newPerson === 'object'){
    //step 7:

    return newPerson;
} else {
    //step 8:

    return newObj;

You can add an return statement in the constructor to hijack what it returns:

function Person(){
    return {};

var p1 = new Person(); // p1 is just a plain object not an instance of Person

If the returned object is not an object, then step 8 kicks in:

function Person(){
    return 2;

var p1 = new Person(); // p1 is an instance object of Person instead of 2