Skip to content

Instantly share code, notes, and snippets.

View jjuarez's full-sized avatar
🛠️
Fixing almost everything

Javier Juarez jjuarez

🛠️
Fixing almost everything
View GitHub Profile
#!/bin/bash
usage() {
cat << EOF
usage: $0 options
This script sets ownership for all tables, sequences, views, and functions for a given schema.
Run this script as your postgres OS user.
# To create a classic TCP listening daemon, similar to netcat -l, use a variation of the following command.
socat TCP-LISTEN:8080 stdout
# use remotly a command shell
socat TCP4-LISTEN:1234,reuseaddr,fork 'SYSTEM:/bin/cat /home/infos.txt'
# SSLfy a server
socat OPENSSL-LISTEN:443,reuse‐addr,pf=ip4,fork,cert=server.pem,cafile=client.crt TCP4-CONNECT:localhost:80
# remote logger on server
@jjuarez
jjuarez / cdrom2onimg.sh
Last active August 29, 2015 14:02
From CDROM 2 OpenNebula IMG
##
# Preparar una imagen con la ISO de la distribución a generar (driver tap:aio:)
# Preparar un DATABLOCK de un tamaño de 5-8Gb (driver tap:aio:, formato ext3 (pe) y de tipo persistente)
# Preparar un template que boote de la imagen del CDROM y que tenga como storage adicional el DATABLOCK
# Instalación... >> El resultado será una imagen raw multiparticionada MBR, /boot y LVM en formato RAW
# Convertir la imagen a formato qcow2
qemu-img convert -f raw my_image.img -O qcow2 my_image.qcow2
# Montar la nueva imagen:
@jjuarez
jjuarez / Clean_VM_images
Last active August 29, 2015 14:02
Shellscript for clean our VM images
# Mount the img (qcow2)
guestmount -a my_vm.qcow2 -i /mnt/my_vm —rw
# Hacemos chroot
chroot /mnt/my_vm
# Clean yum information
/usr/bin/yum —enablerepo=extra,repos,if,apply clean all
# Rotate logs
def translate(settings)
settings.inject({}) do |hash, (key, value)|
case key
when 'foo' then hash[:foo] = value
when 'bar' then hash[:bar] = value.split(%r,/)
end
hash
end
@jjuarez
jjuarez / default_options
Created September 26, 2013 10:39
This cook works well for default parameters
class YourClass
DEFAUL_PARAMETER_VALUE = :foo
def your_method(parameter, options={ })
options = { :default_parameter =>DEFAULT_PARAMETER_VALUE }.merge(options)
# Do something with this
end
end
@jjuarez
jjuarez / options_validate
Last active December 23, 2015 23:49
How to validate a set of options fast and classy
module YourModule
VALID_OPTIONS = [ :foo, :bar ]
def your_method(parameter, options={ })
invalid_options = options.keys - VALID_OPTIONS
raise ArgumentError, "invalid option(s): #{invalid_options.join(', ')}" if invalid_options.any?
end
#!/bin/bash
RABBITMQ_VHOST="/chef"
RABBITMQ_USERNAME="chef"
RABBITMQ_PASSWORD="testing"
CHEF_COUCH_URL="http://127.0.0.1:5984/chef"
console() {
# vim:ft=sh
function generate_project() {
[ -d "${1}" ] && {
echo "The directory: ${1} already exist"
exit 1
}
local project="${1}"
@jjuarez
jjuarez / gist:4536709
Created January 15, 2013 06:46
Ruby Style Guide
Original Source: https://github.com/chneukirchen/styleguide
= Christian Neukirchen's Ruby Style Guide
You may not like all rules presented here, but they work very well for
me and have helped producing high quality code. Everyone is free to
code however they want, write and follow their own style guides, but
when you contribute to my code, please follow these rules: