Skip to content

Instantly share code, notes, and snippets.

View mdouchement's full-sized avatar
♨️
❨╯°□°❩╯︵┸━┸

mdouchement mdouchement

♨️
❨╯°□°❩╯︵┸━┸
View GitHub Profile
@mdouchement
mdouchement / barrier.sh
Last active August 29, 2015 14:03
Bash: synchronisation barrier
#!/bin/bash
./process_1.sh &
pid_1=`echo $!`
./process_2.sh &
pid_2=`echo $!`
./process_3.sh &
pid_3=`echo $!`
@mdouchement
mdouchement / ruby_abstract.rb
Created July 11, 2014 07:30
Ruby module (abstract) example
module Abstract
def self.included(base)
base.extend(ClassMethods)
end
def hello
'hello from instance method'
end
module ClassMethods
@mdouchement
mdouchement / 1_selective_instance_eval.rb
Last active August 29, 2015 14:07
Selective instance eval
String.class_eval do
alias_method :original_initialize, :initialize
def initialize(*args)
# https://www.ruby-forum.com/topic/1893190
c = caller(0)
case
when c.to_s.include?('module:V1')
instance_eval do
def to_v1
@mdouchement
mdouchement / before_filter.rb
Last active August 29, 2015 14:07
Ruby before filter
module MethodInterception
def before_filter(*meths, &blk)
return @wrap_next_method = true if meths.empty?
meths.delete_if { |meth| wrap(meth, &blk) if method_defined?(meth) }
@intercepted_methods += meths
end
private
def wrap(meth, &blk)
@mdouchement
mdouchement / profiler.go
Last active June 3, 2016 14:29
Golang memory profiler
package profiler
import (
"github.com/wblakecaldwell/profiler"
"net/http"
"sync"
)
var cache = struct {
sync.RWMutex
package main
import (
"bytes"
"encoding/gob"
"fmt"
"github.com/peterbourgon/diskv"
)
@mdouchement
mdouchement / rate_limiter.go
Created July 10, 2016 15:34
Goroutine rate limiter
package main
import (
"fmt"
"sync"
"time"
)
// limiter is a counting semaphore for limiting concurrency in action function.
var limiter = make(chan struct{}, 4)
@mdouchement
mdouchement / go.md
Last active January 25, 2017 10:45
Useful Golang packages

Static Build

CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' *.go

Objects

  • structs
    • Various utilities to work with Go (Golang) structs.
    • map[string]interface{} struct conversion.
  • github.com/fatih/structs
@mdouchement
mdouchement / gzip_bug.go
Last active June 19, 2017 15:24
Golang gzip reader does not returns the right error.
package main
import (
"bytes"
"compress/gzip"
"errors"
"fmt"
"io"
)
@mdouchement
mdouchement / camelcase.go
Created November 16, 2017 16:58
Golang camelcase / camelize
package main
import (
"fmt"
"unicode"
)
func main() {
for _, v := range []string{"target_prob1", "target_prob_1", "_target_prob_1", "target_prob_1_"} {
fmt.Printf("%s => %s\n", v, ToCamel(v))