Skip to content

Instantly share code, notes, and snippets.

View tsdtsdtsd's full-sized avatar

Orkan Alat tsdtsdtsd

View GitHub Profile
@asukakenji
asukakenji / go-stdlib-interface-selected.md
Last active April 8, 2025 14:21
Go (Golang) Standard Library Interfaces (Selected)

Go (Golang) Standard Library Interfaces (Selected)

This is not an exhaustive list of all interfaces in Go's standard library. I only list those I think are important. Interfaces defined in frequently used packages (like io, fmt) are included. Interfaces that have significant importance are also included.

All of the following information is based on go version go1.8.3 darwin/amd64.

@matryer
matryer / term_context.go
Last active March 10, 2022 05:23
Making Ctrl+C termination cancel the context.Context
func main() {
ctx := context.Background()
// trap Ctrl+C and call cancel on the context
ctx, cancel := context.WithCancel(ctx)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
defer func() {
signal.Stop(c)
@judy2k
judy2k / parse_dotenv.bash
Created March 22, 2017 13:34
Parse a .env (dotenv) file directly using BASH
# Pass the env-vars to MYCOMMAND
eval $(egrep -v '^#' .env | xargs) MYCOMMAND
# … or ...
# Export the vars in .env into your shell:
export $(egrep -v '^#' .env | xargs)
@jesselucas
jesselucas / changroup.go
Last active November 20, 2024 20:23
Simple solution for using a WaitGroup with select{}
package main
import (
"fmt"
"sync"
"time"
)
func main() {
// Create a wait group of any size
@Ovid
Ovid / newton.go
Last active December 21, 2016 16:28
Newton's methods for calculating the square root in golang
package main
// newton's method for calculating square roots
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
@r0l1
r0l1 / copy.go
Last active March 24, 2025 21:38
Copy a directory tree (preserving permissions) in Go.
/* MIT License
*
* Copyright (c) 2017 Roland Singer [[email protected]]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
// Copyright 2016 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
// Command caption reads an audio file and outputs the transcript for it.
package main
import (
"fmt"
"io"
func (b *backend) handle(c1 *tls.Conn, c *net.TCPConn) {
c2, err := net.DialTCP("tcp", nil, b.addr)
if err != nil {
c1.Close()
return
}
go func() {
err := io.Copy(c2, c1)
if err != nil {
log.Print(err)
@noelboss
noelboss / git-deployment.md
Last active April 1, 2025 16:56
Simple automated GIT Deployment using Hooks

Simple automated GIT Deployment using GIT Hooks

Here are the simple steps needed to create a deployment from your local GIT repository to a server based on this in-depth tutorial.

How it works

You are developing in a working-copy on your local machine, lets say on the master branch. Most of the time, people would push code to a remote server like github.com or gitlab.com and pull or export it to a production server. Or you use a service like deepl.io to act upon a Web-Hook that's triggered that service.

@dmitshur
dmitshur / main.go
Last active January 28, 2018 08:48
Server for HTTPS protocol. Redirects to canonical hosts, reverse proxies requests to internal backing servers.
// Server for HTTPS protocol. Redirects to canonical hosts, reverse proxies requests to internal backing servers.
package main
import (
"crypto/tls"
"flag"
"log"
"net/http"
"net/http/httputil"
"time"