Skip to content

Instantly share code, notes, and snippets.

Avatar
🏡
Playing catch up!

Mahmoud Hashemi mahmoud

🏡
Playing catch up!
View GitHub Profile
View nextID.php
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];
}
}
View importer v0.1 output
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
@mahmoud
mahmoud / mattslist.py
Created May 10, 2011
this is terrible, but it'll probably work
View mattslist.py
# 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.
@mahmoud
mahmoud / gist:1044311
Created Jun 24, 2011
python dict destruction
View gist:1044311
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
@mahmoud
mahmoud / vbscript_list_min.vbs
Created Jul 18, 2011
VBScript List creation and Min findin'
View vbscript_list_min.vbs
(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 )
@mahmoud
mahmoud / gist:1169652
Created Aug 25, 2011
range() and xrange() limits
View gist:1169652
>>> 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):
@mahmoud
mahmoud / pypy_exc.py
Created Oct 14, 2011
pypy Exception games
View pypy_exc.py
>>>> class MyException(Exception):
.... def pr(self):
.... print 'hi'
>>>> __builtins__.FutureWarning = MyException
>>>> try:
.... raise FutureWarning
.... except FutureWarning as fw:
.... fw.pr()
....
hi
@mahmoud
mahmoud / subsets.py
Created Oct 28, 2011
Some subset fun.
View subsets.py
#!/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:
@mahmoud
mahmoud / profiled_generate.txt
Created Jan 25, 2012
PythonDoesBlog profiler output
View profiled_generate.txt
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)
@mahmoud
mahmoud / pubsubhubbub_ugh.txt
Created Feb 7, 2012
superfeedr derp stuff
View pubsubhubbub_ugh.txt
# 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-