Skip to content

Instantly share code, notes, and snippets.

@lufeihaidao
lufeihaidao / python_challenge_q4.sh
Created April 13, 2014 15:19
Q4 of python challenge
ruby -wle 'n = 12345; print n = $1 while
`GET "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=#{n}"`
=~ /(\d+)$/'
@lufeihaidao
lufeihaidao / python_challenge_q5.py
Created April 13, 2014 15:25
Q5 of python challenge
# 推荐的做法
import urllib2, sys, pickle
pickle_data = urllib2.urlopen('http://www.pythonchallenge.com/pc/def/banner.p').read()
data = pickle.loads(pickle_data)
for line in data:
for char, count in line: sys.stdout.write(char * count)
sys.stdout.write("\n")
@lufeihaidao
lufeihaidao / python_challenge_q6.py
Created April 13, 2014 15:27
Q6 of python challenge
f = "channel.zip"
z = zipfile.ZipFile(f)
name = '90052.txt'
while 1:
print z.getinfo(name).comment,
name = z.read(name).split()[-1] + '.txt'
@lufeihaidao
lufeihaidao / python_challenge_q6.rb
Created April 13, 2014 15:28
Q6 of python challenge
require "zip/zip"
zipfilename = "/home/haidao/Downloads/channel.zip"
Zip::ZipFile.open(zipfilename) do |zipfile|
s = zipfile.get_input_stream("readme.txt").read
num = s.match(/\d{2,6}/)
output = Array.new
while num do
entry = zipfile.find_entry("#{num}.txt")
s = entry.get_input_stream.read
num = s.match(/\d{2,6}/)
@lufeihaidao
lufeihaidao / python_challenge_q7.py
Created April 13, 2014 15:39
Q7 of python challenge
import re, Image
im = Image.open("oxygen.png")
row = [im.getpixel((x, 47)) for x in range(0, im.size[0], 7)]
chrs = [chr(r) for r, g, b, a in row if r == g == b]
s = ''.join(chrs)
print ''.join(map(chr, map(int, re.findall(r'\d+',s))))
@lufeihaidao
lufeihaidao / python_challenge_q7.rb
Created April 13, 2014 15:40
Q7 of python challenge
require "RMagick"
Magick::ImageList.new("oxygen.png").get_pixels(0,45,629,1).map.with_index
{|p,i| (p.red/255).chr if i%7==0)}.join.scan(/\d+/){|c| print c.to_i.chr }
@lufeihaidao
lufeihaidao / python_challenge_q8.py
Created April 13, 2014 15:42
Q8 of python challenge
import bz2
un = "un 的字符串内容,表示 user name"
pw = "pw 的字符串内容,表示 password"
print bz2.decompress(un), bz2.decompress(pw)
@lufeihaidao
lufeihaidao / python_challenge_q8.rb
Created April 13, 2014 15:42
Q8 of python challenge
require 'bzip2'
un = "同上,需要用双引号括起来"
pw = "同上,需要用双引号括起来"
puts Bzip2.uncompress(un), Bzip2.uncompress(pw)
@lufeihaidao
lufeihaidao / python_challenge_q9.py
Created April 13, 2014 15:44
Q9 of python challenge
from PIL import Image, ImageDraw
img = Image.new("RGB",(640,480), 'white')
draw = ImageDraw.Draw(img)
draw.polygon(first_list, 'black')
draw.polygon(second_list, 'grey')
img.show()
@lufeihaidao
lufeihaidao / python_challenge_q9.rb
Created April 13, 2014 15:45
Q9 of python challenge
require "RMagick"
img = Magick::ImageList.new 'good.jpg'
gc = Magick::Draw.new
gc.fill('#CC6600')
gc.polygon(*first_list)
gc.fill('white')
gc.polygon(*second_list)
gc.draw(img)
img.display