Skip to content

Instantly share code, notes, and snippets.

View aliuygur's full-sized avatar

Ali UYGUR aliuygur

View GitHub Profile
// client.go
package rickandmorty
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
// client_test.go
package rickandmorty
import (
"io/ioutil"
"net/http"
"strings"
"testing"
)
@aliuygur
aliuygur / hackerrank_time_conversion_solution.go
Created July 28, 2022 19:18
hackerrank Time Conversion problem solution in Golang
/*
* Complete the 'timeConversion' function below.
*
* The function is expected to return a STRING.
* The function accepts STRING s as parameter.
*/
func timeConversion(s string) string {
var AM_PM string = s[len(s)-2:]
// split time strings
@aliuygur
aliuygur / etag-cache.go
Created October 23, 2018 14:16
etag caching example in go
/*
A client for openexchangerates.org's API
This package is a small client for openexchangerates.org's HTTP API. It
respects the HTTP etags returned by the service, and implements most of
the available methods at the moment.
*/
package openexchangerates
import (
@aliuygur
aliuygur / id.go
Created September 8, 2017 10:55
mongo golang examples
package mongo
import (
mgo "gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
)
type (
nextID struct {
Next uint64 `bson:"n"`
@aliuygur
aliuygur / install.go.sh
Created February 10, 2017 09:43
go installation
GO_VERSION=1.7.1
OS=linux
ARCH=amd64
curl -O https://storage.googleapis.com/golang/go${GO_VERSION}.${OS}-${ARCH}.tar.gz
sudo tar -C /usr/local -xzf go$GO_VERSION.$OS-$ARCH.tar.gz
# Put go on the PATH, keep the usual installation dir
sudo ln -s /usr/local/go/bin/go /usr/bin/go
rm go$GO_VERSION.$OS-$ARCH.tar.gz
@aliuygur
aliuygur / desc.md
Last active July 22, 2022 09:48
removes duplicate values in given slice

this algorithm 10x faster than https://www.dotnetperls.com/duplicates-go and zero allocation

➜  api git:(master) ✗ go test -v -bench=. main_test.go
=== RUN   TestSliceUniq
--- PASS: TestSliceUniq (0.00s)
BenchmarkSliceUniq-4             3000000               439 ns/op               0 B/op          0 allocs/op
BenchmarkRemoveDuplicates-4       500000              4599 ns/op             571 B/op          8 allocs/op
PASS
package main
import (
"net/http"
"net/http/httputil"
"net/url"
)
func main() {
u, _ := url.Parse("https://leanfoods-9f12.restdb.io")
@aliuygur
aliuygur / main.go
Last active August 29, 2015 14:24 — forked from nmerouze/main.go
package main
import (
"encoding/json"
"log"
"net/http"
"reflect"
"time"
"github.com/gorilla/context"
@aliuygur
aliuygur / add-swap-file.sh
Created May 28, 2015 13:59
this file add 4GB swap file to ubuntu 14.04 x64
#!/bin/bash
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo "/swapfile none swap sw 0 0" >> /etc/fstab
echo "Added!"
free -m