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
@kurtbrose
kurtbrose / f2cmd.py
Created August 25, 2015 04:58
Converts functions into simple commands.
'''
Converts functions into simple commands.
Turns function arguments into command line arguments, and docstrings into helpstrings.
Essentially an argparse shortcutter.
e.g.
@f2cmd.cmd(arg1={"type": int})
def my_main_function(arg1, arg2):
pass
# -*- coding: utf-8 -*-
IRREGULAR_PLURALS = {'alumnus': 'alumni',
'cactus': 'cacti',
'focus': 'foci',
'fungus': 'fungi',
'nucleus': 'nuclei',
'radius': 'radii',
'stimulus': 'stimuli',
'axis': 'axes',
'''
Simple distributed, streaming algorithm for keeping counts on
an adaptive sample of data.
'''
import time
import hashlib
import json
import base64
@reclosedev
reclosedev / parsimonious_json.py
Last active August 29, 2018 19:13
JSON parser implementation using https://github.com/erikrose/parsimonious + simple demo and benchmark.
# -*- coding: utf-8 -*-
import ast
from parsimonious.grammar import Grammar
from parsimonious.nodes import NodeVisitor
json_syntax = r'''
json_file = ws? json ws?
json = object / array
@zzzeek
zzzeek / gist:a3bccad40610b9b69803531cc71a79b1
Last active August 12, 2020 19:24
how to do CIDR overlapping in SQL with SQLite / MySQL / SQLAlchemy
from sqlalchemy import event
from sqlalchemy import DDL
def _mysql_cidr_overlap(metadata):
@event.listens_for(metadata, "after_create")
def _create_mysql_proc(target, connection, **kw):
if connection.engine.name != 'mysql':
return
@SeanHayes
SeanHayes / fabfile.py
Last active September 27, 2020 20:10
Example Fabric fabfile.py. It's a hodgepodge of old scripts and probably isn't best practice (uWSGI ought to have an init script), but it should give you a practical idea of how to use Fabric. This fabfile relies heavily on custom settings from a Django project in order to be more DRY. Includes commands for setting up a fresh Ubuntu Server insta…
# -*- coding: utf-8 -*-
#Copyright (C) 2013 Seán Hayes
import my_project.settings as dj_settings
from fabric.api import local, run, sudo, env, prompt, settings, cd, parallel, execute
from fabric.contrib.files import exists
from fabric.decorators import hosts, roles, runs_once
import json
import logging
import os
@zzzeek
zzzeek / buildy_w_lambdas.py
Last active October 31, 2020 06:34
buildything with lambdas
# note: we are using SQLAlchemy that includes _cache_key
# currently at:
# https://gerrit.sqlalchemy.org/#/c/sqlalchemy/sqlalchemy/+/1204/5/
import typing
from sqlalchemy import bindparam
from sqlalchemy import Column
from sqlalchemy import func
from sqlalchemy import inspection
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kurtbrose
kurtbrose / key_wrap.py
Last active December 28, 2022 13:15
implementation of RFC 3394 AES key wrapping/unwrapping
'''
Key wrapping and unwrapping as defined in RFC 3394.
Also a padding mechanism that was used in openssl at one time.
The purpose of this algorithm is to encrypt a key multiple times to add an extra layer of security.
Personally, I wouldn't recommend using this for most applications.
Just use AES/mode CTR to encrypt your keys, the same as you would any other data.
The time to use this code is when you need compatibility with another system that implements the RFC.
(For example, these functions are compatible with the openssl functions of the same name.)
@audreyfeldroy
audreyfeldroy / pypi-release-checklist.md
Last active February 23, 2023 15:03
My PyPI Release Checklist
  • Update HISTORY.md
  • Commit the changes:
git add HISTORY.md
git commit -m "Changelog for upcoming release 0.1.1."
  • Update version number (can also be minor or major)
bumpversion patch