Skip to content

Instantly share code, notes, and snippets.

View sofianinho's full-sized avatar

Sofianinho sofianinho

View GitHub Profile
$ vagrant --nodes=3 up
Bringing machine 'node-1' up with 'virtualbox' provider...
Bringing machine 'node-2' up with 'virtualbox' provider...
Bringing machine 'node-3' up with 'virtualbox' provider...
==> node-1: Importing base box 'ubuntu/bionic64'...
==> node-1: Matching MAC address for NAT networking...
==> node-1: Checking if box 'ubuntu/bionic64' is up to date...
==> node-1: A newer version of the box 'ubuntu/bionic64' for provider 'virtualbox' is
==> node-1: available! You currently have version '20181030.0.0'. The latest is version
==> node-1: '20181101.0.0'. Run `vagrant box update` to update.
#!/bin/bash
PROTOC_REPO="google/protobuf"
# Credits to: lukechilds here: https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c
get_latest_release() {
URL="https://api.github.com/repos/$1/releases/latest"
VERSION=$(curl -L --silent $URL |grep '"tag_name":' |sed -E 's/.*"([^"]+)".*/\1/')
echo $VERSION
}
@sofianinho
sofianinho / gin-logrus-swagger.go
Last active April 11, 2018 11:28
create your swagger v2 (openAPIv2) straight from your gin code
//download swagger-ui as a zip from https://github.com/swagger-api/swagger-ui/tree/v2.2.10
//make sure to change line 40 of file: swagger-ui/dist/idex.html to: "/swagger.json" in the url var
//this is how the swagger-ui knows to ask for the specification at the right place
//You can enrich your swagger api by using the swag.XXXX functions that return "Option" type. example: Description, Host, License...
// These functions are here: https://godoc.org/github.com/savaki/swag#Option
//the original code of the author from swag has been modified
//original lionk: https://raw.githubusercontent.com/savaki/swag/master/examples/gin/main.go
// Copyright 2017 Matt Ho
# for python2 version
sudo apt-get install python-scapy
#to create dynamic payload
sudo pip2 install loremipsum
#to forge packets need to be root
sudo scapy
#python part
@sofianinho
sofianinho / set-gitignore.sh
Created February 15, 2017 11:25
set your .gitignore file in a git project
#First you need to commit any useful changes
#respect the syntax of .gitignore when writing it
git rm -r --cached .
git add .
git commit -m ".gitignore is now working"
@sofianinho
sofianinho / modify-mongo.sh
Created November 21, 2016 16:56
Change Mongo entry on the fly
# Mongo database musty be started with the rest option
# Port 28017 is the port for restful HTTP calls
docker run --rm -it mongo:3.2 --rest
#Suppose you injected the following
curl -i -X POST -d '{ "firstName" : "Rick", "lastName" : "Sanchez" }' http://172.17.0.3:28017/testDB/testC
#Return one entry with firstName equal Rick
curl -i 'http://172.17.0.3:28017/testDB/testC?filter_firstName=Rick&limit=1'
#Modify it using jq and sed
curl -s 'http://172.17.0.3:28017/testDB/testC?filter_firstName=Rick&limit=1' |jq .'rows[0]'|sed 's/\"lastName\".\+$/\"lastName\": \"Wabba lubba dub dub\"/g'
# To reinject the modified content, you need to localize the "_id" generated by Mongo and delete it to add the entry. For example, if it's line 2 to 4, with sed
@sofianinho
sofianinho / nb-addresses.sh
Last active November 23, 2016 08:30
Find number of addresses already attributed by docker engine
#!/bin/sh
# part by part:
# 1. "brctl showmacs docker0" show the MAC addresses attached to the docker0 bridge
# 2. "$(($(brctl showmacs docker0|wc -l) - 1))" returns the number of the lines returned by the brctl command minus 1 (to exclude the header, for cleanup)
# 3. "uniq" show only unique enteries
# 4. "wc -l" count the number of lines in the result. Which is also the number of running containers with an IP address behind the docker0 bridge.
# Next address given by the docker engine is: (@IP of docker0)+the found number+1
brctl showmacs docker0|tail -n $(($(brctl showmacs docker0|wc -l) - 1))|uniq|wc -l
#Alternative through docker
#1. the docker inspect command with its arguments returns allocated IP addresses