Skip to content

Instantly share code, notes, and snippets.

View samaita's full-sized avatar

MasGar samaita

View GitHub Profile
@samaita
samaita / load-test-with.go
Created August 23, 2023 08:52
Load Test with Go
package main
import (
"fmt"
"net/http"
"sync"
"time"
)
const (
@samaita
samaita / JSON.lua
Last active August 22, 2023 13:35
Load Test with WRK | Enable Header & Request logging
-- -*- coding: utf-8 -*-
--
-- Simple JSON encoding and decoding in pure Lua.
--
-- Copyright 2010-2017 Jeffrey Friedl
-- http://regex.info/blog/
-- Latest version: http://regex.info/blog/lua/json
--
-- This code is released under a Creative Commons CC-BY "Attribution" License:
-- http://creativecommons.org/licenses/by/3.0/deed.en_US
@samaita
samaita / main.go
Created January 26, 2023 20:16
Golang Script to Migrate Postgres Last Sequence
package main
import (
"database/sql"
"os"
"fmt"
"log"
_ "github.com/lib/pq"
@samaita
samaita / batch.go
Last active May 23, 2022 04:05
Split an Array into several batch
package main
/*
Playground: https://go.dev/play/p/81iyOZMOeMP
Output:
batch: [1 2 3 4 5 6 7 8 9 10]
batch: [11 12 13]
*/
@samaita
samaita / mock.sample.go
Last active August 21, 2019 05:21
Sample usage on gomock, generate a mock with mockgen
// Code generated by MockGen. DO NOT EDIT.
// Source: mocking.go
// Package sample is a generated GoMock package.
package sample
import (
reflect "reflect"
gomock "github.com/golang/mock/gomock"
@samaita
samaita / var.go
Created August 20, 2019 14:54
Quick Make Unit Test for your Spaghetty Code
package unittest
import (
"context"
"errors"
"log"
"time"
"github.com/tokopedia/kunyit/src/conf"
"github.com/tokopedia/sqlt"
@samaita
samaita / coverage.sh
Created August 20, 2019 07:19
Bash Script for measure Unit Test coverage percentage for Golang package, skipping vendor
#!/bin/bash
set -e
echo 'mode: count' > profile.cov
for dir in $(find . -maxdepth 10 -not -path './.git*' -not -path '*/_*' -not -path '*/vendor*' -type d);
do
if ls $dir/*.go &> /dev/null; then
go test -short -covermode=count -coverprofile=$dir/profile.tmp $dir
if [ -f $dir/profile.tmp ]
@samaita
samaita / output.txt
Created August 8, 2018 04:53
Output of Golang Benchmark for Fraud Check Function
nakama@slack-gary:~/go$ go test -bench=.
goos: linux
goarch: amd64
BenchmarkIsFraud1-4 200000 5510 ns/op
BenchmarkIsFraud10-4 200000 6340 ns/op
BenchmarkIsFraud100-4 100000 15631 ns/op
BenchmarkIsFraud1000-4 20000 69969 ns/op
BenchmarkIsFraudByMap1-4 1000000 1013 ns/op
BenchmarkIsFraudByMap10-4 300000 4962 ns/op
BenchmarkIsFraudByMap100-4 30000 44113 ns/op
@samaita
samaita / fraud_test.go
Last active August 8, 2018 05:05
Sample of Golang Benchmark for Fraud Check Function
package fraud
import (
"flag"
"os"
"strings"
"testing"
)
@samaita
samaita / pipeline.go
Last active August 6, 2018 06:44
Pipeline with Redigo
package redis
import (
redigo "github.com/garyburd/redigo/redis"
)
// HMGET is a common usage of Redis command HMGET
func (r *redis) HMGET(key string, fields ...string) ([]string, error) {
conn := r.Pool.Get()
defer conn.Close()