Skip to content

Instantly share code, notes, and snippets.

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

Rahmat Fathoni ftamhar

🏠
Working from home
  • Indonesia
View GitHub Profile
@ftamhar
ftamhar / HaversinFormula.go
Created January 24, 2022 08:21 — forked from cdipaolo/HaversinFormula.go
Golang functions to calculate the distance in meters between long,lat points on Earth.
// haversin(θ) function
func hsin(theta float64) float64 {
return math.Pow(math.Sin(theta/2), 2)
}
// Distance function returns the distance (in meters) between two points of
// a given longitude and latitude relatively accurately (using a spherical
// approximation of the Earth) through the Haversin Distance Formula for
// great arc distance on a sphere with accuracy for small distances
//
@ftamhar
ftamhar / go_cpu_memory_profiling_benchmarks.sh
Created December 30, 2021 23:10 — forked from arsham/go_cpu_memory_profiling_benchmarks.sh
Go cpu and memory profiling benchmarks. #golang #benchmark
go test -run=. -bench=. -benchtime=5s -count 5 -benchmem -cpuprofile=cpu.out -memprofile=mem.out -trace=trace.out ./package | tee bench.txt
go tool pprof -http :8080 cpu.out
go tool pprof -http :8081 mem.out
go tool trace trace.out
go tool pprof $FILENAME.test cpu.out
# (pprof) list <func name>
# go get -u golang.org/x/perf/cmd/benchstat
benchstat bench.txt
@ftamhar
ftamhar / camel_case.go
Created December 17, 2021 08:12
Camel Case 4 golang
package main
import (
"bufio"
"fmt"
"os"
"strings"
"unicode"
)
func mySplit(s string) []string {
@ftamhar
ftamhar / http2_apache2_ubuntu18.04.md
Created October 18, 2021 14:59 — forked from GAS85/http2_apache2_ubuntu18.04.md
How to Enable HTTP/2 in Apache 2.4 on Ubuntu 18.04

Requirements

  • A self-managed VPS or dedicated server with Ubuntu 18.04 running Apache 2.4.xx.
  • A registered domain name with working HTTPS (TLS/SSL). HTTP/2 only works alongside HTTPS because most browsers, including Firefox and Chrome, don’t support HTTP/2 in cleartext (non-TLS) mode.

Step 1: Install Apache2

@ftamhar
ftamhar / InsertStructValueFromMultipart.go
Last active October 9, 2021 23:04
function to insert struct value from multipart value, tested on fiber framework.
func InsertStructValueFromMultipart(form map[string][]string, tipe interface{}) {
refValue := reflect.ValueOf(tipe)
newTipe := refValue.Elem()
indirect := reflect.Indirect(refValue).Type() // remove pointer
for i := 0; i < indirect.NumField(); i++ {
value := form[indirect.Field(i).Tag.Get("json")]
if len(value) > 0 && value[0] != "" && value[0] != "null" {
newTipe.Field(i).SetString(strings.Trim(value[0], " "))
}
@ftamhar
ftamhar / SolutionCase1.py
Last active May 14, 2020 09:52
Lombok.py #SolutionCase1
class Solution:
def lengthOfLongestSubstring(self, strings):
self.strings = strings
self.panjangs = [0]
self.sudah = []
for char in self.strings:
if char not in self.sudah:
self.sudah.append(char)
self.panjangs[len(self.panjangs)-1] += 1
else:
@ftamhar
ftamhar / gist:13943ac082627d6ed45b1e9a378ca895
Created May 8, 2020 00:23 — forked from peymano/gist:2047968
Restore from a binary Postgres dump file
pg_restore --clean --no-acl --no-owner -d <database> -U <user> <filename.dump>