Skip to content

Instantly share code, notes, and snippets.

@airekans
airekans / .emacs-project.sample.el
Last active December 10, 2015 06:48
Sample .emacs-project file
(setl ffip-file-exts '("py" "el"))
@airekans
airekans / testMultiInheritance.cpp
Created December 30, 2012 08:37
Implementaton of Virtual function in multiple inheritance in C++
class Base1
{
public:
Base1() {
m_base1 = 1;
}
virtual ~Base1() {}
virtual Base1* clone()
{
return 0;
@airekans
airekans / interleave_string.py
Created January 8, 2013 07:07
Interleaving string implemented in Python
def interleave(a, b):
if len(a) == 0 and len(b) == 0:
return []
elif len(a) == 0:
return [b]
elif len(b) == 0:
return [a]
first = [a[0] + s for s in interleave(a[1:], b)]
second = [b[0] + s for s in interleave(a, b[1:])]
@airekans
airekans / bak.py
Created January 14, 2013 10:51
Backup and un-backup file in Python
#! /usr/bin/env python
import sys
import os
if __name__ == '__main__':
for f in sys.argv[1:]:
os.system('mv -v %s %s.bak' % (f, f))
@airekans
airekans / square.c
Created January 16, 2013 04:23
Code solving "Square" problem in http://acm.tju.edu.cn/toj/showp1398.html
#include <stdio.h>
#include <stdlib.h>
int st[ 101 ], visited[ 101 ];
int find, num, length, size;
int cmp( const int *f, const int *s )
{
if ( *f > *s )
{
@airekans
airekans / histogram_rect.py
Created January 16, 2013 09:04
Find the max rectangle in the histogram
def max_rect(histogram):
rect_stack = []
result = {"max_area": 0, "range": (-1, -1)}
for i, h in enumerate(histogram + [0]):
if len(rect_stack) == 0 or rect_stack[-1][0] < h:
rect_stack.append((h, i))
elif rect_stack[-1][0] > h:
while len(rect_stack) > 0 and rect_stack[-1][0] > h:
(last_h, last_i) = rect_stack.pop()
@airekans
airekans / setup.py
Created February 5, 2013 08:01
setup.py for python binding of libclang 3.2
#! /usr/bin/env python
from distutils.core import setup
setup(name='clang',
version='3.2',
description='libclang python bindings',
author='clang',
author_email='[email protected]',
url='http://clang.llvm.org',
@airekans
airekans / pylint-git-precommit.py
Last active December 14, 2015 05:58
pre-commit with pylint written by @fitzgen. You can check the script in http://fitzgeraldnick.com/weblog/9/.
#!/usr/bin/env python
"""
A pre-commit hook for git that uses Pylint for automated code review.
If any python file's rating falls below the ``PYLINT_PASS_THRESHOLD``, this
script will return nonzero and the commit will be rejected.
This script must be located at ``$REPO/.git/hooks/pre-commit`` and be
executable.
@airekans
airekans / boot.txt
Created April 3, 2013 16:23
Minix notes
The initial stack of the minix kernel when passing control from boot monitor.
---------
addr of boot image component headers(32)
---------
size of the array of boot parameters(32)
---------
addr of array of boot parameters(32)
---------
boot monitor's code segment(16)
@airekans
airekans / gitlab-toc.py
Created April 7, 2013 09:40
use python-markdown to generate Gitlab compatible TOC.
import markdown
def inc_header(): data = [0]
def fun(x, *rest):
header = 'toc_%d' % data[0]
data[0] += 1
return header
return fun