Skip to content

Instantly share code, notes, and snippets.

@LeoShi
LeoShi / interval_store.py
Last active August 29, 2015 13:58
Write a program to do addition of intervals to an interval store
class IntervalStore(object):
def __init__(self):
self.store = []
def filter_result(self, flatten_store, low_index, upp_index):
useless_values = filter(lambda value: low_index < flatten_store.index(value) < upp_index, flatten_store)
flatten_store = filter(lambda value: value not in useless_values, flatten_store)
self.store = []
for i, k in zip(flatten_store[0::2], flatten_store[1::2]):
self.store.append([i, k])
@LeoShi
LeoShi / foo.py
Last active December 26, 2015 12:19
python instance method call class method
class Foo(object):
@classmethod
def here(cls):
print "shit"
Foo().here()
#output: shit
@LeoShi
LeoShi / RemoveMultipleSpaces.cs
Created March 28, 2012 17:15 — forked from Ninputer/RemoveMultipleSpaces.cs
模拟微面试之去空格
//请实现下面的函数,输入参数baseStr是一个(可以更改的)字符串,请将其中所有连续出现的多个空格都替换成一个空格,单一空格需保留。
//请直接使用baseStr的空间,如需开辟新的存储空间,不能超过o(N)(注意是小o,N是字符串的长度)。返回值是替换后的字符串的长度。
//样例代码为C#,但可以使用任何语言。如需使用任何库函数,必须同时给出库函数的实现。
class Program
{
public static int RemoveMultipleSpaces(char[] baseStr)
{
var result = new char[baseStr.Length];
var count = 0;
for (var i = 1; i < baseStr.Length; i++)
@LeoShi
LeoShi / helper.rb
Created January 28, 2012 03:14 — forked from mimosz/helper.rb
帮着优化优化呗~~
def show_props(str)
props = str.split(';') # 切割
if props.is_a?(Array)
str = "<dl class='props'>"
props.each do |property|
prop_arr = property.split(':') # 切割
if prop_arr.is_a?(Array) && prop_arr.count == 4
str += "<dt title='#{prop_arr[0]}'>#{prop_arr[2]}</dt><dd title='#{prop_arr[1]}'>#{prop_arr[3]}</dd>"
else
str += "<dt class='warning'>提示:</dt><dd>无属性</dd>"