Skip to content

Instantly share code, notes, and snippets.

@jadwigo
jadwigo / mysql_convert_blocksource_to_target.sql
Created January 29, 2020 16:05
Convert block type CMS entries to Rich HTML Textarea entries - with JSON objects too
-- # Convert block type CMS entries to Rich HTML Textarea entries - with JSON objects too #
-- Because there will be large joins make this size ridiculous
SET SESSION group_concat_max_len = 6000000;
-- String variable replacement in mysql is handy
SET @uploads_target_path = CAST('/storage/uploads/' AS CHAR CHARACTER SET utf8);
-- this inserts rows with concatenated formatted blocks
-- from source_db.page and source_db.block
@jadwigo
jadwigo / mysql_split_magic.sql
Last active January 15, 2020 20:19
Mysql split
-- https://stackoverflow.com/a/22669310/1531963
-- Assuming that the comma separated list is in table data.list,
-- and it contains listing of codes from other table classification.code, you can do something like:
SELECT
d.id, d.list, c.code
FROM
classification c
JOIN data d
ON d.list REGEXP CONCAT('[[:<:]]', c.code, '[[:>:]]');
@jadwigo
jadwigo / fix-digitalocean-composer-memory-problems.md
Last active October 1, 2023 17:07
Composer memory problems on digital ocean

If composer runs out of memory on digitalocean or another RAM limited cloud VM You need to create a swap drive

Create and activate the swapdrive as superuser And get back to the normal shell

sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=8192
sudo chmod 600 /var/swap.1
sudo /sbin/mkswap /var/swap.1
sudo /sbin/swapon /var/swap.1
@jadwigo
jadwigo / fn.slugify.sql
Last active October 11, 2019 11:54 — forked from jareis-zz/fn.slugify.sql
slugify function for MySQL
-- The MIT License (MIT)
-- Copyright (c) 2014 jose reis<[email protected]>
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
-- The above copyright notice and this permission notice shall be included in all
@jadwigo
jadwigo / lookupProvincie.php
Created February 19, 2019 13:46
Lookup provincie ahv postcode
<?php
/**
* Lookup provincie ahv postcode:
* https://nl.wikipedia.org/wiki/Postcodes_in_Nederland
*
* @param $postcode
*
* @return string
*/
function lookupProvincie($postcode, $location = false)
@jadwigo
jadwigo / split.sh
Created January 31, 2019 12:14
move many files to subdirectories
#!/bin/bash
# This script takes a directory with many files and moves all nnormal files
# to a subdirectory with the year-month
for i in *
do
if [ -f "$i" ]
then
filemonth=`stat --format=%y "$i" | cut -c 1-7`
@jadwigo
jadwigo / backup.sql
Created January 14, 2019 10:29
Backup and restore a mysql database
mysqldump -u {user} -p{pass} {db} > {outputfile}.sql
@jadwigo
jadwigo / master.twig
Created September 27, 2018 10:05
Master with header includes
<!doctype html>
<html class="no-js" lang="{{ htmllang() }}">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{%- if seo.title is defined -%}
{{ seo.title }}
{%- elseif record.title is defined -%}
{{ record.title }} | {{ config.get('general/sitename') }}
@jadwigo
jadwigo / composer.json
Created July 31, 2018 13:37
Bolt extension from custom git repository
{
"autoload": {
"psr-4": {
"Bolt\\Composer\\EventListener\\": "../vendor/bolt/bolt/src/Composer/EventListener"
}
},
"config": {
"discard-changes": true,
"preferred-install": "dist"
},
@jadwigo
jadwigo / config.xml
Last active October 5, 2018 18:15
Cordova cli-8.0.0 config.xml for geolocation
<?xml version='1.0' encoding='utf-8'?>
<widget
id="com.example.appname"
xmlns="http://www.w3.org/ns/widgets"
xmlns:cdv="http://cordova.apache.org/ns/1.0"
xmlns:gap="http://phonegap.com/ns/1.0"
versionCode="10203"
version="1.2.3">
<name>appname</name>