Skip to content

Instantly share code, notes, and snippets.

View selfboot's full-sized avatar
🎯
Focusing

selfboot selfboot

🎯
Focusing
View GitHub Profile
@selfboot
selfboot / article.txt
Created August 12, 2014 15:11
用字典树实现字频统计。
9 Mac OS X Port Command Examples to Install and Update Packages
by Sanjay Kumar, thegeekstuff.comJanuary 23
Port is a terminal command utility which is used to update open source software on Mac OS X.
The port command is bundled as part of MacPorts Framework.
You can install port command either by downloading and installing the binary version for your corresponding Mac OS X, or by downloading the source code and compiling it on your OS X version.
The binary file of MacPorts for various version of OSX are available here. Once you download the binary version, just click on the package to install it. You should have administrator right on your system to install it. X-code is pre-req for MacPorts. If you don’t have X-code on your system, it will display a warning message.
@selfboot
selfboot / coursera_download.py
Created September 2, 2014 12:47
批量下载Coursera上面的课程资源。使用时,我们只需要运行程序,并把课程名称作为参数传递给程序就可以了(这里的课程名称并不是整个课程的完整名字,而是在课程介绍页面地址中的缩略名字,比如Computer Networks这门课,课程名称是comnetworks-002)。
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import requests
from bs4 import BeautifulSoup
import codecs
import string
import random
import re
import getpass
class Solution(object):
def divide(self, dividend, divisor):
"""
:type dividend: int
:type divisor: int
:rtype: int
"""
if divisor == 0:
return -1
@selfboot
selfboot / index.html
Created October 15, 2015 07:41
A simple nw.js based desktop app
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>算法分析作业1:统计页码中单个数字出现的次数</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="main.js"></script>
</head>
[General]
loglevel = notify
skip-proxy = 192.168.0.0/16, 10.0.0.0/8, 172.16.0.0/12, 127.0.0.0/8, 100.64.0.0/10, localhost, *.local, e.crashlytics.com
bypass-tun = 192.168.0.0/16, 0.0.0.0/8, 1.0.0.0/9, 1.160.0.0/11, 1.192.0.0/11, 10.0.0.0/8, 14.0.0.0/11, 14.96.0.0/11, 14.128.0.0/11, 14.192.0.0/11, 27.0.0.0/10, 27.96.0.0/11, 27.128.0.0/9, 36.0.0.0/10, 36.96.0.0/11, 36.128.0.0/9, 39.0.0.0/11, 39.64.0.0/10, 39.128.0.0/10, 42.0.0.0/8, 43.224.0.0/11, 45.64.0.0/10, 47.64.0.0/10, 49.0.0.0/9, 49.128.0.0/11, 49.192.0.0/10, 54.192.0.0/11, 58.0.0.0/9, 58.128.0.0/11, 58.192.0.0/10, 59.32.0.0/11, 59.64.0.0/10, 59.128.0.0/9, 60.0.0.0/10, 60.160.0.0/11, 60.192.0.0/10, 61.0.0.0/10, 61.64.0.0/11, 61.128.0.0/10, 61.224.0.0/11, 100.64.0.0/10, 101.0.0.0/9, 101.128.0.0/11, 101.192.0.0/10, 103.0.0.0/10, 103.192.0.0/10, 106.0.0.0/9, 106.224.0.0/11, 110.0.0.0/7, 112.0.0.0/9, 112.128.0.0/11, 112.192.0.0/10, 113.0.0.0/9, 113.128.0.0/11, 113.192.0.0/10, 114.0.0.0/9, 114.128.0.0/11, 114.192.0.0/10, 115.0.0.0/8, 116.0.0.0/8, 117.0.0.0/9,
@selfboot
selfboot / 7B.R
Last active November 8, 2015 07:05
Mining Massive Datasets Quiz Week7B Basic.
# Question 1
# Suppose we have an LSH family h of (d1,d2,.6,.4) hash functions.
# We can use three functions from h and the AND-construction to form a (d1,d2,w,x) family,
# and we can use two functions from h and the OR-construction to form a (d1,d2,y,z) family.
# Calculate w, x, y, and z, and then identify the correct value of one of these in the list below.
matrix_m <- matrix(c(0,0.5,0.5,0,1,0,0,0,0,0,0,1,0,0,1,0) * 0.7,4,4)
beta_set <- matrix(c(2/3,1/3,0,0,2/3,1/3,0,0,2/3,1/3,0,0,2/3,1/3,0,0) * 0.3, 4, 4)
a <- matrix_m + beta_set
@selfboot
selfboot / 7A.R
Created November 8, 2015 07:50
Mining Massive Datasets Quiz Week7A Advanced.
# First, we index a string of length L on the symbols appearing in its prefix of length floor(0.2L+1). Thus, strings of length 5 and 6 are indexed on their first two symbols, while strings of length 4 are indexed on their first symbol only. Thus, the index for a consists of {s1, s2, s4, s8}; the index for b consists of {s1, s3, s5, s6}, the index for c consists of {s2, s3, s5, s7}, and no other symbol is indexed at all.
# For s1, we examine the indexes for a and b, which contains all strings but s7. Thus, s1 is compared with 6 other strings.
# For s3, we examine the indexes for b and c, which together contain s1, s2, s3, s5, s6, and s7. Thus, s3 is compared with five other strings.
# For s6, we examine only the index for b. Thus, s6 is compared only with the three other strings s1, s3, and s5.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
/*
* Addition in GF(2^8)
* http://en.wikipedia.org/wiki/Finite_field_arithmetic
*/
uint8_t gadd(uint8_t a, uint8_t b) {
return a^b;
@selfboot
selfboot / ProducerConsumer.cpp
Created April 18, 2016 09:41
用信号量实现的生产者消费者问题,OS X 平台
/*
* @Author: [email protected]
* @Last Modified time: 2016-04-18 17:37:33
*/
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <dispatch/dispatch.h>
@selfboot
selfboot / SerializeAndDeserializeBinaryTree.cpp
Created April 27, 2016 00:53
Serialize and Deserialize Binary Tree
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
class Codec {
public:
string serialize(TreeNode* root) {
ostringstream out;