Skip to content

Instantly share code, notes, and snippets.

@luiscoms
luiscoms / detect-os.sh
Created September 27, 2016 12:54
Bash script to detect OS by type
#!/bin/bash -x
case "$OSTYPE" in
darwin*) echo "I am a Mac" ;;
*) echo "I am not a Mac" ;;
esac
@luiscoms
luiscoms / wrapper.py
Created September 12, 2016 14:23
Python Wrapper behaviours
from functools import wraps
def dec_wrapper(name):
def dec(func):
@wraps(func)
def wrapper(*args, **kw):
print(name)
print(args)
result = func(*args, **kw)
print('acabou')
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import logging
from pprint import pprint, pformat
import sys
logging.basicConfig(
stream=sys.stdout,
# level=logging.DEBUG,
format='[%(asctime)s] %(levelname)s:%(name)s:%(lineno)d - %(message)s'
@luiscoms
luiscoms / docker-utils.sh
Last active October 3, 2016 18:11
Docker utils
# Delete all containers
docker rm $(docker ps -aq --filter status="exited" --filter status="dead")
docker rm $(docker ps -aq)
# Delete all untaged images
docker rmi $(docker images --filter "dangling=true" -q | sort -u)
http://serverspec.org/resource_types.html
https://docs.docker.com/engine/installation/linux/ubuntulinux/#create-a-docker-group
@luiscoms
luiscoms / CallApplicationFragment.java
Created November 11, 2015 17:48
Call another application if is installed
package com.example.app.fragments;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@luiscoms
luiscoms / cvs-patch.sh
Created April 17, 2015 14:56
CVS Utils
#!/bin/bash
PROJECT_PATH=$(pwd);
APPLY=false
IDENTIFIER=""
echoerror() {
printf "$@\n" 1>&2
}
@luiscoms
luiscoms / trollface
Created March 6, 2015 16:56
Trollface in ASCII Art
QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ
QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ
QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ
QQQQQQQQQQQQQQQQQQQWQQQQQWWWBBBHHHHHHHHHBWWWQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ
QQQQQQQQQQQQQQQD!`__ssaaaaaaaaaass_ass_s____. -~""??9VWQQQQQQQQQQQQQQQQQQQ
QQQQQQQQQQQQQP'_wmQQQWWBWV?GwwwmmWQmwwwwwgmZUVVHAqwaaaac,"?9$QQQQQQQQQQQQQQ
QQQQQQQQQQQW! aQWQQQQW?qw#TTSgwawwggywawwpY?T?TYTYTXmwwgZ$ma/-?4QQQQQQQQQQQ
QQQQQQQQQQW' jQQQQWTqwDYauT9mmwwawww?WWWWQQQQQ@TT?TVTT9HQQQQQQw,-4QQQQQQQQQ
QQQQQQQQQQ[ jQQQQQyWVw2$wWWQQQWWQWWWW7WQQQQQQQQPWWQQQWQQw7WQQQWWc)WWQQQQQQQ
QQQQQQQQQf jQQQQQWWmWmmQWU???????9WWQmWQQQQQQQWjWQQQQQQQWQmQQQQWL 4QQQQQQQQ
@luiscoms
luiscoms / index.htm
Created February 6, 2015 21:14
Iframe 100% width height
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Welcome</title>
<style type="text/css">
body {
margin: 0;
padding: 0;
}
@luiscoms
luiscoms / top10commands.sh
Last active November 25, 2016 01:13
Top 10 commands used on shell
#!/bin/bash
history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n10
@luiscoms
luiscoms / dict2xml.py
Created September 22, 2014 16:50
Convert python dictionary to xml
# -*- coding: utf-8 -*-
''' Code based on
Huseyin Yilmaz - Convert python dictionary to xml - https://gist.github.com/huseyinyilmaz/1448723
Ye Lui - dict2xml - https://gist.github.com/jaux/1478881
Simple Dictionary XML Serializer - https://gist.github.com/reimund/5435343
'''
from xml.dom import minidom
from collections import Mapping
import unittest