This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function nextID($id) { | |
$avail_chars = $this->config->item('link_id_chars'); //a string, no dupe chars plz. | |
if($id === '') { | |
return $avail_chars[0]; | |
} else if($id[strlen($id)-1] === $avail_chars[strlen($avail_chars)-1]) { | |
return $this->nextID(substr($id, 0, -1)).$avail_chars[0]; | |
} else { | |
return substr($id, 0, -1).$avail_chars[strrpos($avail_chars,$id[strlen($id)-1])+1]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Importer.py | |
/ftp/public | |
Traceback (most recent call last): | |
File "Importer.py", line 65, in <module> | |
importer.import_path(path) | |
File "Importer.py", line 56, in import_path | |
self.import_path(os.path.join(path,entry)) | |
File "Importer.py", line 56, in import_path | |
self.import_path(os.path.join(path,entry)) | |
File "Importer.py", line 56, in import_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# actually not python, just pseudocode highlighted like python. | |
if( len(ints) < 2 ) # if the list is short, just exit | |
return | |
for (i=1; i < len(ints)-1; ++i): # for each of the list entries, from the second to the second to last | |
if ints[i] == ints[i-1] or ints[i] == ints[i+1]: # if the entry to the left or entry to the right is equal to the current one | |
ints[i] = ints[i] + 1 # add one to the current one | |
i = i - 1 # set the cursor back one, because continuing/looping again will cause it to move forward | |
continue # repeat the loop to make sure our +1 change was ok. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
PyDict_MINSIZE = 8 # from dictobject.h | |
class DictDestroyer(object): | |
def __init__(self): | |
self.hash = 1 | |
def __hash__(self): | |
self.hash = random.randint(0, 2**31) | |
return self.hash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(for fixed sized inputs, so not terribly useful. It's VBScript, so also not terribly useful. Also, haven't run this.) | |
Dim myArray(4) | |
myArray(0) = A | |
myArray(1) = B | |
myArray(2) = C | |
myArray(3) = D | |
myArray(4) = E | |
Function MinN( vals ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> import sys | |
>>> xrange(sys.maxint) | |
xrange(9223372036854775807) | |
>>> xrange(sys.maxint+1) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
OverflowError: Python int too large to convert to C long | |
>>> range(sys.maxint+1) | |
Traceback (most recent call last): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>>> class MyException(Exception): | |
.... def pr(self): | |
.... print 'hi' | |
>>>> __builtins__.FutureWarning = MyException | |
>>>> try: | |
.... raise FutureWarning | |
.... except FutureWarning as fw: | |
.... fw.pr() | |
.... | |
hi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from itertools import combinations, chain | |
fun_list = ['a','b','c'] | |
print "\nThe FB way" | |
def subsets(ins, out=None): | |
if out is None: | |
out = [''] | |
if len(ins) == 0: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1245683 function calls (1214448 primitive calls) in 6.210 seconds | |
Ordered by: internal time | |
ncalls tottime percall cumtime percall filename:lineno(function) | |
70411 0.314 0.000 1.316 0.000 re.py:228(_compile) | |
78966 0.222 0.000 0.222 0.000 {method 'match' of '_sre.SRE_Pattern' objects} | |
22563 0.203 0.000 0.375 0.000 lexer.py:64(match_reg) | |
10233 0.186 0.000 1.007 0.000 pygen.py:55(writeline) | |
19780 0.169 0.000 0.541 0.000 statemachine.py:694(make_transition) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# subscribe | |
curl http://pythondoeswhat.superfeedr.com/ --basic -d"hub.mode=subscribe" -d"hub.verify=sync" -d"hub.callback=http://makuro.org:7777/callback" -d"hub.topic=http://www.pythondoeswhat.com/feed/rss.xml" -D- | |
# ping | |
curl -X POST http://pythondoeswhat.superfeedr.com -d"hub.mode=publish" -d"hub.url=http://www.pythondoeswhat.com/feed/rss.xml" -D- | |
# unsubscribe | |
curl http://pythondoeswhat.superfeedr.com/ --basic -d"hub.mode=unsubscribe" -d"hub.verify=sync" -d"hub.callback=http://makuro.org:7777/callback" -d"hub.topic=http://www.pythondoeswhat.com/feed/rss.xml" -D- |
OlderNewer