Skip to content

Instantly share code, notes, and snippets.

View vaskoz's full-sized avatar
🏠
Working from home

Vasko Zdravevski vaskoz

🏠
Working from home
View GitHub Profile
@vaskoz
vaskoz / dns.go
Created May 11, 2015 02:58
Golang dynamic linking for DNS resolution
package main
import "net"
func main() {
net.Dial("tcp", "google.com:80")
}
@vaskoz
vaskoz / ldd.txt
Created May 11, 2015 03:08
Non-DNS Go version
ldd test
not a dynamic executable
[raft] 2015/05/12 22:34:35 leader[2]: leaderLoop: send heartbeat: index: idx=4, idxs=[4]
[raft] 2015/05/12 22:34:35 leader[2]: leaderLoop: send heartbeat: index: idx=4, idxs=[4 4]
panic: test timed out after 1m0s
goroutine 503 [running]:
testing.func·008()
/usr/local/Cellar/go/1.4.2/libexec/src/testing/testing.go:681 +0x12f
created by time.goFunc
/usr/local/Cellar/go/1.4.2/libexec/src/time/sleep.go:129 +0x4b
public class TooSmall {
public static void main(String[] args) {
double start = 0.1;
double tooSmall = 1.0e-18;
for (int i = 0; i < 1_000_000_000; i++) {
start += tooSmall;
}
System.out.println(start == 0.1); // TRUE
}
}
@vaskoz
vaskoz / Quicksort.java
Created June 7, 2015 00:35
Implementation of Quicksort in Algorithms in a Nutshell
import java.util.Comparator;
public class Quicksort {
public static void sort(Comparable<?>[] data, int left, int right) {
if (left < right) {
int pi = partition(data, left, right);
sort(data, left, pi-1);
sort(data, pi+1, right);
}
}
import java.util.Stack;
public class StackedQuicksort {
public static void sort(Comparable<?>[] data, int left, int right) {
Stack<Integer> stack = new Stack<>();
stack.push(left);
stack.push(right);
while (!stack.empty()) {
right = stack.pop();
left = stack.pop();
@vaskoz
vaskoz / DecompiledForEach.java
Created June 9, 2015 01:46
decompiled foreach
import java.util.ArrayList;
import java.util.Iterator;
public class ForEach {
public ForEach() {
}
public static void main(String[] var0) {
ArrayList var1 = new ArrayList();
Iterator var2 = var1.iterator();
@vaskoz
vaskoz / ProgrammaticJUnit.java
Created June 24, 2015 00:42
Run JUnit tests programmatically
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class ProgrammaticJUnit {
@Test public void test1() {
assertEquals(3, 1+2);
}
@Test public void test2() {
assertEquals(8, 3*3); // INTENTIONAL FAIL
}
@vaskoz
vaskoz / defer_bench.go
Created July 13, 2015 18:03
Defer significantly slower
package main
import (
"flag"
"log"
"runtime"
"sync"
"testing"
)
class Ninja{private final String test="This is just a test String";private Ninja(){}public String getTest(){return test;}}