Skip to content

Instantly share code, notes, and snippets.

View tuesd4y's full-sized avatar

Chris Stelzmüller tuesd4y

View GitHub Profile
@tuesd4y
tuesd4y / HappyNumbers.kt
Last active June 13, 2022 09:02
Calculate all happy numbers from 0 to 100
/**
* What's a happy number? https://en.wikipedia.org/wiki/Happy_number
*
* Simple brute force solution that just evaluates if the happy number sequence reaches one within [MAX_DEPTH] iterations.
*/
object HappyNumbers {
const val MAX_DEPTH = 10_000
@JvmStatic
@tuesd4y
tuesd4y / tuesd4y.postgis.postfixTemplates
Last active April 27, 2021 15:15
IntelliJ custom postfix templates - depends on https://plugins.jetbrains.com/plugin/9862-custom-postfix-templates being installed.
# Custom postfix templates useful for postgis functions - created by tuesd4y
# see www.tuesd4y.com
.trans : transform geometry into WG84 (=SRID 4326)
ANY -> ST_TRANSFORM($expr$, 4326)
.transform : transform geometry into another CRS
ANY -> ST_TRANSFORM($expr$, $NAME#1::4326$)
.trans3 : transform geometry into 3035 lambert azimuthal covering europe
@tuesd4y
tuesd4y / example_out.csv
Created April 2, 2020 13:42
transform ippodo.co.jp tea order into a machine-readable csv file
502612 Kumpu 100g Bag(Green Tea) Gift Wrapping?:No 2000
408612 Hekiun 100g Bag(Green Tea) Gift Wrapping?:No 1400
602102 Kuki Hojicha (Roasted Stems) 100g Bag(Green Tea) Gift Wrapping?:No 500
606612 Gokujo Genmaicha 100g Bag(Green Tea) Gift Wrapping?:No 450
133624 Horai-no-mukashi 20g Can(Green Tea) Gift Wrapping?:No 1100
182024 Shoin-no-mukashi 20g Can(Green Tea) Gift Wrapping?:No 1500
103644 Sayaka-no-mukashi 40g Can (Green Tea) Gift Wrapping?:No 2200
643402 Mugicha (Barley Tea) 400g Bag Gift Wrapping?:No 380
642152 Uji-Shimizu 150g Bag(Green Tea) Gift Wrapping?:No 300
136623 Enishi-no-shiro 20g Box(Green Tea) Gift Wrapping?:No 600
@tuesd4y
tuesd4y / helper_functions.sql
Last active April 14, 2021 13:25
GIS stuff
CREATE OR REPLACE FUNCTION f(geom geometry, variadic rec anyarray) RETURNS json AS
$$
BEGIN
RETURN
json_build_object(
'type', 'Feature',
'id',
'null', -- the GeoJson spec includes an 'id' field, but it is optional. some services still cry if it's not in there, so we leave it empty just for now.
'geometry', ST_AsGeoJSON(geom)::json,
'properties', json_build_object(variadic rec)
@tuesd4y
tuesd4y / Main.kt
Last active October 10, 2019 07:43
imagemagick scripts
package at.triply.backend.eventbackend
import java.io.File
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
import java.util.concurrent.TimeUnit
object Main {
@JvmStatic
@tuesd4y
tuesd4y / hexgrids.sql
Last active March 20, 2020 17:53
[hex grids from postgres table]
CREATE OR REPLACE PROCEDURE create_hex_grid(source_table_name varchar(30), height numeric = 1000, srid integer = 31287,
geom_column_name varchar(30) = 'geom', target_table_name varchar(30) = 'hexgrid')
LANGUAGE plpgsql
AS
$$
DECLARE
_curs refcursor ;
_width NUMERIC := height * 0.866;
_geom GEOMETRY;
_hx GEOMETRY := ST_GeomFromText(
package at.triply.backend.test
import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.jupiter.api.extension.TestExecutionExceptionHandler
import java.net.URLEncoder
class TestAdditionalOutputExtension : TestExecutionExceptionHandler {
override fun handleTestExecutionException(context: ExtensionContext?, throwable: Throwable) {
println("============================================================================================\n" +
"Hey, there seems to be something wrong with the test!\n" +
package at.triply.backend.test
import org.junit.jupiter.api.extension.ExtensionContext
import org.junit.jupiter.api.extension.TestExecutionExceptionHandler
import java.net.URLEncoder
class TestAdditionalOutputExtension : TestExecutionExceptionHandler {
override fun handleTestExecutionException(context: ExtensionContext?, throwable: Throwable) {
println("============================================================================================\n" +
"Hey, there seems to be something wrong with the test!\n" +
@tuesd4y
tuesd4y / export_to_csv.sql
Last active March 11, 2019 10:04
export distance summaries with points from postgres (+postgis) db to csv file. Includes coordinates of customers and stops, as well as spherical distance
\copy (select cd.name, pv.id as variation_id,
st_distance_sphere(cd.location, pv.location) as distance,
cd.city,
cd.address,
li.name as product,
pv.stop as bus_stop,
ST_X(pv.location) as stopX,
ST_Y(pv.location) as stopY,
ST_X(cd.location) as customerX,
ST_Y(cd.location) as customerY
dependencies {
...
implementation('org.springframework.boot:spring-boot-starter-security')
...
}