Skip to content

Instantly share code, notes, and snippets.

@joseche
joseche / xmlTocsv.rb
Last active October 1, 2015 19:54
Convert a XML file to a CSV file
# first argument the xml file to convert
# second argument the csv output file
# TODO: it doesn't create the header of the csv file, only values
require 'nokogiri'
require 'pp'
exit unless ARGV.length > 1
exit unless File.exist?(ARGV[0])
@joseche
joseche / fix_ulimit.sh
Created October 1, 2015 22:17
Mac OS fix ulimit open files
echo kern.maxfiles=65536 | sudo tee -a /etc/sysctl.conf
echo kern.maxfilesperproc=65536 | sudo tee -a /etc/sysctl.conf
sudo sysctl -w kern.maxfiles=65536
sudo sysctl -w kern.maxfilesperproc=65536
ulimit -n 65536 65536
@joseche
joseche / bashrc.sh
Last active October 8, 2015 22:43
.bashrc
# .bash_profile for login shell
# .profile for interactive shell
#
# control line:
[ -z "$BASHRC" ] || exit
# load defaults
[ -f /etc/bashrc ] && . /etc/bashrc
[ -f ~/.bash_profile ] && . ~/.bash_profile
[ -f ~/.profile ] && . ~/.profile
@joseche
joseche / s3policy.aws
Created October 20, 2015 05:12
Grant IAM user access to bucket
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:ListAllMyBuckets"
],
"Resource": "arn:aws:s3:::*"
@joseche
joseche / computeDistance.js
Last active November 6, 2015 06:43
Compute the distance between two coordinates
function computeDistance(startCoords, destCoords) {
var startLatRads = degreesToRadians(startCoords.latitude);
var startLongRads = degreesToRadians(startCoords.longitude);
var destLatRads = degreesToRadians(destCoords.latitude);
var destLongRads = degreesToRadians(destCoords.longitude);
var Radius = 6371; // radius of the Earth in km
var distance =
Math.acos(Math.sin(startLatRads) * Math.sin(destLatRads) +
@joseche
joseche / multiple_githubs.md
Last active November 13, 2015 23:04
Multiple Accounts for GitHub

Use different github accounts with key auth

this works with URLs like git@github.com:...., not https

1 - Create a separate key for each account

Use this command:

ssh-keygen -t rsa -C "email address of each account"
# make sure you name the key file accordingly
@joseche
joseche / selinux.sh
Last active November 16, 2015 21:15
selinux blocking nginx or any other program to access files
# install tools
yum install -y policycoreutils-devel
# create policy from logs
grep nginx /var/log/audit/audit.log | audit2allow -M nginx
# add policy to allowed policies
semodule -i nginx.pp
# more info
# get access and secret keys form a role
# last param is the role name
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/MyRole
@joseche
joseche / unix.sh
Created December 22, 2015 16:44
Unix Tips & Tricks
# A public telnet server with many little games and distractions.
telnet telehack.com
# x-mas syslog
tail -F /var/log/syslog | awk '{printf("\033[%dm%s\033[0m\n",31+NR%2,$0)}'
# Star Wars Episode IV in Reverse DNS.
( seq 1 8 200 ; seq 6 8 200 ) | sort -n | xargs -I{} -n 1 dig +short -x 206.214.251.{}
@joseche
joseche / ddns_route53.py
Last active May 1, 2019 00:36
DDNS using Route53
#!/usr/bin/python
# Author: jose@josehidalgo.net,
# github.com/joseche
# Requirements:
# pip install boto urlopen
# Credentials:
# You need to have your AWS keys in this file ~/.aws/credentials: