Skip to content

Instantly share code, notes, and snippets.

@jvmvik
jvmvik / app.go
Created April 1, 2018 02:24
Unmarshalling nested JSON / Hash with dynamic key
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
)
@jvmvik
jvmvik / docker_cheat_sheet.md
Created March 30, 2018 01:18
Docker basic cheat sheet

stop all containers:

docker kill $(docker ps -q)

remove all containers.

docker rm $(docker ps -a -q)

remove all docker images.

docker rmi $(docker images -q)

@jvmvik
jvmvik / .gitconfig
Created October 26, 2017 16:13
My git config file
[user]
name = Victor Benarbia
email = victor.benarbia@arm.com
[push]
default = simple
[alias]
ci = commit
ll = log --graph --stat --abbrev-commit --decorate=full
lp = log --graph --patch --abbrev-commit --decorate=full
lm = log --graph --patch --abbrev-commit --decorate=full --author victor
# 0. Shortcuts.
CTRL+A # move to beginning of line
CTRL+B # moves backward one character
CTRL+C # halts the current command
CTRL+D # deletes one character backward or logs out of current session, similar to exit
CTRL+E # moves to end of line
@jvmvik
jvmvik / unix_bash.md
Created August 11, 2017 12:06
UNIX / Bash cheat/ LSF

0. Shortcuts.

CTRL+A # move to beginning of line CTRL+B # moves backward one character CTRL+C # halts the current command CTRL+D # deletes one character backward or logs out of current session, similar to exit CTRL+E # moves to end of line

@jvmvik
jvmvik / Makefile
Created November 29, 2016 17:37
Doubling dollar sign allow to preserve $
test:
ruby -p -i.old -e '$$_.gsub!('name', "$$USER" )' *.v
@jvmvik
jvmvik / wait_and_see.sh
Last active June 13, 2016 22:38
Launch a process on the background, then start a loop waiting for the process completion.
#!/bin/bash
cmd="sleep 5s"
# Run a command
nohup $cmd > /dev/null 2>&1 &
pid=$!
# Here is the process id
echo $pid
@jvmvik
jvmvik / walk_dependency_graph.rb
Created May 17, 2016 13:30
Solve a simple dependency graph in Ruby. This is useful to follow file dependency like: #include in C++
# Walk a dependency graph
#
def walk(deps, available = [])
# End condition
return if deps.keys.size == available.size
if available.size == 0
deps.each do |f, h|
next if h[:visited] == true
next if h[:includes].size > 0
@jvmvik
jvmvik / log.rb
Last active April 1, 2016 19:37
Ruby logging wrapper. Allow: Add interceptor
require 'logger'
module Log
class << self
def log
@logger ||= Logger.new($stdout)
@logger.formatter = proc do |severity, datetime, progname, msg|
if(@interceptors)
@interceptors.each { |interceptor|
interceptor.call(severity, msg)
@jvmvik
jvmvik / mongodb_map_reduce.rb
Last active November 21, 2016 13:06
Ruby mongoDB map reduce
# Ruby mongoDB map reduce
# The mongoDB documentation missed totally to
# describes a simple usage for map reduce in Ruby.
# and the web is full of misleading example based on the previous API.
#
# This gist try to fill out the gap.
# First please read https://docs.mongodb.org/manual/tutorial/map-reduce-examples/
# below it is a simple Ruby implementation.
#
# @doc https://docs.mongodb.org/manual/core/map-reduce/