Skip to content

Instantly share code, notes, and snippets.

View ppazos's full-sized avatar
🌎
All around

Pablo Pazos Gutiérrez ppazos

🌎
All around
View GitHub Profile
@ppazos
ppazos / print_tree.c
Created April 27, 2024 05:31 — forked from ximik777/print_tree.c
Printing Binary Trees in Ascii
/*
Copy from: http://web.archive.org/web/20090617110918/http://www.openasthra.com/c-tidbits/printing-binary-trees-in-ascii/
Source: http://web.archive.org/web/20071224095835/http://www.openasthra.com:80/wp-content/uploads/2007/12/binary_trees1.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ppazos
ppazos / decimal_to_binary.groovy
Created April 20, 2024 00:36
Transforma un número decimal a uno binario en Groovy
int n = 1024 // entrada
String binario = '' // numero binario como string para poder verlo
int c = n
while (c > 1)
{
// modulo (%) da 0 cuando el numero es par y da 1 cuando el numero impar
// los numeros pares en binario terminan en cero, y los impoares en 1,
// entonces esto sirve para tomar el ultimo bit y saber si es 0 o 1.
binario = (c % 2).toString() + binario
@ppazos
ppazos / keybindings.json
Created April 15, 2024 18:25
Useful keybindings for vscode
// Place your key bindings in this file to override the defaultsauto[]
[
{
"key": "ctrl+alt+r",
"command": "workbench.files.action.showActiveFileInExplorer"
},
{
"key": "ctrl+alt+tab",
"command": "type",
"args": {
@ppazos
ppazos / get_fks_for_table.sql
Created April 12, 2024 04:18
Gets all the FKs that points to a given table
SELECT
TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME
FROM
INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE
REFERENCED_TABLE_SCHEMA = (SELECT DATABASE()) AND
REFERENCED_TABLE_NAME = '$TABLE_NAME'
@ppazos
ppazos / timestamp.groovy
Last active March 31, 2024 22:07
Create and consume millisecond timestamps in PHP and Groovy
// Consume timestamp in Java/Groovy
def timestamp = ...
def date = new Date(timestamp)
println new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date)
// Generate milliseconds in Groovy for current date
def timestamp = new Date().getTime()
@ppazos
ppazos / write_file.groovy
Created March 25, 2024 18:31 — forked from js1972/write_file.groovy
How to write content to a new file (overwrite if already existing) in Groovy.
//
// Write the mock request payload to a file for checking later...
// newWrite() is the important it to ensure you get a *new* file each time.
//
def filename = "C:\\MyScratchFolder\\soapUI projects\\Testing\\procon\\mock_po_activity_request.xml"
def file = new File(filename)
def w = file.newWriter()
w << mockRequest.requestContent
w.close()
@ppazos
ppazos / mysql_table_count.sql
Created March 7, 2024 19:27
Count records for each table in MySQL
SELECT SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '__YOUR_DB__';
@ppazos
ppazos / sub_query.groovy
Created February 28, 2024 05:01 — forked from roalcantara/sub_query.groovy
Grails: Criteria + Subquery (DetachedCriteria)
/*
Suppose we need a query searching for all Equipments that are not being used in any ServiceOrder.
It means, given the following query:
select this_.*
from equipment this_
where this_.status == 'enabled'
and not exists (select so_.id as y0_ from service_order so_ where (so_.equipment_id=this_.id))
order by this_.serial_number asc;
def lines = (1..10000000)
println lines.getClass()
// with list.each {}
def start = System.nanoTime()
lines.each { line->
line++;
}
@ppazos
ppazos / i18n_messages_with_variables.groovy
Created February 22, 2024 01:06
Methods to replace ordered arguments on strings and access certain paths on parsed JSON objects
// UTIL METHODS
/**
* Replaces arguments in error messages: "This {0} is an error for {1}", [a, b] => "This a is an error for b"
*/
private error_message_replace_values(String error_msg, List values)
{
for (int i = 0; i < values.size(); i++)
{
error_msg = error_msg.replace("{$i}", values[i].toString())