Skip to content

Instantly share code, notes, and snippets.

View tacone's full-sized avatar
💭
¯\_(ツ)_/¯

tacone

💭
¯\_(ツ)_/¯
View GitHub Profile
@tacone
tacone / deploy
Created April 10, 2024 13:42
deploy
#!/bin/bash
# ------------------------------------------------------------------
# This script deploys the application to production
#
# example:
#
# scripts/deploy
# ------------------------------------------------------------------
@tacone
tacone / sendmail.sh
Created August 9, 2022 12:39
Send a mail from the CLI using an external SMTP server
#!/bin/bash
echo -e '\n\nSample test body' | LC_ALL=C mail -Sv15-compat -Sttycharset=utf8 \
-S 'mta=smtp://smtpuser:smtppassword@smtphost:587' -S 'smtp-auth=plain' \
-a 'attachment.bin' \
-r '[email protected]' \
-s 'sample subject' \
-t '[email protected]'
@tacone
tacone / cacheburn.js
Created March 7, 2022 22:25
Add timestamp to every image and update the HTML files to link to the renamed images
import fastGlob from 'fast-glob';
import crypto from 'crypto';
import path from 'path';
import fs from 'fs';
// I could try to parse the HTML files using cheerio[1], but a simple find and replace
// is likely to be faster, more powerful and - realistically - quite as much as reliable.
//
// [1] just like this: https://github.com/maxogden/inline-images/blob/master/index.js
@tacone
tacone / isSafeUrl.js
Created February 18, 2022 20:41
Make sure a Url is safe to call from your service
import hostnameIsPrivate from "hostname-is-private";
import { promisify } from "util";
const isSafeUrl = async (untrustedUrl, protocols = ["http", "https"]) => {
try {
// will throw error on malfomed url
const url = new URL(untrustedUrl);
// no protocol, no fun
if (!url.protocol) return false;
@tacone
tacone / inspectSchema.graphql
Created May 5, 2021 19:30
A query to print the whole schema
fragment FullType on __Type {
kind
name
fields(includeDeprecated: true) {
name
args {
...InputValue
}
type {
...TypeRef
@tacone
tacone / script.sh
Created December 1, 2020 14:58
How to use file locking
#!/bin/bash
# will wait
flock -n /tmp/mycommand.flock mycommand
# -n makes it fail rather than wait
flock -n /tmp/mycommand.flock mycommand
@tacone
tacone / utils.sh
Last active January 23, 2024 15:22
bash logging function
#!/bin/bash
ignore () { true }
warning () { echo "$@" }
error () { ERR=$?; echo "$@"; return $ERR }
# --- Usage
#
# set -e;
#
@tacone
tacone / map.sh
Created May 26, 2020 10:23
Sample code to remap the keyboard
#!/bin/bash
xmodmap -e "keycode 66 = Mode_switch"
xmodmap -e "keysym i = i I Up"
xmodmap -e "keysym j = j J Left"
xmodmap -e "keysym k = k K Down"
xmodmap -e "keysym l = l L Right"
xmodmap -e "keysym u = u U Prior"
xmodmap -e "keysym o = o O Next"
@tacone
tacone / wait-port.sh
Created October 10, 2019 10:46
Wait for a port to be open (i.e. for the db to be ready)
#!/bin/bash
set -e
echo "Waiting for port opening on ${1}:${2}..."
function check_port() {
local host=${1} && shift
local port=${1} && shift
local retries=90
local wait=1
<?php
/*
|--------------------------------------------------------------------------
| Check for maintenance
|--------------------------------------------------------------------------
|
| Se l'applicazione è standby proviamo ad aspettare che torni su. In questo
| modo l'utente non riceve messaggi di errore durante il deploy, non perde
| i dati inviati nel form, etc.