Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Pablo Pazos Gutiérrez ppazos

🏠
Working from home
View GitHub Profile
@ppazos
ppazos / pump_control.ino
Last active Nov 22, 2020
Automatic Irrigation System for Arduino
View pump_control.ino
// IN/OUT PINS
// button pressed to run the water pump for on_ms milliseconds
const int button_in = 5; // D05 / PIN 8
// control pin that turns on the relay for the water pump
const int control_out = 2; // D03 / PIN 5
const int buzzer_out = 6; // D06 / PIN 9
@ppazos
ppazos / date_to_utc.php
Created Oct 1, 2020
Transforms a datetime with timezone into a UTC date without timezone in the MySQL format.
View date_to_utc.php
<?php
const SQL_DATETIME_FORMAT = 'Y-m-d H:i:s';
// need to transform to UTC
$original_date = "2020-09-29T12:50:20-07:00";
//$utc_date = date(SQL_DATETIME_FORMAT, strtotime($original_date));
$original_date_obj = new \DateTime($original_date);
@ppazos
ppazos / xml_serialization_pretty_and_ugly.groovy
Created Aug 12, 2020
Examples with XML serialization in pretty print and ugly print / minified
View xml_serialization_pretty_and_ugly.groovy
def xml = new XmlSlurper().parseText(
'<root><one a1="uno!"/><two>Some text!</two></root>' )
def out = groovy.xml.XmlUtil.serialize(xml)
println out
println out.class // string
out = new groovy.xml.StreamingMarkupBuilder().bind{
View for_array_to_object_data_validation.js
/*
using the jquery serializedArray from a form is very difficult to validate the
data because of the structure, passing that to an object results in a easier
to use structure for data validation, this is an example on hwo that works
*/
var params = $('#processed_form').serializeArray();
var params_obj = {};
$(params).each(function(i, field){
@ppazos
ppazos / git_branch_in_terminal_prompt.sh
Last active Aug 19, 2020
add this to the end of the .bashrc and for git repos it will show the current branch in the command prompt of the terminal
View git_branch_in_terminal_prompt.sh
# Git branch in prompt.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w \[\033[00m\]\[\033[32;1m\]\[\033[42m\]$(parse_git_branch)\[\033[00m\] $ '
@ppazos
ppazos / get_client_tz.js
Created Jul 11, 2020
Function to get the client's timezone and send it to the server in JS
View get_client_tz.js
/**
* returns the client's TZ in the "+-HH:MM" format.
*/
var get_client_tz = function()
{
visitor_time = new Date();
visitor_tz = -visitor_time.getTimezoneOffset()/60; // -3
//visitor_tz = -210/60; // test
// add - sign
@ppazos
ppazos / material-design-shadows.css
Last active Jul 3, 2020 — forked from serglo/material-design-shadows.css
Google material design elevation system shadows as css. Based on https://material.io/design/environment/elevation.html#default-elevations Exported with Sketchapp from the Google material design theme editor plugin "Baseline" theme.
View material-design-shadows.css
/* Shadow 0dp */
box-shadow: none;
/* Shadow 1dp */
box-shadow: 0 1px 1px 0 rgba(0,0,0,0.14), 0 2px 1px -1px rgba(0,0,0,0.12), 0 1px 3px 0 rgba(0,0,0,0.20);
/* Shadow 2dp */
box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 3px 1px -2px rgba(0,0,0,0.12), 0 1px 5px 0 rgba(0,0,0,0.20);
/* Shadow 3dp */
@ppazos
ppazos / openehr_duration_generator.groovy
Created Jun 21, 2020
Generates a duration expression from an ISO 8601 duration pattern
View openehr_duration_generator.groovy
def p = "PYMDTHMS"
Random random = new Random()
def gen = ""
def is_time = false
def util_date = new Date()
p.each { c ->
switch (c)
{
@ppazos
ppazos / replace_all_non_letters_or_numbers.groovy
Created Jun 12, 2020
Replaces all characters that are not letters or numbers with an underscore
View replace_all_non_letters_or_numbers.groovy
def inputs = [
'hola',
'hola Carola',
'~a`b!c@d#e$f%g@#$%^&^h&i*j(k)l_m+n=o-p'
]
inputs.each {
@ppazos
ppazos / relaxed_template_id_regex_check.groovy
Created Jun 12, 2020
Checks if the template id matches our normalized format just checking the ending
View relaxed_template_id_regex_check.groovy
def regex = /.*\.([a-z]{2})\.v([0-9]+[0-9]*(\.[0-9]+[0-9]*(\.[0-9]+[0-9]*)?)?)$/
def input = [
'c_o_v_i_d-19_pneumonia_diagnosis_and_treatment_(7th_edition)_en_v1_en_v1.en.v1',
'Cualequier Cosa.es.v1',
'Cualequier Cosa.es.v234.234',
'Cualequier Cosa.es.v234.234.234',
'`1234567890-=~!@#$%^&*(){}"|>?><,./;[].en.v1',
'asdasda.v1'
]
You can’t perform that action at this time.