Skip to content

Instantly share code, notes, and snippets.

@joenas
joenas / useOnce.js
Created April 20, 2022 11:42
React useOnce hook for one-time effects
import { useEffect, useRef } from 'react';
const useOnce = (effect) => {
const didUse = useRef(false);
useEffect(() => {
if (didUse.current === false) {
didUse.current = true;
effect();
}
@joenas
joenas / docker-compose.yaml
Last active March 26, 2022 14:14
Matrix docker-compose with Postgres and docker network
### To use this file you need to run
### $ docker network create matrix-network
version: "2"
services:
postgres:
image: postgres:9.6.4
restart: always
# I like to be able to use psql on the host to connect to the database
@joenas
joenas / minetest@.service
Created April 10, 2017 13:17
Minetest systemd service for user
[Unit]
Description=Minetest server
After=syslog.target network.target
[Service]
Type=simple
Restart=on-failure
ExecStart=/usr/bin/minetest --server --world /home/minetest/.minetest/worlds/%i --gameid %i --config server.conf
[Install]
@joenas
joenas / matrix_synapse.nginx.conf
Last active May 14, 2021 16:53
Nginx example conf for Synapse matrix Homeserver
# vim: syntax=nginx
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
@joenas
joenas / script-template.sh
Created December 15, 2020 12:49 — forked from m-radzikowski/script-template.sh
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1
trap cleanup SIGINT SIGTERM ERR EXIT
usage() {
cat <<EOF
#!/bin/bash
timestamp=$(($(date +%s%N)/1000000))
curl --header "Authorization: Bearer $1" -d '{}' -H 'Content-Type: application/json' localhost:8008/_synapse/admin/v1/purge_media_cache?before_ts=$timestamp
@joenas
joenas / ghost_huginn_twitter.json
Created August 12, 2017 13:36
Huginn scenario to post new blog posts from Ghost to Twitter
{
"schema_version": 1,
"name": "Ghost to Twitter",
"description": "Post your Ghost blog posts to Twitter",
"source_url": false,
"guid": "8b950438b4618fac9fbe5f400a32bafa",
"tag_fg_color": "#FFFFFF",
"tag_bg_color": "#5BC0DE",
"icon": "pencil",
"exported_at": "2017-08-12T13:31:40Z",
@joenas
joenas / parallel_spec_notifier.rb
Created April 19, 2017 13:08
OS X notifications with parallel_spec
#!/usr/bin/env ruby
require 'terminal-notifier-guard'
path = ARGV[0] || 'spec'
output = `parallel_rspec #{path} -n 8 --nice`
num = output.scan(/(\d) failure/).flatten.map(&:to_i).inject(0, &:+)
meth = (num>0) ? :failed : :success
TerminalNotifier::Guard.send(meth, "#{num} failures", title: 'RSpec results')
$?.success?