Skip to content

Instantly share code, notes, and snippets.

404 404pnf

Block or report user

Report or block 404pnf

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:eff759380b5e5cbbbc18

Set the Mac OS X SOCKS proxy on the command line

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

View koa.coffee
'use strict'
koa = require 'koa'
app = koa()
note = console.log
time_logger = (next) ->
start = Date.now()
yield next
note "耗时: #{Date.now() - start} 毫秒"
View Linux Static IP
## 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
View lispy-ruby-example-1.rb
# 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!
View partitioner.rb
# 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 = {}
View fizz_buzz.rb
class FizzBuzz
def fizz
loop do
["", "", "Fizz"].each{|s| yield s}
end
end
def buzz
loop do
["", "", "", "", "Buzz"].each{|s| yield s}
View gist:1df153e22b32ca08340d
# 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
@404pnf
404pnf / gist:19b4ef978be621144253
Created May 26, 2014
ruby coll, ascending? and friends
View gist:19b4ef978be621144253
# 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) }
@404pnf
404pnf / gist:10964044
Created Apr 17, 2014
for the sake of another way doing fizbuzz
View gist:10964044
# 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] }
@404pnf
404pnf / timer
Last active Jan 4, 2016
ruby function to time a function
View timer
# 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
You can’t perform that action at this time.