Skip to content

Instantly share code, notes, and snippets.

@dei-biz
dei-biz / index.html
Created March 12, 2025 18:01
Geodesics from any point to its antipode using Miller Cylindrical Projection
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8" />
<title>Mapa Mundial con Proyección Miller y Geodésicas</title>
<script src="https://d3js.org/d3.v7.min.js"></script>
<script src= "https://d3js.org/d3-geo-projection.v2.min.js"></script>
<style>
body { margin: 0; overflow: hidden; }
svg { background: #e0f7fa; }
async function getTodosList() {
const response = await fetch('https://jsonplaceholder.typicode.com/todos'); //fetch es await function. Podemos llamarlo con await y esperará aquí
const data = await response.json(); //.json es método async, podemos llamarlo con await y esperará aquí.
return data; //el return lo hará cuando la línea anterior acabe, después de esperar la conversión a json de la response
}
async function countCompletedTodosTitleLength(){
const todos = await getTodosList(); //Llamamos a getTodosList y esperamos aquí hasta que acabe.
console.log(todos
@dei-biz
dei-biz / executeEveryNMinutes.js
Created March 22, 2019 09:48
Execute a function every N minutes at even hour divisions. I.E: 10:00, 10:15, 10:30, 10:45, 11:00 etc
/*receives a function and an integer between 1 and 60. Executes the function every N minutes at even hour divisions*/
const executeEveryNMinutes = (callback, minutes)=>{
if (!(Number.isInteger(minutes) && minutes>0 && minutes<60 && typeof(callback) == "function")){
return false;
}
const now = new Date();
const nextTime = new Date(now.getTime() + minutes * 60 * 1000 + 1);
const nextTimeRound = new Date(nextTime
.setMinutes(minutes*(Math.floor((nextTime.getMinutes() / 60) * (60/minutes)))))
@dei-biz
dei-biz / every15.js
Last active March 22, 2019 09:51
Every15minutes
//Superseded by https://gist.github.com/dei-biz/112c3825b5752c76dcb0a915b49bca47
executeNext15 = (callback)=>{
const now = new Date();
const nextTime = new Date(now.getTime() + 15 * 60 * 1000 + 1);
const nextTimeRound = new Date(nextTime
.setMinutes(15*(Math.floor((nextTime.getMinutes() / 60) * 4)))) //every 15 minutes/4 times an hour
.setSeconds(0)
const timeout = nextTimeRound - now;
@dei-biz
dei-biz / mysql2xslx
Created May 14, 2018 17:19
Python3 XLSX from MySQL
import pandas as pd
host = 'HOST'
port = 3306
user = 'USER'
password = 'PASS'
database = 'DATABASE'
writer = pd.ExcelWriter(database+'.xlsx')
{
"query" : {
"bool" : {
"should" : [{
"multi_match" : {
"type" : "best_fields",
"fields" : ["campo_importante^3", "campo_menos_importante^2", "campo_poco_importante"],
"query" : "QUERY"
}
}, {
@dei-biz
dei-biz / scaleCanvas.js
Last active January 18, 2017 12:21
scale a region of a canvas to the whole canvas given a boundaries object
var scaleCanvas = function(canvas, bb){
var retina = window.devicePixelRatio;
var width = canvas.width;
var height = canvas.height;
var newWidth = bb.xMax - bb.xMin;
var newHeight = bb.yMax - bb.yMin;
var aspectCanvas = width/height;
var aspectBB = newWidth/newHeight;
var offsetX = 0;
var offsetY = 0;
@dei-biz
dei-biz / findbb.js
Created January 15, 2017 00:03
find boundary box of non transparent pixels on a <canvas>
var findBB = function(canvas){
var width = canvas.width;
var height = canvas.height;
var imageData = canvas.getContext('2d').getImageData(0,0,width,height);
var data = imageData.data;
var bounds = {
xMax : 0,
xMin : width,
yMax : 0,
<policy domain="coder" rights="none" pattern="EPHEMERAL" />
<policy domain="coder" rights="none" pattern="HTTPS" />
<policy domain="coder" rights="none" pattern="HTTP" />
<policy domain="coder" rights="none" pattern="URL" />
<policy domain="coder" rights="none" pattern="FTP" />
<policy domain="coder" rights="none" pattern="MVG" />
<policy domain="coder" rights="none" pattern="MSL" />
@dei-biz
dei-biz / testPGSQL.php
Last active November 9, 2015 15:11
Insert básico PHP postgresql
<?php
$dbconn = pg_connect("host= dbname=OTIENDA user= password=")
or die('Could not connect: ' . pg_last_error());
$query = file_get_contents('data.txt');
$time_start = microtime_float();
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
$time_end = microtime_float();
$time = round($time_end - $time_start, 3);