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} |
| # require 'benchmark' | |
| # # ==> true | |
| # def ascending?(data, opts={}) | |
| # return false if data.nil? | |
| # (data.size-1).times do |i| | |
| # if block_given? | |
| # return false if yield(data[i]) > yield(data[i+1]) | |
| # else |
| # my proposal to functional-ruby gem | |
| def in_order?(compare_fn) | |
| -> col, &blk do | |
| if blk | |
| col.map {|e| blk[e] } | |
| .each_cons(2) | |
| .all? { |e1, e2| e1.send(compare_fn, e2) } | |
| else | |
| col.each_cons(2).all? { |e1, e2| e1.send(compare_fn, e2) } |
| # for the sake of another way doing fizbuzz | |
| # must call fiz last since since it returns n by default | |
| >> fiz = -> n { n % 3 == 0 ? 'fiz' : n } | |
| => #<Proc:0x00000101be66d8@(irb):11 (lambda)> | |
| >> buzz = -> n { n % 5 == 0 ? 'buzz' : nil } | |
| => #<Proc:0x00000101bb7a68@(irb):12 (lambda)> | |
| >> fizbuzz = -> n { n % 5 == 0 && n % 3 == 0 ? 'fizbuzz' : nil } | |
| => #<Proc:0x00000102065970@(irb):13 (lambda)> | |
| >> (1..40).map { |e| fizbuzz[e] or buzz[e] or fiz[e] } |
| # found at <https://github.com/jdantonio/functional-ruby/blob/master/lib/functional/utilities.rb> | |
| # Run the given block and time how long it takes in seconds. All arguments | |
| # will be passed to the block. The function will return two values. The | |
| # first value will be the duration of the timer in seconds. The second | |
| # return value will be the result of the block. | |
| # | |
| # @param args [Array] zero or more arguments to pass to the block | |
| # | |
| # @return [Integer, Object] the duration of the operation in seconds and |