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
go test -bench=. itoa_test.go
goos: darwin
goarch: amd64
BenchmarkFmtSprintf-4 2000000 938 ns/op
BenchmarkStrconvItoa-4 5000000 253 ns/op
PASS
ok command-line-arguments 4.335s
@vaskoz
vaskoz / floyd.go
Created February 23, 2017 05:44
Interesting to view the trace: go test -bench . -trace trace.out
package floyd
import "sync"
// FloydTriangle implements the triangle as a slice of slices based on
// https://github.com/plutov/practice-go/tree/master/floyd
func FloydTriangle(rows int) [][]int {
if rows < 0 {
panic("can't be less than zero")
}
@vaskoz
vaskoz / hostname.go
Last active March 11, 2016 20:51
Test Coverage Question
package main
import (
"log"
"os"
)
// METHOD1
// Typical Method
func GetHostname() string {
@vaskoz
vaskoz / cpu8_server.go
Last active September 18, 2015 14:51
go pprof includes cpu and syscall time
package main
import (
"fmt"
"log"
"os"
"runtime/pprof"
"sync"
)
@vaskoz
vaskoz / defer_bench.go
Created July 13, 2015 18:03
Defer significantly slower
package main
import (
"flag"
"log"
"runtime"
"sync"
"testing"
)
@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 / programatic_tests.go
Created June 24, 2015 00:33
Run golang tests programatically
package main
import (
"flag"
"fmt"
"testing"
)
func Test1(t *testing.T) {
if 1+2 != 3 {
@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();
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 / 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);
}
}