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
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
}
}
[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
@vaskoz
vaskoz / ldd.txt
Created May 11, 2015 03:08
Non-DNS Go version
ldd test
not a dynamic executable
@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 / timeout_with_intervals.go
Created February 4, 2015 21:35
Use a timeout library to embedded a global timeout within smaller interval timeouts
package main
import (
"fmt"
"github.com/getlantern/withtimeout"
"net/http"
"time"
)
func main() {
@vaskoz
vaskoz / cpu_loader.go
Created January 22, 2015 19:35
Golang CPU bomb - actually prevents the main thread from getting scheduled to run
package main
import (
"fmt"
"os"
"os/signal"
"runtime"
"syscall"
)
#include <stdio.h>
int main (void)
{
int a = -1;
unsigned int b = 2;
printf("%d\n", 1 > 0); // TRUE == 1
printf("%d\n", 0 > 1); // FALSE == 0
printf("%d\n", a > b); // -1 > 2 apparently TRUE == 1
printf("%d\n", -1 > 2u); // -1 > 2unsigned apparently TRUE == 1
printf("%d\n", -1 > 2); // -1 > 2 FALSE == 0
@vaskoz
vaskoz / singleton.go
Created April 13, 2014 21:00
Singleton pattern in Golang
package main
import (
"fmt"
"time"
)
var instance TheOnlyOne = &onlyOne{time.Now()}
type TheOnlyOne interface {
@vaskoz
vaskoz / for_blocks.go
Created April 12, 2014 17:20
4 different Go For loops, but 2 don't use blocks the same was as the other 2. "for_blocks_fmt.go" is the gofmt version, but it breaks the code by its formatting because it changes the CForLoopNoPrePost example so that it doesn't compile if you add the newline as the original.
package main
// There are 4 FOR examples below, but they differ in how they require
// blocks to start.
import "fmt"
// CANNOT start block on next line
func CForLoop() {
sum := 0
@vaskoz
vaskoz / strategy.go
Created April 8, 2014 18:33
Golang strategy pattern
package main
import "fmt"
type Strategy func(string, string) string
type Strategic interface {
SetStrategy(Strategy)
Result() string
}