Skip to content

Instantly share code, notes, and snippets.

View akandratovich's full-sized avatar

Andrei Kandratovich akandratovich

  • Zurich, Switzerland
View GitHub Profile
import javax.inject.Named;
import javax.inject.Singleton;
import org.restlet.Context;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.resource.ResourceException;
import org.restlet.resource.Variant;
import org.sonatype.plexus.rest.resource.AbstractPlexusResource;
import org.sonatype.plexus.rest.resource.PathProtectionDescriptor;
@akandratovich
akandratovich / crop.py
Created September 23, 2011 12:43
Script for cropping pdf books
from pyPdf import PdfFileWriter as pw, PdfFileReader as pr
# crop in_file
in_file = 'file.pdf'
out_file = 'file.crop.pdf'
out_pdf = pw()
in_pdf = pr(file(in_file, 'rb'))
for p in range(in_pdf.getNumPages()):
@akandratovich
akandratovich / T.java
Created December 19, 2011 19:21
Unsafe utility class
import java.lang.reflect.Field;
import sun.misc.Unsafe;
public class T {
public static Unsafe u;
private static long fieldOffset;
private static T instance = new T();
private Object obj;
@akandratovich
akandratovich / RNO.kt
Created February 15, 2012 14:49
Recycled and New Objects Comparison
/**
* Created with IntelliJ IDEA.
* User: Andrew Kondratovich
* Date: 2/13/12
* Time: 3:53 AM
*/
import java.nio.ByteBuffer
import java.util.ArrayList
@akandratovich
akandratovich / gist:2035472
Created March 14, 2012 09:54
crash_report
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6b30107f, pid=5888, tid=5620
#
# JRE version: 7.0-b147
# Java VM: Java HotSpot(TM) Client VM (21.0-b17 mixed mode, sharing windows-x86 )
# Problematic frame:
# V [jvm.dll+0x6107f]
#
[PerfHash Benchmark]
Running PerfHashBenchmark
95% gets, 2% inserts, 2% removes, table_size=1000 ALL
Threads from 10 to 100 by 10
Warmup -variance:
=== CHM_16 2 cnts/sec= 20263610
=== CHM_256 2 cnts/sec= 15084940
=== CHM_4096 2 cnts/sec= 20211076
=== NBHashMap 2 cnts/sec= 14599631
=== LHM 2 cnts/sec= 1807576
@akandratovich
akandratovich / webchat.freenode.net.js
Created March 21, 2012 07:36
show/hide status messages
function info(show) {
var d = 'none';
if (show) d = '';
var xc4 = document.getElementsByClassName('Xc4');
for (var i = 0; i < xc4.length; i++)
xc4[i].parentElement.style['display'] = d;
};
@akandratovich
akandratovich / ls.py
Created March 27, 2012 06:49
generates foldermap, used for dropbox public folder
import os
def write_to(path, content):
f = open(path, 'w')
f.write(content.encode('utf-8'))
f.close()
def make_page(names, pwd):
page = '<body><ul>'
-module(qlct).
-compile([export_all]).
fill(T0, T1, []) -> {T0, T1};
fill(T0, T1, [H | T]) ->
ets:insert(T0, {H, make_ref()}),
ets:insert(T1, {H, make_ref()}),
fill(T0, T1, T).
@akandratovich
akandratovich / gist:3162849
Created July 23, 2012 09:47
fast serialization
// https://github.com/kondratovich/machariel/blob/master/src/main/java/org/machariel/core/serialization/Serializer.java#L34
private Key serializecm(Object object, int depth, ClassMap cm) {
final int size = Reflection.size(object);
final Key ref = allocator.allocate(cm, size - Reflection.MAGIC_SIZE + PTR_OFFSET); // Unsafe.allocateMemory(size)
allocator.put(ref, 0, size); // Unsafe.putInt(pointer, offset, value)
allocator.put(ref, Reflection.ARRAY_INT_INDEX_SCALE, object.getClass().hashCode()); // Unsafe.putInt(pointer, offset, value)
allocator.copy(object, Reflection.MAGIC_SIZE, ref, PTR_OFFSET, size - Reflection.MAGIC_SIZE); // Unsafe.copyMemory(...)
for (int j = 0; j < cm.refs().length; j++) { // in case we have Reference fields