Skip to content

Instantly share code, notes, and snippets.

View ddimtirov's full-sized avatar
👺
I may be slow to respond.

Dimitar Dimitrov ddimtirov

👺
I may be slow to respond.
  • Tokyo, Japan
  • 22:31 (UTC +09:00)
View GitHub Profile
package org.junit.tests.running.methods;
import org.junit.Test;
import org.junit.runner.Description;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import java.util.ArrayList;
@ddimtirov
ddimtirov / SlidingWindowMap.groovy
Created September 3, 2012 10:37
Coding challenge: a sliding window map
import java.util.concurrent.DelayQueue
import java.util.concurrent.Delayed
import java.util.concurrent.TimeUnit
class SlidingWindowMap {
private periodMs
private available = new DelayQueue<DelayedKey<String>>()
SlidingWindowMap(Set<String> keys, int maxCount, long periodMs) {
this.periodMs = periodMs
@ddimtirov
ddimtirov / dashboard.html
Created October 16, 2012 00:45
PerceptualEdge.com dashboard design contest 2012 entry
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Dashboard</title>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<link rel='stylesheet' href='//fonts.googleapis.com/css?family=Open+Sans:300,600' type='text/css'>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/2.0/css/font-awesome.css" >
@ddimtirov
ddimtirov / WrongSeatSimulation.java
Created October 30, 2013 15:01
Imagine people boarding a plane and the first one sits at the wrong place. Every next one sits at his own place if it is available, or at a random place if not. What is the chance that the last person boarded sits at his own place?
import java.util.Arrays;
import java.util.Random;
public class WrongSeatSimulation {
private static final int AVAILABLE = -1;
static boolean simulate(Random rnd, int numberOfSeats) {
int[] seats = new int[numberOfSeats];
Arrays.fill(seats, AVAILABLE);
@ddimtirov
ddimtirov / Plus64.java
Created November 2, 2013 06:41
Simple utility to convert from old Bulgarian DOS cyrillic to Windows 1251 text encoding.
import java.io.*;
/**
* Simple utility to convert from old Bulgarian DOS cyrillic to Windows 1251 text encoding.
* <pre>
* Usage: java Plus64 inputfile outputfile
* </pre>
* @author dimiter@blue-edge.bg
* @since Mar 3, 2003 1:15:33 AM
*/
@ddimtirov
ddimtirov / PythonEmbeddedExample.java
Created November 2, 2013 06:46
Shows how to embed Jython and use it as a code generator to create dynamic classes with runtime-defined behavior. Circa 2002.
import org.python.util.PythonInterpreter;
import org.python.core.*;
public class PythonEmbeddedExample {
private static final String EOL = "\n";
private static final PythonInterpreter INTERP = new PythonInterpreter();
private static final String I = "\t";
public static void main(String[] args) throws PyException {
exchangeObjects();
@ddimtirov
ddimtirov / IpOperator.java
Created November 2, 2013 06:49
A mini echo-server, I used for testing connectivity through mobile operator proxies. Feb 21, 2004
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class IpOperator {
public static void main(String[] args) throws IOException {
int port = 80;
@ddimtirov
ddimtirov / fixcyr.py
Created November 2, 2013 06:54
Another script translating from one non-standard Cyrillic code page to another (by adding offset). This time in python. Circa 2004
#!/usr/bin/python
# -*- coding: windows-1251 -*-
r"""
:Authors: Dimitar A. Dimitrov
:Contact: dimiter[at]blue[dash]edge[dot]bg
:Copyright: This work is licensed under the X license.
For the full text of the license see http://www.opensource.org/licenses/xnet.php
:Version: 0.1
:Date: 2004-08-22
@ddimtirov
ddimtirov / latinizator.pyw
Created November 2, 2013 06:56
Transliterating Cyrillic text and preparing it for publishing to mailing lists. Useful for crappy non-Unicode mailing lists like Yahoo Groups. Easy to customize.
#!/usr/bin/python
# -*- coding: utf-8 -*-
r"""
:Authors: Dimitar A. Dimitrov
:Contact: dimiter[at]blue[dash]edge[dot]bg
:Dedication: To the I18N team at Yahoo! Inc.
:Copyright: This work is licensed under the X license.
For the full text of the license see http://www.opensource.org/licenses/xnet.php
:Version: 0.1
@ddimtirov
ddimtirov / Benchmark.java
Created November 2, 2013 07:01
Flawed benchmark for reflection performance of Java. Don't do this. Circa 2005.
import java.util.Date;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
public class Benchmark {
public static int method(int parameter) {
return parameter%3 > 2 ? System.identityHashCode(new Date()) : -1;
}