三星ADV考试题(Tunnel Construction)

好久没有写东西啦。
因为前两天和同学一起玩的很开心,于是就索性放纵了自己一下下,把写东西的任务暂时抛掷脑后了。
前天花花给我发来了一道新鲜出炉的算法题,奈何我已经好久不写这种东西了,所以一路过程十分曲折。打算记录一下,权当好玩。
题目是图片版的,讲道理看的非常不爽。原文链接在这里:http://www.cnblogs.com/linux0537/p/6163158.html

s = [1, 4, 1, 3, 11]
c1 = 7
r1 = 2
c2 = 2
r2 = 6
ans = float("inf")
for i in range(0, len(s)+1):
    offset = 0
    result = 0
    if len(s) - 2*i > 0: offset = r2*(len(s)-2*i-1)
    if len(s) - 2*i < 0: offset = r1*(2*i-len(s)-1)
    for l in range(0, i): result += c1*s[l]
    for r in range(i,len(s)): result += c2*s[r]
    if (result + offset) < ans: ans = result + offset
print ans

python生成器(generator)

今天心血来潮想刷Leetcode,发现了一道没有AC的Easy题。无脑Gank掉之后突然想起来生成器来做的话,效率可能会高一点,所以趁机也温习了一下生成器。

def fizzBuzz(n):
    for i in range(1, n+1):
        if i % 15 == 0:
            yield "FizzBuzz"
        elif i % 5 == 0:
            yield "Buzz"
        elif i % 3 == 0:
            yield "Fizz"
        else:
            yield str(i)
tt = fizzBuzz(16)
try:
    print(tt.next())
except Exception,e:
    pass

Python黑魔法——一行实现多线程

在 Python 中有个两个库包含了 map 函数: multiprocessing 和它鲜为人知的子库 multiprocessing.dummy.
这里多扯两句: multiprocessing.dummy? mltiprocessing 库的线程版克隆?这是虾米?即便在 multiprocessing 库的官方文档里关于这一子库也只有一句相关描述。而这句描述译成人话基本就是说:”嘛,有这么个东西,你知道就成.”相信我,这个库被严重低估了!
dummy 是 multiprocessing 模块的完整克隆,唯一的不同在于 multiprocessing 作用于进程,而 dummy 模块作用于线程(因此也包括了 Python 所有常见的多线程限制)。
所以替换使用这两个库异常容易。你可以针对 IO 密集型任务和 CPU 密集型任务来选择不同的库。

import urllib2
from multiprocessing.dummy import Pool as ThreadPool
urls = [
 'http://www.python.org',
 'http://www.python.org/about/',
 'http://www.onlamp.com/pub/a/python/2003/04/17/metaclasses.html',
 'http://www.python.org/doc/',
 'http://www.python.org/download/',
 'http://www.python.org/getit/',
 'http://www.python.org/community/',
 'https://wiki.python.org/moin/',
 'http://planet.python.org/',
 'https://wiki.python.org/moin/LocalUserGroups',
 'http://www.python.org/psf/',
 'http://docs.python.org/devguide/',
 'http://www.python.org/community/awards/'
 # etc..
 ]
 # Make the Pool of workers
 pool = ThreadPool(4)
 # Open the urls in their own threads
 # and return the results
 results = pool.map(urllib2.urlopen, urls)
 #close the pool and wait for the work to finish
 pool.close()
 pool.join()

Leetcode 461. Hamming Distance

The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
Given two integers x and y, calculate the Hamming distance.
Note:
0 ≤ xy < 231.
Example:

Input: x = 1, y = 4
Output: 2
Explanation:
1   (0 0 0 1)
4   (0 1 0 0)
       ↑   ↑
The above arrows point to positions where the corresponding bits are different.
class Solution(object):
def hammingDistance(self, x, y):
    """
    :type x: int
    :type y: int
    :rtype: int
    """
    str_x = bin(x)
    str_y = bin(y)
    count = 0
    if len(str_x) <= len(str_y):
    str_x, str_y = str_y, str_x
    for i in range(1, len(str_y)-1 ):
        if str_x[-i] != str_y[-i]:
            count += 1
    for i in range(len(str_y)-1, len(str_x)-1):
        if str_x[-i] == "1":
            count += 1
    return count

我的站点是不是有点Low啊~~

看了几个著名网红的Blog,发现这群家伙各种轮子用的溜得飞起,页面也炫酷无比。
再回头看看我这个基本没怎么修葺过的原始Wordpress,真™不好意思。
不过话说回来,我一个后台狗和那帮前端狗争这个干嘛~ ~
打算等回学校了换装Typecho,抽空得搞一个导入工具了。

锐速是个好东西

昨天VPN用的不顺心,怒拿Vultr搭了个SS服务。
看Youtube测试了一下,基本上看480P就有点吃力了。于是在91yun上找到了锐速的破解版。这东西可以无视拥塞协议,泰迪发包。
安装的过程中还出了一点小插曲,Centos 7的内核版本有点超前了,于是强行降了内核,成功安装。
安装之后再测试,发现1080P已经无压力了。
Nice~

终极Terminal

这两天发现ZSH、tmux再加上Vim简直天作之合啊!
ZSH可以用Oh-my-Zsh来搞定
tmux的话我觉得有这最关键的几行配置就够了:

setw -g mouse-resize-pane on
setw -g mouse-select-pane on
setw -g mouse-select-window on
setw -g mode-mouse on

少数派报告——树莓派搭建Tor匿名站点

Tor介绍

Tor is free software and an open network that helps you defend against traffic analysis, a form of network surveillance that threatens personal freedom and privacy, confidential business activities and relationships, and state security.
如果需要了解更多请看 Tor官方网站

树莓派介绍

The Raspberry Pi is a tiny and affordable computer that you can use to learn programming through fun, practical projects.
如果需要了解更多请看 Raspberry Pi官方网站

序言

众所周知,现在国内上网需要掌握许多种科学上网的方法。最近还要封杀VPN了,简直过分。这两天看了不少网上搭建Tor匿名站点的方法,但大都鱼龙混杂,而且并没有考虑到我国的”特殊国情”。在经过两天的奋斗之后,我终于搞定了整套流程,现在把它记录在这里,希望可以帮到大家。

Continue reading

Linux渗透提权脚本

在以一个低权限进入系统之后,我们通常需要利用系统的不当配置将权限进行提升。
下面是一个我觉得还不错的脚本,用Python写的。
现在一般服务器上也都带着Python,所以使用起来很方便。

https://github.com/Elfsong/WintersWrath/blob/master/python/linuxprivchecker.py