Skip to content

Instantly share code, notes, and snippets.

@technetium
technetium / d_to_hdm
Created October 14, 2023 19:17
MySql function to convert decimal degrees to Half, Decimal and Minutes
CREATE FUNCTION D_TO_HDM(value FLOAT, halfs TEXT)
RETURNS TEXT
RETURN CONCAT(
IF(value > 0, LEFT(halfs, 1), RIGHT(halfs, 1)), FLOOR(ABS(value+1/120000)) , ' '
, LPAD(FLOOR((ABS(value+1/120000)-FLOOR(ABS(value+1/120000)))*60), 2, "0") , '.'
, LPAD(ROUND((ABS(value+1/120000)*60-FLOOR(ABS(value+1/120000)*60))*1000), 3, "0")
)
;
@technetium
technetium / gc_code_to_id
Last active May 27, 2024 17:26
MySql functions to convert geocaching codes to id and back (Remove the GC, PR, and other prefixes)
CREATE FUNCTION GC_ID_TO_CODE(p_id INT)
RETURNS TEXT
DETERMINISTIC
RETURN IF (
p_id < 65536,
CONV(p_id, 10, 16),
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(CONV(p_id+411120, 10, 31),
'U', 'Z'), 'T', 'Y'), 'S', 'X'), 'R', 'W'), 'Q', 'V'), 'P', 'T'), 'O', 'R'), 'N', 'Q'), 'M', 'P'), 'L', 'N'), 'K', 'M'), 'J', 'K'), 'I', 'J')
)
@technetium
technetium / geldvoorelkaar.html
Created January 23, 2020 09:47
Geldvoorelkaar cloudflare
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
<meta name="robots" content="noindex, nofollow" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>Just a moment...</title>
<style type="text/css">
<!-- Short Description -->
<img src="http://img.geocaching.com/76d138fb-5ca6-4c04-a816-b9432babb5cf.gif" width="18" height="12" alt="NL" />
Een omgekeerde geocache, maar dan anders.<br />
<!-- /Short Description -->
<br />
<!-- Long Description -->
<img src="http://img.geocaching.com/36046a42-78d5-4721-a65e-f394309a446f.gif" width="18" height="12" alt="EN" />
A reverse geocache, but different.<br />
<?php
namespace AppBundle\Twig\Extension;
/**
* A TWIG Extension which allows to generate a range of excel columns
* Since excel works with column names instead of numbers a range of names is needed.
*/
class ExcelExtension extends \Twig_Extension
{
@technetium
technetium / Association-management-methods.md
Last active October 26, 2018 08:13
Association Management Methods

Altough the Doctrine documentation about Working with associations states: "proper bidirectional association management in plain OOP is a non-trivial task and encapsulating all the details inside the classes can be challenging" I've used the following management methods (getters. setters, adders and removers) quite successfully.

@technetium
technetium / wilson.sql
Last active August 3, 2016 16:15
A function to calculate Lower bound of Wilson score confidence interval for a Bernoulli parameter @see http://www.evanmiller.org/how-not-to-sort-by-average-rating.html For this formula the interval is set at 95%
CREATE FUNCTION wilson(stars INT, total INT)
RETURNS REAL DETERMINISTIC
RETURN IF (
total,
(
(stars + 1.9208) / total -
1.96 * SQRT((stars * (total-stars)) / total + 0.9604) / total
) / (1 + 3.8416 / total),
0
)
@technetium
technetium / distance.sql
Last active March 29, 2019 10:26
Create a function to calculate the distance between two points on the earth. This function assumes the input to be decimal degrees and the earth to be a sphere with a radius of 6371 km
CREATE FUNCTION distance (lat1 REAL, lng1 REAL, lat2 REAL, lng2 REAL)
RETURNS REAL DETERMINISTIC
RETURN 2 * 6371 * ASIN(SQRT(
SIN(RADIANS(lat1 - lat2)/2) * SIN(RADIANS(lat1 - lat2)/2) +
COS(RADIANS(lat1)) * COS(RADIANS(lat2)) *
SIN(RADIANS(lng1 - lng2)/2) * SIN(RADIANS(lng1 - lng2)/2)
));
@technetium
technetium / .Propagating-awareness-via-ManyToOne-associations.md
Created April 14, 2016 07:47
Propagating awareness via ManyToOne associations

Propagating awareness via ManyToOne associations

Introduction

Michaël Perrin has written an article about using annotation and filters improve security.

With a more complex model, for example an order that contains products, you want also to filter on the associations of the filtered entity.