Skip to content

Instantly share code, notes, and snippets.

View hgmiguel's full-sized avatar

Miguel Angel Huerta Gonzalez hgmiguel

View GitHub Profile
@hgmiguel
hgmiguel / with example
Created May 22, 2014 14:26
beautifull sql
with temp as (select d_codigo
from (select d_codigo,d_estado, length(d_codigo)
from colonia_tmp
group by d_codigo,d_estado
having length(d_codigo) = 4) newcode)
update colonia_tmp set d_codigo= '0' || d_codigo where d_codigo in (select d_codigo from temp);
@hgmiguel
hgmiguel / TestController.groovy
Created July 25, 2014 19:32
groovy method missing pattern
def dynamicMethods = [
[regex:"hasPermission(.*)", method:this.&hasPermission],
[regex:"create(.*)Permission", method:this.&createPermission]]
def methodMissing(String name, args) {
def method = dynamicMethods.find { name =~ it.regex}
if(method) {
def match = name =~ method.regex
return method.method(match[0][1], * args)
} else
@hgmiguel
hgmiguel / Collection_Pipeline.groovy
Created July 27, 2014 17:32
Collection Pipeline in groovy
some_articles
.collectMany{article -> article.tags.collect{ [ ( it ), article] }}
.groupBy{it.first()}
.collectEntries {k,v -> [( k ): v.collect {it.last()}]}
.collect {k,v -> [( k ):[articles: v.size(),words:v.collect{it.words}.inject(0) { acc, val -> acc + val }] ]}
@hgmiguel
hgmiguel / busca.groovy
Created October 27, 2014 23:42
busca minas horrible
file = new File('input.txt')
board = [][]
file.eachWithIndex {obj, i ->
if (i == 0) {
(rows, columns) = obj.split(" ")*.toInteger()
} else {
board << ([0] << obj.collect{ it == '*'?'*':0 } << [0]).flatten()
}
}
@hgmiguel
hgmiguel / DemoDynamic.groovy
Created November 11, 2014 03:14
Ejemplo de invocacion dinamica de metodos en groovy
class DemoDynamic {
Map<String, List<String>> permissions = [:]
Boolean hasPermission(String name, String permission){
permission in permissions?."$name"
}
Map createPermission(String name, List<String> permissions) {
this.permissions?."$name" = permissions
this.permissions
@hgmiguel
hgmiguel / wath_rds_logs.sh
Created May 14, 2016 19:18
script para deterctar errores en los logs de postgres rds
#!/bin/bash
INSTANCES="sepa-prod-db-replica-analysis sepa-prod-db-replica1 sepa-prod-db-replica2 sepa-prod-db-replica3 sepa-prod-db-replica4"
DATE=$(date +"%Y-%m-%d")
FILENAME=$(aws rds describe-db-log-files --db-instance-identifier sepa-prod-db-replica1 --filename-contains $DATE --max-items 1 --output text | awk '{print $3}')
#filename="error/postgresql.log.2016-05-14-13"
for DB_INSTANCE in $INSTANCES ; do
echo $DB_INSTANCE
aws rds download-db-log-file-portion --db-instance-identifier $DB_INSTANCE --log-file-name $FILENAME --output text | grep 'ERROR: prepared statement\|connection to client lost'
import json
import boto3
import logging
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
logger = logging.getLogger()
CONFIG = {'hgmigueldb-replica1': 'i-847d9502'}
def get_source_id(message):
@hgmiguel
hgmiguel / add-server-group.cli
Created October 6, 2016 15:52
[wildfly-cli] add a server-group, server and jvm to wildfly in domain mode
set serverGroupName=${env.WILDFLY_SERVER_GROUP_NAME}
set portOffset=${env.WILDFLY_PORT_OFFSET}
set host=${env.WILDFLY_HOST}
set maxHeapSize=${env.WILDFLY_MAX_HEAP_SIZE}
set permgenSize=${env.WILDFLY_PERMGEN_SIZE}
set jvmOptions=${env.WILDFLY_JVM_OPTIONS}
batch
@hgmiguel
hgmiguel / immediately-promotion.groovy
Created June 23, 2017 00:31
Obtiene una lista de usuarios de la variable de ambiente APPROVERS y la injecta al proceso de promoción.
promotionProcess.getPromotionCondition("hudson.plugins.promoted_builds.conditions.ManualCondition").setUsers(build.getEnvVars()["APPROVERS"])
return true
@hgmiguel
hgmiguel / download.rds.logs.sh
Last active July 13, 2017 14:18
Download rds log file
for i in `aws rds describe-db-log-files --db-instance-identifier ${INSTANCE} --output text | awk '{print $3}' | sed '$d' ` ; do
FILE=`basename ${i}`
if [ ! -e ${INSTANCE}/${FILE} ]; then
aws rds download-db-log-file-portion --db-instance-identifier ${INSTANCE} --log-file-name ${i} --output text > ${INSTANCE}/${FILE}
fi