Skip to content

Instantly share code, notes, and snippets.

Avatar
🏡
Playing catch up!

Mahmoud Hashemi mahmoud

🏡
Playing catch up!
View GitHub Profile
@mahmoud
mahmoud / remerge.py
Last active Jun 15, 2016 — forked from pleasantone/remerge.py
Recursively merging dictionaries with boltons.iterutils.remap. Useful for @hynek's configs. https://twitter.com/hynek/status/696720593002041345
View remerge.py
"""
This comes from Mahmoud Hashemi @mhashemi found at:
https://gist.github.com/mahmoud/db02d16ac89fa401b968
This is an extension of the technique first detailed here:
http://sedimental.org/remap.html#add_common_keys
In short, it calls remap on each container, back to front, using the accumulating
previous values as the default for the current iteration.
@mahmoud
mahmoud / cython_pdb.pytb
Last active Mar 17, 2016 — forked from kurtbrose/cython_pdb.txt
Cython is amazing
View cython_pdb.pytb
(Pdb) w
<stdin>(1)<module>()
c:\old_user\workspace\cyopenssl\test\_test.py(117)session_test()
-> tls_c.send('hello')
c:\old_user\workspace\cyopenssl\test\cyopenssl\openssl.pyx(680)cyopenssl.openssl.Socket.send (cyopenssl/openssl.c:6673)()
> c:\old_user\workspace\cyopenssl\test\cyopenssl\openssl.pyx(776)cyopenssl.openssl.Socket._do_ssl (cyopenssl/openssl.c:8320)()
(Pdb) l
771 elif err == SSL_ERROR_SSL:
772 raise SSLError("SSL_ERROR_SSL")
773 elif err == SSL_ERROR_WANT_READ:
View sorrow.py
import os
import random
import threading
import sqlite3
class W(threading.Thread):
def __init__(self, connection):
super(W, self).__init__()
View another.sql
SELECT rc.rc_id,
rc.rc_cur_id,
rc.rc_title,
rc.rc_timestamp,
rc.rc_this_oldid,
rc.rc_last_oldid,
rc.rc_user_text,
rc.rc_old_len,
rc.rc_new_len,
rc.rc_comment
View README.md

This example demonstrates how to add and remove nodes and links from a force layout. The graph initially appears with three nodes A, B and C connected in a loop. Three seconds later, node B is removed, along with the links B-A and B-C. At six seconds, node B is reintroduced, restoring the original links B-A and B-C. This example uses the general update pattern for data joins.

View index.html
<!doctype html>
<meta charset="utf-8">
<title>C3 visualization</title>
<style>
text {
font: 300 16px "Helvetica Neue";
}
View jks.py
'''
JKS file format decoder.
Use in conjunction with PyOpenSSL to translate to PEM, or load private key and certs
directly into openssl structs and wrap sockets.
See http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/sun/security/provider/JavaKeyStore.java#JavaKeyStore.engineLoad%28java.io.InputStream%2Cchar%5B%5D%29
'''
import struct
import hashlib
@mahmoud
mahmoud / pretty_print_xml.py
Created Jul 10, 2012 — forked from anonymous/gist:3079509
Pretty printing XML in Python
View pretty_print_xml.py
from StringIO import StringIO
import xml.etree.cElementTree as ET
def pretty_xml(xml_str, indent=" "):
"""
A very simple, hopefully not simplistic, XML pretty printer.
Concept courtesy Mark Williams.
"""
if not hasattr(xml_str, "read"): # ElementTree uses file-like objects
fn = StringIO(xml_str) # cStringIO doesn't support UTF-8