Skip to content

Instantly share code, notes, and snippets.

Muhammad Hewedy mhewedy

Block or report user

Report or block mhewedy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mhewedy
mhewedy / context_canceled.go
Created Aug 19, 2019
Detect request cancelation
View context_canceled.go
package main
import (
"fmt"
"github.com/labstack/echo/v4"
"net/http"
"time"
)
func main() {
View order_emited_elements_using_chan.go
package main
import (
"fmt"
"github.com/fatih/color"
"sync"
)
func main() {
View chan_signaling_patterns.go
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
func main() {
View sync_map_example.go
package main
import (
"fmt"
"sync"
)
var cache = sync.Map{}
func main() {
View goroutines101.go
package main
import (
"fmt"
"runtime"
"sync"
)
func init() {
// my cpu has 2 cores with 2 thread each, so num of logical cpus is 4, it is late 2013 macbook pro:
@mhewedy
mhewedy / tee.go
Created Aug 11, 2019
Simple Tee writer
View tee.go
type TeeWriter struct {
w []io.Writer
}
func (t TeeWriter) Write(p []byte) (n int, err error) {
for _, writer := range t.w {
n, err = writer.Write(p)
if err != nil {
return n, err
}
@mhewedy
mhewedy / server.go
Created Aug 10, 2019
Example with custom authentication and authorization with echo go web framework
View server.go
package main
import (
"fmt"
"github.com/dgrijalva/jwt-go"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"net/http"
"time"
)
View main.go
import (
"fmt"
)
type User int
func (self User) Run() {
fmt.Printf("%v %p Running\n", self, &self)
}
View main.go
import (
"fmt"
)
type User int
func (self User) Run() {
fmt.Printf("%v %p Running\n", self, &self)
}
@mhewedy
mhewedy / append_nasty_side_effect.go
Last active Aug 4, 2019
Go is not easy at all, it is not java or ruby or c#, it is a simpler c++ (nasty side effects of using append on slices)
View append_nasty_side_effect.go
package main
import (
"fmt"
)
type user struct {
likes int
}
You can’t perform that action at this time.