Skip to content

Instantly share code, notes, and snippets.

@corbands
corbands / qsort.py
Created April 17, 2014 19:09
quick sort
def partition(a, p, q):
pivot = a[q-1]
i = p-1
for j in range(p, q-1):
if a[j] < pivot:
i += 1
t = a[j]
a[j] = a[i]
a[i] = t
@corbands
corbands / count_lines_in_files.py
Created January 16, 2014 12:09
считает кол-во строк кода в дереве папок с исходниками (.cpp, .h, .mm) usage: count_lines_in_file <dirname
#!/usr/bin/python
import sys
import os
if len(sys.argv) < 2:
sys.exit('Error! you must give root directory (rel to this dir)')
src_cpp = []
src_mm = []
@corbands
corbands / search_empty_files.py
Created January 16, 2014 12:08
запускается в папке. ищет рекурсивно пустые текстовые файлы
#!/usr/bin/python
import os
import string
i = 0
for dirname, dirnames, filenames in os.walk('days'):
# for subdirname in dirnames:
# print os.path.join(dirname, subdirname)
@corbands
corbands / merged_sort
Created January 15, 2014 22:39
merged sort
#include <iostream>
#include <list>
using namespace std;
void merge(int* arr, int p, int q, int r)
{
list<int> l1(arr + p, arr + q + 1);
list<int> l2(arr + q + 1, arr + r + 1);
@corbands
corbands / insertion_sort
Created January 15, 2014 08:52
insertion sort
#include <iostream>
using namespace std;
int main()
{
int arr[] = {12, 6, 17, 8, 97, 123, 21, 12, 5, 945, 32, 343};
for (int i = 1; i < _countof(arr); ++i)
{
int key = arr[i];
int j = i - 1;
#include <fstream>
#include <string>
#include <boost/thread.hpp>
class Writer
{
public:
Writer(const char* out_filename)
: m_out_filename(out_filename)
#include <fstream>
#include "writer.h"
class WriterManager
{
public:
void Run()
{
std::unique_ptr<Writer> wp(new Writer("out.txt"));