Skip to content

Instantly share code, notes, and snippets.

@precious
precious / FixedMapExample.java
Created December 8, 2011 23:54
map of fixed size (removes eldest by access elements)
import java.util.LinkedHashMap;
import java.util.Map;
class FixedMap<K,V> extends LinkedHashMap<K,V> {
private int max_capacity;
public FixedMap(int initial_capacity, int max_capacity) {
super(initial_capacity, 0.75f, true);
this.max_capacity = max_capacity;
}
@precious
precious / pdf-trim-to-djvy.sh
Created December 24, 2011 20:05
This script trims white margins out of PDF document and packs it to DjVu
#!/bin/bash
# vim: set fileencoding=utf-8 ts=2 sw=2 expandtab:
# PUBLIC DOMAIN
# This script trims white margins out of PDF document and packs it to DjVu.
# Author Sergei Astanin http://sovety.blogspot.com/
# Modified by Vsevolod K. https://github.com/precious
### Settings
@precious
precious / adjvold.py
Created January 12, 2012 17:26
dbus service for volume adjusting with an optional GTK progressbar
#!/usr/bin/env python
# adjvold -- dbus service for volume adjusting with an optional GTK progressbar
#
# Copyright (C) 2009 Adrian C. <anrxc_sysphere_org>
# Modified by 2011 Seva K. <vs.kulaga_gmail_com>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
REM ***** BASIC *****
Option Explicit
Sub Main
Dim oDocument
Dim oSelectedCells
Dim oActiveCells
Dim oSheet
@precious
precious / test.html
Created May 22, 2012 00:29
function to read file inside JS
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script>
function handleFileSelect(input,callback) {
// used links:
// http://www.w3.org/TR/file-upload/
@precious
precious / khizha acl2 tasks
Created October 25, 2012 00:03
funcs.lisp
(defun natural (a)
(and (integerp a) (> a 0))
)
(defun fib (x)
(if (and (integerp x) (>= x 0))
(if (< x 2)
1
(+ (fib (- x 1)) (fib (- x 2)))
)
#!/usr/bin/python
# -*- coding: utf-8 -*-
from math import *
import sys
# generator for values [a,b] with step 'step'
def frange(a,b,step):
while a <= b:
yield a
a += step
children(Parent,L) :- findall(Next,parent(Parent,Next),L).
ancestors(Child,L) :- findall(Next,parent(Next,Child),L).
repr_internal(Elem,L,R) :- (L == [] -> ancestors(Elem,R); children(Elem,R)).
repr_retval(Elem,R) :- children(Elem,L), repr_internal(Elem,L,R).
repr(Elem):- repr_retval(Elem,R), write(R).
read_line_pls(L) :- read_line(X),string_to_atom(X,L).
main :-
delim(){
if [ -n "`/home/precious/programming/c/git_branch/git-br`" ]; then
echo '|'
fi
}
export PS1='\[\e[0;36m\]$?\[\e[0m\]|\[\e[0;31m\]`/home/precious/programming/c/git_branch/git-br`\[\e[0m\]$(delim)\[\e[0;35m\]\u\[\e[0m\]:\[\e[0;34m\]\w\[\e[0m\]\$ '
@precious
precious / minifier.py
Last active December 24, 2016 20:06
bash scripts minifier
#!/usr/bin/python
import sys
class BashFileIterator:
def __init__(self, src):
self.src = src
self.reset()
def reset(self):