dd if=/dev/urandom of=/tmp/testFile bs=1M count=500 & watch -n 1 -d 'ls -lh /tmp/testFile'
Don't try this with /dev/random or it will take forever.
Length: 524288000 (500M) [application/octet-stream] Saving to: `./testFile' 100%[============================================================================>] 524,288,000 90.8M/s in 5.2s 2015-06-12 11:55:00 (96.7 MB/s) - `./testFile' saved [524288000/524288000] real 0m5.289s user 0m0.137s sys 0m1.950s
testFile 100% 500MB 33.3MB/s 00:15 real 0m14.233s user 0m11.118s sys 0m4.453s
receiving incremental file list testFile sent 30 bytes received 524543976 bytes 13987840.16 bytes/sec total size is 524288000 speedup is 1.00 real 0m37.000s user 0m13.829s sys 0m3.601s
virtualenv is the Python 2 tool to interact with virtual environments and won't be discussed here. I'll focus on Python 3 tools and methods only.
The Python 3 tool to manage virtual environments is venv, which —depending on your distro / version :
(myVirtualEnvironmentName)
showing the virtual environment is enabled.
#!/usr/bin/env python3 class Person(object): def __init__(self, firstName, lastName, age): self.firstName = firstName self.lastName = lastName self.age = age def getItem(self, itemName): return getattr(self, itemName) user = Person('John', 'Smith', 42) for item in [ 'firstName', 'lastName', 'age' ]: print(user.getItem(item))will display :
John Smith 42
some python code
is code stored in a fileimport math print(math.pow(2,38))
274877906944.0
Next level : http://www.pythonchallenge.com/pc/def/274877906944.html
inTable = 'KOE' outTable = 'MQG' message = 'KOE' print(message.translate({ord(x): y for (x, y) in zip(inTable, outTable)}))
MQG
List comprehensions provide a more concise way to create lists in situations where nested loops would currently be used.
print({x: y for (x, y) in zip(inTable, outTable)})
{'K': 'M', 'E': 'G', 'O': 'Q'}
print({ord(x): y for (x, y) in zip(inTable, outTable)})
{75: 'M', 69: 'G', 79: 'Q'}
inTable = 'abcdefghijklmnopqrstuvwxyz' outTable = 'cdefghijklmnopqrstuvwxyzab' message = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj." print(message.translate({ord(x): y for (x, y) in zip(inTable, outTable)}))
i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url.
inTable
and outTable
strings :
import string inTable = string.ascii_lowercase outTable = string.ascii_lowercase[2:] + string.ascii_lowercase[:2]
Next level : http://www.pythonchallenge.com/pc/def/ocr.html
The question is in the HTML source :
find rare characters in the mess below: %%$@_$^__#)^)&!_+]!*@&^}@[@%]()%+$&[(_@%+%$*^@$^!+]!&_#)_*}{}}!}_]$[%}@[{_@#_^{* @##&{#&{&)*%(]{{([*}@[@&]+!!*{)!}{%+{))])[!^})+)$]#{*+^((@^@}$[**$&^{$!@#$%)!@(& +^!{%_$&@^!}$_${)$_#)!({@!)(^}!*^&!$%_&&}&_#&@{)]{+)%*{&*%*&@%$+]!*__(#!*){%&@++ !_)^$&&%#+)}!@!)&^}**#!_$([$!$}#*^}$+&#[{*{}{((#$]{[$[$$()_#}!@}^@_& ...
localFile='./level02.txt'; >"$localFile"; wget -O "$localFile" http://www.pythonchallenge.com/pc/def/ocr.html; sed -i '38,1257 !d' "$localFile"; sed -ri 'sa[][)({}@%&$_+*^#!]aag' "$localFile"; sed -i '/^$/ d' "$localFile"; tr '\n' '\0' < "$localFile"
Next level :
#!/usr/bin/env python3 import lxml.etree as ET dom = ET.parse('data.xml') xslt = ET.parse('stylesheet.xsl') transform = ET.XSLT(xslt) newdom = transform(dom) print(ET.tostring(newdom, pretty_print=True))
import datetime from datetime import datetime, timedelta timeFormat = '%Y-%m-%d %H:%M:%S' now = datetime.now() print(now.strftime(timeFormat)) future = now + timedelta(seconds=500) print(future.strftime(timeFormat))