Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Pablo Pazos Gutiérrez ppazos

🏠
Working from home
View GitHub Profile
View round_bigdecimal_2_decimals.groovy
BigDecimal.metaClass.round2 = {
def ctx = new java.math.MathContext(4) // doesnt work this is the total number of digits not the decimals
delegate.round(ctx)
}
def n = 2290.389649
println n.round2()
println n.setScale(2, java.math.RoundingMode.HALF_UP)
View cloud_plan_dates_tests.groovy
Date.metaClass.toFirstDayOfMonth = {
Calendar c = Calendar.getInstance()
c.setTime(delegate)
// first day of month
c.set(Calendar.DAY_OF_MONTH, 1)
// time to zero
c.set(Calendar.HOUR_OF_DAY, 0)
c.set(Calendar.MINUTE, 0)
c.set(Calendar.SECOND, 0)
delegate = c.getTime()
View duration_period_tests.groovy
def d = "P4Y24M3DT2H10M33S"
println d.split("T")
println java.time.Duration.parse("PT"+ d.split("T")[1])
println java.time.Period.parse(d.split("T")[0])
println java.time.Period.parse(d.split("T")[0]).normalized()
println java.time.Duration.parse("PT"+ d.split("T")[1]).seconds
println java.time.Duration.parse("PT"+ d.split("T")[1]).get(java.time.temporal.ChronoUnit.SECONDS)
@ppazos
ppazos / openehr_terminology_id_regex.groovy
Last active Sep 8, 2021
openEHR TERMINOLOGY_ID format
View openehr_terminology_id_regex.groovy
// matcher api https://docs.oracle.com/javase/8/docs/api/java/util/regex/Matcher.html
// regex ref https://docs.oracle.com/javase/tutorial/essential/regex/pre_char_classes.html
def pat = ~/([\w_-]+)\s*(?:\(?(\w*)\)?.*)?/
// https://specifications.openehr.org/releases/BASE/latest/base_types.html#_syntaxes
def patoehr = ~/(([A-Za-z]+)[\w-\+\/]*)(\(([A-Za-z]+)[\w-\+\/]*\))?/
def tids = [
'SNOMED-CT',
View opt_constraint_alternatives.groovy
/*
invoke like this:
$ groovy generate_opt_alternatives.groovy ~/GitHub/openEHR-OPT/src/main/resources/opts/com.cabolabs.openehr_opt.namespaces.default/minimal_observation.opt [max] [destination]
*/
import groovy.xml.XmlUtil
import groovy.util.Node
import groovy.xml.XmlParser
import java.util.UUID
@ppazos
ppazos / markdown-details-collapsible.md
Created Jun 24, 2021 — forked from pierrejoubert73/markdown-details-collapsible.md
How to add a collapsible section in markdown.
View markdown-details-collapsible.md

A collapsible section containing markdown

Click to expand!

Heading

  1. A numbered
  2. list
    • With some
    • Sub bullets
@ppazos
ppazos / buffer.php
Created Jun 14, 2021
buffer pattern sample
View buffer.php
<?php
// these could be elements in a db loaded by small chunks into the buffer to avoid having too much memory consumption
$data = range(1, 1000);
$pointer = 0;
$buffer_size = 10; // process just these items per loop
$buffer = array();
do {
@ppazos
ppazos / test_falsy.php
Created May 12, 2021
Tests falsy values which compared to false give true
View test_falsy.php
<?php
$items = array(
array(),
0,
'',
null
);
function is_false($v)
@ppazos
ppazos / toBinary.groovy
Created Apr 14, 2021
displays binary string from int
View toBinary.groovy
void toBinary(int decimal)
{
int[] binary = new int[40]
int index = 0
String bin = ""
while(decimal > 0)
{
binary[index++] = decimal%2
decimal = decimal/2
}
@ppazos
ppazos / precision_to_step.php
Created Apr 7, 2021
Transform a number representing the precision of another number, into a string containing the step value for HTML input number atttribute "step"
View precision_to_step.php
<?php
// transforms p=3 into s=0.001
function precision_to_step($precision = 0)
{
if ($precision <= 0) return '1';
$step = str_pad('1', $precision, "0", STR_PAD_LEFT);
$step = substr_replace($step, '0.', 0, 0);