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 / cheap-feature-branch-deploy
Last active Jan 15, 2020
cheap feature branch deploy
View cheap-feature-branch-deploy
#script to make ad-hoc cheap deploy for a git feature-branch
input: ubuntu machine IP & root username&password (EC2 or Digitalocean VM)
input will be saved in the github/bitbucet variables and referenced by varname
1. scp docker-compose file for dependent services (e.g. db) to the remote server
2. scp docker file + the artifact (e.g. war file) to the remote server
3. run the following on remote server (ssh)
a. install docker & docker-compose
b. run docker-compose file, make sure sevices start on uniq ports
@mhewedy
mhewedy / vm
Last active Jan 18, 2020
Virtualbox control cli
View vm
#! /bin/sh
case $1 in
list)
vboxmanage list vms
;;
ps)
vboxmanage list runningvms
;;
create)
@mhewedy
mhewedy / wc-src.sh
Created Dec 24, 2019
word count for source code files
View wc-src.sh
wc -w $(find ./ -not -name '*.png' -not -name "*.json" -iname '*')
@mhewedy
mhewedy / handler.go
Last active Dec 8, 2019
Separate serialization and error handling from the actual api handling logic in golang
View handler.go
type handlerFunc func(w http.ResponseWriter, r *http.Request) (interface{}, error)
func handle(fn handlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
i, err := fn(w, r)
if err != nil {
handleError(w, err, http.StatusInternalServerError)
@mhewedy
mhewedy / packr.go
Created Oct 4, 2019
workaround #golang packr2 issue with index.html
View packr.go
package main
import (
"github.com/gobuffalo/packr/v2"
"net/http"
"path/filepath"
"strings"
)
var extensionToContentType = map[string]string{
@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:
You can’t perform that action at this time.