Skip to content

Instantly share code, notes, and snippets.

View mahmoud's full-sized avatar
Back on the grid!

Mahmoud Hashemi mahmoud

Back on the grid!
View GitHub Profile
@mahmoud
mahmoud / remerge.py
Last active June 15, 2016 09:57 — forked from pleasantone/remerge.py
Recursively merging dictionaries with boltons.iterutils.remap. Useful for @hynek's configs. https://twitter.com/hynek/status/696720593002041345
"""
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 March 17, 2016 22:17 — forked from kurtbrose/cython_pdb.txt
Cython is amazing
(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:
@mahmoud
mahmoud / README.md
Last active December 20, 2015 22:49 — forked from mbostock/.block

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.

<!doctype html>
<meta charset="utf-8">
<title>C3 visualization</title>
<style>
text {
font: 300 16px "Helvetica Neue";
}
@mahmoud
mahmoud / jks.py
Created August 7, 2013 06:03 — forked from kurtbrose/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
import os
import random
import threading
import sqlite3
class W(threading.Thread):
def __init__(self, connection):
super(W, self).__init__()
@mahmoud
mahmoud / pretty_print_xml.py
Created July 10, 2012 07:42 — forked from anonymous/gist:3079509
Pretty printing XML in Python
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
@mahmoud
mahmoud / another.sql
Last active August 29, 2015 14:24 — forked from slaporte/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