a.k.a. what to do when your ISP starts blocking sites :(
Set the SOCKS proxy to local SSH tunnel
networksetup -setsocksfirewallproxy "Ethernet" localhost 8080
To clear the domain and port
| 'use strict' | |
| koa = require 'koa' | |
| app = koa() | |
| note = console.log | |
| time_logger = (next) -> | |
| start = Date.now() | |
| yield next | |
| note "耗时: #{Date.now() - start} 毫秒" |
| ## Configure eth0 | |
| # | |
| # vi /etc/sysconfig/network-scripts/ifcfg-eth0 | |
| DEVICE="eth0" | |
| NM_CONTROLLED="yes" | |
| ONBOOT=yes | |
| HWADDR=A4:BA:DB:37:F1:04 | |
| TYPE=Ethernet | |
| BOOTPROTO=static |
| # treating a function as data | |
| putter = ->(message) { puts message } | |
| def deliver_message(message, handler) | |
| handler.(message) | |
| end | |
| deliver_message("Hello, code as data!", putter) | |
| # => Hello, code as data! |
| # Very (very) naive wordt segmentation algorithm for Chinese | |
| # (or any language with similar characteristics, works at the | |
| # character level.) | |
| class Partitioner | |
| attr_reader :ngrams | |
| # +ngrams+ Enumerable list of ngrams | |
| def initialize(ngrams, lookahead = 6) | |
| @lookahead = lookahead | |
| @ngrams = {} |
| class FizzBuzz | |
| def fizz | |
| loop do | |
| ["", "", "Fizz"].each{|s| yield s} | |
| end | |
| end | |
| def buzz | |
| loop do | |
| ["", "", "", "", "Buzz"].each{|s| yield s} |
| # pnodes => path | |
| # ppath => parent | |
| class Zipper | |
| attr_reader :parent, :path, :node, :lefts, :rights, :at_end | |
| def initialize(branch, children, make_node, node, lefts = nil, path = nil, parent = nil, rights = nil, changed = false, at_end = false) | |
| @branch = branch | |
| @children = children | |
| @make_node = make_node |
| class Tree | |
| attr_accessor :children, :node_name | |
| def initialize(name, children={}) | |
| @children = children | |
| @node_name = name | |
| end | |
| def visit_all(&block) | |
| visit &block |
| # Generate all possible combinations for a 46-point win in the game of | |
| # Goofspiel. | |
| # | |
| cards = [*1..13] | |
| res = [*4..13].map do |n| | |
| cards.combination(n). | |
| select { |cards| cards.reduce(:+) == 46 }. | |
| map(&:sort). | |
| map(&:reverse) |
| #!/usr/bin/env python | |
| import sys | |
| import urllib2 | |
| import simplejson | |
| def get_info(adress): | |
| print "************************************************" | |
| api = "http://freegeoip.net/json/" + adress | |
| try: |