Skip to content

Instantly share code, notes, and snippets.

@lvsl-deactivated
lvsl-deactivated / close_fds.py
Created November 16, 2010 04:44
How to close all files except stdin,stdout,stderr in python
# In case you use some sloppy daemon starter script do this.
os.closerange(3, rosource.RLIMIT_NOFILE)
@lvsl-deactivated
lvsl-deactivated / Литература по Языку Python
Created February 12, 2011 10:05
Язык программирования Python Автор: Р.А. Сузи
http://www.intuit.ru/department/pl/python/
@lvsl-deactivated
lvsl-deactivated / py1 presentation
Created February 12, 2011 17:48
Презентация из первой лекции по Веб-Программированию
https://docs.google.com/viewer?a=v&pid=explorer&chrome=true&srcid=0B_pPOTVD5uBaM2JhYjA2YzItMWQxYy00YWZkLTgzODItM2MxYWFiMjMzMzJj&hl=en
@lvsl-deactivated
lvsl-deactivated / quake_live.py
Created July 5, 2012 21:38
Google CodeJam EuroPython 2012, Problem A "Quake Live" solution
#!/usr/bin/env python
# coding: utf-8
import itertools
def find_min_skill_difference(skills):
n = len(skills)
if n == 2:
return abs(skills[0] - skills[1])
skills.sort()
@lvsl-deactivated
lvsl-deactivated / top_four.py
Created August 12, 2012 10:41
evernote contest
# coding: utf-8
'''
Given an unordered list of N elements, write a function to find the top four elements of the given list. Make sure your function runs in linear time O(N).
Input format :
First line of input contains N , number of elements in list.
Next N line , each contains a element.
@lvsl-deactivated
lvsl-deactivated / circular_buffer.py
Created August 12, 2012 10:42
evernote contest
# coding: utf-8
'''
Implement a circular buffer of size N. Allow the caller to append, remove and list the contents of the buffer. Implement the buffer to achieve maximum performance for each of the operations.
The new items are appended to the end and the order is retained i.e elements are placed in increasing order of their insertion time. When the number of elements in the list elements exceeds the defined size, the older elements are overwritten.
There are four types of commands.
@lvsl-deactivated
lvsl-deactivated / frequent_terms.py
Created August 12, 2012 10:44
evernote contest
# coding: utf-8
'''
Frequency Counting of Words / Top N words in a document.
Given N terms, your task is to find the k most frequent terms from given N terms.
Input format :
First line of input contains N, denoting the number of terms to add.
# coding: utf-8
'''
Given a list of integers, your task is to write a program to output an integer-valued list of equal length such that the output element at index 'i' is the product of all input elements except for the input element at 'i'.
In other words, let inputArray by an integer array of length 'n'. The solution,computed into outputArray, would be:
for each j from 1 to n-2:
outputArr[ j ] = inputArray[0] * inputArray[1] * inputArray[2] * ... * inputArray[j-1] * inputArray[j+1] * inputArray[j+2] *...* inputArray[n-1]
for j = 0
@lvsl-deactivated
lvsl-deactivated / dozer-in-thread-demo.py
Created November 25, 2012 09:10
Using Dozer memory profiler in any python script
from wsgiref.simple_server import make_server
from wsgiref.util import setup_testing_defaults
import random
import threading
import dozer
def run_dozer():
# taken from wsgiref documentation
def simple_app(environ, start_response):
import array
import tracemalloc
from contextlib import contextmanager
@contextmanager
def tracemem(msg):
tracemalloc.start()
snapshot1 = tracemalloc.take_snapshot()
yield
snapshot2 = tracemalloc.take_snapshot()