Skip to content

Instantly share code, notes, and snippets.

View sherifzain's full-sized avatar

Sherif Zain sherifzain

View GitHub Profile

Keybase proof

I hereby claim:

  • I am sherifzain on github.
  • I am sherifzain (https://keybase.io/sherifzain) on keybase.
  • I have a public key ASBqYVOQcTJSCr5edYhnflebGJpsGIwJfLjRQ2PRSVO0hgo

To claim this, I am signing this object:

def _is_anagram(s1, s2):
for c in s1:
if c in s2:
s2 = s2.replace(c, '', 1)
continue
else:
return False
return len(s2) == 0
@sherifzain
sherifzain / memcached_client_hashring.py
Created February 2, 2015 09:29
A modified memcached client that uses HashRing as servers internal data structure, which allows to add memcached servers (instances) at runtime
"""
HINT 1: Run this file first to see how the current implementation of memcache
deals with adding a host.
You'll need to setup 8 running memcached instances on the following ports:
11211
11212
11213
11214
11215
@sherifzain
sherifzain / shortest_sub_segment.py
Created February 2, 2015 09:24
A solution to the shortest sub segment problem
import re
def find_shortest_subsegment(paragraph, words):
words = [word.lower() for word in words]
paragraph_words = re.findall(r"[\w']+", paragraph)
paragraph_words = [word.lower() for word in paragraph_words]
possible_results = []
for pword in paragraph_words:
for result in possible_results:
if not all([True if word in result else False for word in words]):
@sherifzain
sherifzain / rand1to7.py
Created February 2, 2015 09:22
A function to generate a random number from 1 to 7, using another function generating a random number from 1 to 5
#!/usr/bin/python
import random
import unittest
def rand1to5():
return random.randint(1, 5)
def rand1to7():
rand = rand1to5() + rand1to5() - 1
return ((rand % 7) + 1)
@sherifzain
sherifzain / producer.py
Last active August 29, 2015 14:14
Beanstalkd test with Python and Lua workers
import beanstalkc
import gevent
def producer():
beanstalk = beanstalkc.Connection()
# using tube 'test'
beanstalk.use('test')
print('PRODUCER: Starting a producer, putting jobs on "test" tube...')
i = 1
while True:
@sherifzain
sherifzain / sorter.py
Last active August 29, 2015 14:12
Sorter
#!/usr/bin/python
'''
Problem Statement:
You are to write a program that takes a list of strings containing integers and words and returns a sorted version of the list. The output should maintain the positions of strings and numbers as they appeared in the original string (See example 4 below).
The goal is to sort this list in such a way that all words are in alphabetical order and all integers are in numerical order. Furthermore, if the nth element in the list is an integer it must
remain an integer, and if it is a word it must remain a word.