Skip to content

Instantly share code, notes, and snippets.

View resolve_name_conflicts_original.php
~~~php
protected static function resolve_name_conflicts($new_parent, $items, $params)
{
$resolve_conflicts_strategy = isset($params['resolve_conflicts_strategy']) ? $params['resolve_conflicts_strategy'] : null;
// there are speical logic for folder creation
$new_items_to_check = isset($params['new_items_to_check']) ? $params['new_items_to_check']: false;
// what does it mean?
$ignore_self_conflicts = isset($params['ignore_self_conflicts']) ? $params['ignore_self_conflicts']: true;
if (!in_array($resolve_conflicts_strategy, array('rename_if_conflicts', 'overwrite_if_conflicts', 'throw_exception')))
{
View python_challenge_q13.py
import xmlrpclib
xmlrpclib.ServerProxy('http://www.pythonchallenge.com/pc/phonebook.php').phone('Bert')
View python_challenge_q12.rb
# 一定要注意,读写文件要强调是二进制
evil = File.open("evil2.gfx", 'rb').read
outputs = (0..4).map { |i| File.open("out#{i}", "wb") }
evil.each_char.with_index { |c, i| outputs[i%5].write(c) }
View python_challenge_q12.py
raw = open('evil2.gfx','rb').read()
for i in range(5):
open('out%d'%i, 'wb').write(raw[i::5])
View python_challenge_q11.rb
require "RMagick"
img = Magick::ImageList.new 'cave.jpg'
r, c = img.rows, img.columns
for i in 0..r-2
for j in 0..c-1
if (i+j).odd?
p = img.get_pixels(j, i+1, 1, 1)
img.store_pixels(j, i, 1, 1, p)
end
end
View python_challenge_q11.py
from PIL import Image
img = Image.open("cave.jpg")
c,r = img.size
pix = img.load()
for j in range(r-1):
for i in range(c):
if (i+j)%2:
pix[i,j] = pix[i,j+1]
img.show()
# 注意也可以用 img.getpixel 和 img.putpixel 来操作像素。
View python_challenge_q10.rb
def f n
n == 0 ? "1":
f(n-1).scan(/(\d)(\1*)/).collect{|i| "#{i[1].size+1}#{i[0]}"}.join
end
puts f(30).size
View python_challenge_q10.py
from re import findall
def f(n):
return "1" if n == 0 else ''.join(
["%d%s"%(len(j)+1, i) for i,j in findall(r'(\d)(\1*)', f(n-1))])
print len(f(30))
View python_challenge_q9.rb
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
View python_challenge_q9.py
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()
You can’t perform that action at this time.