Skip to content

Instantly share code, notes, and snippets.

View hendawy's full-sized avatar

Mohamed Hendawy hendawy

View GitHub Profile
from sqlalchemy.types import TypeDecorator, CHAR
from sqlalchemy.dialects.postgresql import UUID
import uuid
class GUID(TypeDecorator):
"""Platform-independent GUID type.
Uses PostgreSQL's UUID type, otherwise uses
CHAR(36), storing as stringified hex values.
redis-cli -h <host> -p <port> -n <db> KEYS "*pattern*" | xargs -L1 -I '$' echo '"$"'| xargs redis-cli -h <host> -p <port> -n <db> DEL
import uuid
o_u = uuid.uuid4()
u = str(o_u)
cf = u.split('-')
cf[-2] = cf[-2] + cf[-1]
cf.pop(-1)
cf = '-'.join(cf).upper()
h = o_u.hex
@hendawy
hendawy / .vimrc
Last active August 20, 2017 11:09
my epic vimrc
set wildmode=list:longest
set paste
set wildignore=*.pyc,__pycache_,node_modules/*,bower_components/*
set ts=4
set sw=4
set ls=2
set ai
set si
set incsearch
set expandtab
@hendawy
hendawy / simpledb.py
Created February 27, 2015 23:55
A simple in-memory Redis-like data store
"""
Author: Mohamed Hendawy
Last edited: Feb 24 2015
Description: A simple in-memory Redis-like data store
HOW-TO: $ /path/to/python /path/to/simpledb.py < input.file > output.file
To Consider: The output alwas ends with enforced newline, but sometimes text
editors also add a newline to the end of the file
"""
@hendawy
hendawy / largest_subsequence.py
Created February 13, 2015 18:27
Given a list on integers (positive and negative), return the sum of the continues subsequence with largest sum
"""
Given a list on integers (positive and negative), return the sum of the
continues subsequence with largest sum
"""
def largest_subsequence(sequence):
"""
The solution depends on ignoring the sum sequence(j -> i)
if sequence[i+1] > sum sequence(j -> i+1) where j < i and 0 <= i, j < n
@hendawy
hendawy / stairs.py
Last active August 29, 2015 14:15
How many ways to climb n numbers of stairs if you could climb them 1, 2, 3 flights at a time
"""
How many ways to climb n numbers of stairs if you could climb them 1, 2, 3
flights at a time
"""
def stairs(num):
"""
This solution depends on how many ways I could get to any flight of staits.
When I could reach a flight (i) with n ways and I could reach flight (i + 1)