Skip to content

Instantly share code, notes, and snippets.

View macbre's full-sized avatar
🏠
Working from home

Maciej Brencz macbre

🏠
Working from home
View GitHub Profile
@macbre
macbre / multiformat-wp-api-response.php
Created May 30, 2024 11:36 — forked from petenelson/multiformat-wp-api-response.php
WordPress: Example of returning non-JSON results from the WP-API
<?php
// reference https://github.com/WP-API/WP-API/blob/develop/lib/infrastructure/class-wp-rest-server.php
// serve_request() function
add_filter( 'rest_pre_serve_request', 'multiformat_rest_pre_serve_request', 10, 4 );
function multiformat_rest_pre_serve_request( $served, $result, $request, $server ) {
// assumes 'format' was passed into the intial API route
// example: https://baconipsum.com/wp-json/baconipsum/test-response?format=text
@macbre
macbre / docker-compose.yml
Created May 1, 2024 19:37 — forked from lfache/docker-compose.yml
Mattermost docker-compose.yml with Traefik
version: "3"
services:
db:
build: db
read_only: true
restart: unless-stopped
volumes:
- ./volumes/db/var/lib/postgresql/data:/var/lib/postgresql/data
- /etc/localtime:/etc/localtime:ro
environment:
@macbre
macbre / .gitignore
Last active March 16, 2024 14:09
farerskiekadry.geo
.idea/
@macbre
macbre / truncate_docker_logs.sh
Created November 2, 2023 11:59
Docker utils
#!/bin/bash
# https://docs.docker.com/engine/reference/commandline/ps/#format
df -h /
for container in $(docker ps --format "{{.Names}}")
do
echo "Truncating logs for the '${container}' container ..."
# https://forums.docker.com/t/how-to-limit-or-rotate-docker-container-logs/112378/9
@macbre
macbre / .gitignore
Last active July 14, 2023 14:52
py-facebook-feed
# Byte-compiled / optimized / DLL files
__pycache__/
.pytest_cache/
*.py[cod]
*$py.class
*.swp
# C extensions
*.so
@macbre
macbre / example.ts
Created January 23, 2023 13:32
Async fs.exists()
import { fsExists } from './utils';
if ( ! ( await fsExists( folder ) ) ) {
// ...
}
// open any Daft page and go the dev console
clear();
const data = JSON.parse(document.querySelector('script[id="__NEXT_DATA__"]').textContent);
const listing = data.props.pageProps.listing;
console.log( listing.title );
// grab the images
const images = listing.media.images.map( img => img['size1440x960'] );
@macbre
macbre / bygd_2022.tsv
Last active February 12, 2022 20:20
Faroe Islands - IB01030 Population by sex, age, village/city and month(1985-2022)
We can make this file beautiful and searchable if this error is corrected: It looks like row 4 should actually have 41 columns, instead of 40 in line 3.
"sex" "age" "village/city" "1985 Jan" "1986 Jan" "1987 Jan" "1988 Jan" "1989 Jan" "1990 Jan" "1991 Jan" "1992 Jan" "1993 Jan" "1994 Jan" "1995 Jan" "1996 Jan" "1997 Jan" "1998 Jan" "1999 Jan" "2000 Jan" "2001 Jan" "2002 Jan" "2003 Jan" "2004 Jan" "2005 Jan" "2006 Jan" "2007 Jan" "2008 Jan" "2009 Jan" "2010 Jan" "2011 Jan" "2012 Jan" "2013 Jan" "2014 Jan" "2015 Jan" "2016 Jan" "2017 Jan" "2018 Jan" "2019 Jan" "2020 Jan" "2021 Jan" "2022 Jan"
"Total (sex)" "Total (age)" "Total Faroe Islands" 45347 45677 46240 46880 47570 47772 47347 47203 46735 45259 43640 43323 43745 44226 44760 45342 46127 46941 47648 48146 48299 48120 48262 48302 48603 48485 48431 48178 48029 48122 48590 49099 49791 50462 51273 52103 52899 53664
"Total (sex)" "Total (age)" "Hattarvík" 27 27 27 30 36 37 29 33 40 39 32 30 26 24 22 20 20 18 17 16 17 16 15 16 15 16 17 15 14 14 14 13 13 12 11 11 11 10
"Total (sex)" "Total (age)" "Kirkja" 35 32 32 25 24 24 24 24 24 30 22 21 18 18 19 20 30 30 28 29 28 27 28 26 25 22 22 22 23 28 26 27 32 25 26 27 30
@macbre
macbre / README.txt
Created October 28, 2021 11:38
ts-jest setup
npm remove @types/mocha mocha
npm i --save-dev @types/jest jest
npm i --save-dev ts-jest
npx ts-jest config:init
and provide testRegex entry in jest.config.js file.