Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
dict = {
0: "часов",
1: "час",
2: "часа",
#!/usr/bin/python
# -*- coding: utf-8 -*-
filename = "dict.csv"
lookup = {}
with open(filename,"r") as file:
for line in file:
(key, value) = line.split(" ")[0:2]
@lazyval
lazyval / sortByBits.scala
Created September 30, 2012 15:20
Sorting integers by the numbers of bits set
/*
You have given n numbers from 1 to n. You have to sort numbers with increasing number of set bits.
Example: n = 5 => Output: 1,2,4,3,5
*/
def numberOfBitsSet(i: Int) = {
// http://en.wikipedia.org/wiki/Hamming_weight implementation
val j = i - ((i >> 1) & 0x55555555);
@lazyval
lazyval / brackets.scala
Created October 3, 2012 17:53
bracket balanicing
object Main extends App {
println(isBalanced("(.)(.)".toList))
def isBalanced(list: List[Char]) = {
@annotation.tailrec
def countBracets(string: List[Char], count: Int = 0): Int = {
string match {
case '('::tail => countBracets(tail, count+1)
case ')'::tail => countBracets(tail, count-1)
@lazyval
lazyval / list.scala
Created October 19, 2012 16:35
Compile time list
trait Base {
protected def contribute : List[String] = List("Beginning")
val list = contribute.reverse
}
trait TrA extends Base {
override protected def contribute = "A" :: super.contribute
}
trait TrB extends TrA {
@lazyval
lazyval / gist:4082827
Created November 16, 2012 00:40 — forked from saetia/gist:1623487
Clean Install – Mountain Lion OS X 10.8
@lazyval
lazyval / assignment.scala
Created November 24, 2012 18:06
Remove the words where last character is a capital letter from a given sentence and then reverse the characters of each word
"FooO bar baZ bow".split(" ").filter(word => word.last >= 'a').map(_.reverse)
@lazyval
lazyval / example.java
Created January 29, 2013 20:24
An example, I've written to show some **very** basic swing constructs to my classmate
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.event.ActionEvent;
public class Foo {
static final JFrame MainWindow = new JFrame();
static final JPanel content = new JPanel(new BorderLayout());
static final JLabel resultFromDialog = new JLabel("SomeText");
@lazyval
lazyval / .gitignore
Last active December 12, 2015 03:38
SML sandbox. I place here most of the stuff, I've done during coursera course. If you don't like **SPOILERS**, please, move along, don't look inside.
.DS_STORE
@lazyval
lazyval / if_statement_without_space.py
Last active December 12, 2015 03:49
Git hook written in python. I had a habit of leaving 'if' statement without following space which really annoyed my collegues. So I've written git hook which checks if there is some nasty ifs, and if so, it will reject commit until I fix an issues.
#!/usr/bin/python
import os
import sys
import re
import subprocess
devnull = open(os.devnull, 'w')