Skip to content

Instantly share code, notes, and snippets.

Avatar
🌟
𝚊𝚋𝚜𝚝𝚛𝚊𝚌𝚝𝚒𝚘𝚗 & 𝚌𝚘𝚖𝚙𝚕𝚎𝚡𝚒𝚝𝚢

Draven draveness

🌟
𝚊𝚋𝚜𝚝𝚛𝚊𝚌𝚝𝚒𝚘𝚗 & 𝚌𝚘𝚖𝚙𝚕𝚎𝚡𝚒𝚝𝚢
View GitHub Profile
@draveness
draveness / benchmark_foreign_key.go
Last active Oct 14, 2020
Benchmark Foreign Key
View benchmark_foreign_key.go
package main
import (
"testing"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
)
type Post struct {
@draveness
draveness / float64_precision.go
Created Apr 21, 2020
Deposit and Withdraw with float64
View float64_precision.go
package main
import (
"fmt"
)
var balance float64 = 0
func main() {
deposit(.1)
View bitcoin_attack_success_probability.c
#include <math.h>
#include <stdio.h>
double attackerSuccessProbability(double q, int z) {
double p = 1.0 - q;
double lambda = z * (q / p);
double sum = 1.0;
int i, k;
for (k = 0; k <= z; k++) {
double poisson = exp(-lambda);
View golang-syscall.csv
Syscall Type
SYS_TIME RawSyscall
SYS_GETTIMEOFDAY RawSyscall
SYS_SETRLIMIT RawSyscall
SYS_GETRLIMIT RawSyscall
SYS_EPOLL_WAIT Syscall
SYS_MMAP2 Syscall
SYS__NEWSELECT Syscall
SYS_SETGROUPS32 RawSyscall
SYS_GETGROUPS32 RawSyscall
@draveness
draveness / benchmark_timers.go
Created Jul 11, 2019
Benchmark Golang Timers
View benchmark_timers.go
package main
import (
"fmt"
"sort"
"sync"
"testing"
"time"
)
View benchmark_mutex_and_channel_test.go
package main
import (
"errors"
"sync"
"testing"
)
func BenchmarkChannel(b *testing.B) {
ch := make(chan error, 1)
View timer_profile.go
package main
import (
"fmt"
"math/rand"
"sort"
"sync"
"time"
"github.com/RussellLuo/timingwheel"
View selectgo_loop.go
func selectgo(cas0 *scase, order0 *uint16, ncases int) (int, bool) {
// ...
loop:
// ...
for i := 0; i < ncases; i++ {
casi = int(pollorder[i])
cas = &scases[casi]
c = cas.c
switch cas.kind {
@draveness
draveness / main.go
Last active Mar 8, 2019
SQL Mock in Golang
View main.go
package main
import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
func recordStats(db *sql.DB, userID, productID int64) (err error) {
tx, err := db.Begin()
@draveness
draveness / service.go
Last active Mar 11, 2019
Monkey Patch Mock in Golang
View service.go
package service
import (
pwi "pkg-without-interface"
)
type service struct {}
func (s *service) ListPosts() []Post {
posts := pwi.ListPosts() // ListPosts is a pkg function.
You can’t perform that action at this time.