Skip to content

Instantly share code, notes, and snippets.

@mmirolim
mmirolim / whyfparticle.scala
Last active May 24, 2018 18:42
FP ideas implementation
package main
import scala.annotation.tailrec
object FP extends App {
println("test solution")
val nums = List(1, -1, 1, 2,-1)
def comp(in: List[Int]): Int = {
@mmirolim
mmirolim / s3_count_size.sh
Created April 5, 2018 15:11
total size of s3 storage
#!/bin/bash
for bucket in $(aws s3 ls |awk '{print $3}'); do
echo $bucket
for size in $(aws s3 ls s3://${bucket} --recursive |awk '{print $3}'); do
total=$(expr $total + $size);
echo "total=$total b"
done
done
echo "total=$total b"
@mmirolim
mmirolim / set_struct_prop_from_env.go
Created January 24, 2018 08:35
Set struct props from env
// prints evn variable names
func printEnvNames(cfg interface{}) error {
envs := make([]string, 0, 10)
collectEnv := func(elem reflect.Value, i int) error {
// get env variable name from struct.field tag
name := elem.Type().Field(i).Tag.Get("env")
// skip if env tag not set
if name != "" {
envs = append(envs, name)
}
@mmirolim
mmirolim / Bulletproof_foods.md
Created November 5, 2017 11:57 — forked from JamesDullaghan/Bulletproof_foods.md
Dave Aspreys bulletproof diet food list

How many servings should I eat per day?

  • Fruit = 1-2 servings
  • Animal protein = 4 - 6 servings
  • Healthy fats = 5 - 9 servings
  • Healthy vegetables = 6 - 11 servings

How should I allocate my calories per day?

  • Healthy fats = 50%
@mmirolim
mmirolim / mongoose-exec-blocking-event-loop.js
Last active October 20, 2017 11:08
Event loop blocked
'use strict'
//Import the mongoose module
var mongoose = require('mongoose');
var blocked = require('blocked');
//Set up default mongoose connection
var mongoDB = 'mongodb://localhost:27017/m2';
mongoose.connect(mongoDB, {
@mmirolim
mmirolim / funs.sh
Last active August 23, 2018 07:25
shell funcs
#!/bin/bash
#Function to restart one service in services orchestrated by docker-compose
#maybe define func with auto build
docker-compose-restart(){
docker-compose -f $1 stop $2
docker-compose -f $1 rm -f -v $2
docker-compose -f $1 up -d --no-deps $2
}
# remove dangling docker images and exited containers
@mmirolim
mmirolim / errors-wrap-bench_test.go
Created June 17, 2017 11:04
errors wrap is really slow, each time records expensive stack strace
package main
import (
"errors"
"fmt"
"testing"
werrors "github.com/pkg/errors"
)
@mmirolim
mmirolim / glog-prefixed.go
Created May 16, 2017 00:19
add prefix to glog in http middleware
package main
import (
"context"
"flag"
"fmt"
"html"
"log"
"net/http"
"time"
@mmirolim
mmirolim / ca-bundle.crt
Created April 28, 2017 11:47
ca-bundle.crt root
-----BEGIN CERTIFICATE-----
MIIE2DCCBEGgAwIBAgIEN0rSQzANBgkqhkiG9w0BAQUFADCBwzELMAkGA1UEBhMC
VVMxFDASBgNVBAoTC0VudHJ1c3QubmV0MTswOQYDVQQLEzJ3d3cuZW50cnVzdC5u
ZXQvQ1BTIGluY29ycC4gYnkgcmVmLiAobGltaXRzIGxpYWIuKTElMCMGA1UECxMc
KGMpIDE5OTkgRW50cnVzdC5uZXQgTGltaXRlZDE6MDgGA1UEAxMxRW50cnVzdC5u
ZXQgU2VjdXJlIFNlcnZlciBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw05OTA1
MjUxNjA5NDBaFw0xOTA1MjUxNjM5NDBaMIHDMQswCQYDVQQGEwJVUzEUMBIGA1UE
ChMLRW50cnVzdC5uZXQxOzA5BgNVBAsTMnd3dy5lbnRydXN0Lm5ldC9DUFMgaW5j
b3JwLiBieSByZWYuIChsaW1pdHMgbGlhYi4pMSUwIwYDVQQLExwoYykgMTk5OSBF
bnRydXN0Lm5ldCBMaW1pdGVkMTowOAYDVQQDEzFFbnRydXN0Lm5ldCBTZWN1cmUg
@mmirolim
mmirolim / count-max-flip-bit.py
Created February 7, 2017 11:35
flip bits O(n) solution
#code http://www.practice.geeksforgeeks.org/problem-page.php?pid=1337
ntest = int(input())
tests = {}
lens = []
for i in range(ntest):
l = int(input())
tests[raw_input()] = l
for bits in tests:
maxScore = 0