Skip to content

Instantly share code, notes, and snippets.

@prosseek
prosseek / gist:41201d6508f01cf1643e
Last active August 29, 2015 14:20
the numbers 1, 2, ..., 9 (in this order) such that the result is always 100. For example: 1 + 2 + 34 – 5 + 67 – 8 + 9 = 100.
#!/usr/bin/python
# -*- coding: utf-8 -*-
# https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
# http://stackoverflow.com/questions/2136910/can-i-unit-test-an-inner-function-in-python
"""Write a program that outputs all possibilities to put + or - or nothing between the numbers 1, 2, ..., 9 (in this order) such that the result is always 100. For example: 1 + 2 + 34 - 5 + 67 - 8 + 9 = 100.
"""
def cons(head, tails):
"""
@prosseek
prosseek / moniwiki_gen.py
Created February 26, 2014 23:22
Moniwiki generator from markdown
"""
## Goal
This program parses md file to generate moniwiki page.
## Input/Output
>>>
Input:
## 03:07pm - 04:00pm
### [rubichevTask] - [moniwikiGen]
def replace_image_url(self, html):
"""Given html from md that only has 'pic/abc.png' or similar, we return the full path that is
displayable from http address.
1. The file **should** be in the static directory, so the image files should be copied into static directory
2. The image link should be changed to point to that file
"""
if self.image_list:
# Need to create
# from <img alt="pic" src="pic/hello.png"/>
@prosseek
prosseek / getHash.py
Last active December 19, 2015 15:09
Two ways to get hash value
import hashlib
def getHash(key, bytes = 8):
length = len(key)
p = ord(key[0])
x = (p << 7)
for i in range(length):
x = (1000003 * x) ^ ord(key[i]) #^ 0xDEADBEEF
x = x ^ length + 1
return (x % (1 << 8*bytes))
@prosseek
prosseek / findAll.py
Created July 10, 2013 14:04
creates all the python unit tests to be collected and invoked
import unittest
import sys
import os
suiteString = """
def suite():
test_suite = unittest.TestSuite()
{s}
return test_suite
"""