Skip to content

Instantly share code, notes, and snippets.

@rw3iss
rw3iss / backup.sh
Last active August 23, 2022 03:22
Duplicity System Backup Script (to Google Drive)
# Modified from: https://gist.github.com/playfulcorgi/4582f46e91d8ccaaf417341efb30d459
# Set as cronjob every night at 1AM:
# crontab -e
# * 1 * * * /home/rw3iss/scripts/backup.sh
# backup.sh
export GOOGLE_DRIVE_SETTINGS="/home/rw3iss/scripts/.duplicity.credentials.yml"
export PASSPHRASE="YOUR_PASSWORD"
@rw3iss
rw3iss / isomorphic-fetch.js
Created February 10, 2021 11:51
isomorphic-fetch for fetchMock
const isoFetch = jest.requireActual('isomorphic-fetch');
const fetchMock = require('fetch-mock').sandbox();
Object.assign(fetchMock.config, {
fetch: isoFetch
});
fetchMock.config.fallbackToNetwork = true;
fetchMock.config.overwriteRoutes = false;
@rw3iss
rw3iss / bootstrap.test.tsx
Created February 10, 2021 13:11
Jest + Enzyme test bootstrap
import 'jsdom-global/register';
import { configure, mount } from 'enzyme';
import { h } from 'preact';
import Adapter from 'enzyme-adapter-preact-pure';
configure({ adapter: new Adapter });
jest.mock('isomorphic-fetch');
const waitForPromises = () => new Promise(setImmediate)
@rw3iss
rw3iss / mkDirSync.js
Last active March 9, 2021 18:16
Make a directory if it doesn't exist (sync)
var mkdirSync = function(dir) {
if (fs.existsSync(dir)) {
return;
}
try {
fs.mkdirSync(dir);
} catch(err){
if(err.code == 'ENOENT'){
@rw3iss
rw3iss / build.js
Last active June 10, 2023 20:29
esbuild.js frontend build script
var fs = require("fs");
var path = require("path");
// Config params (relative to where npm/script is called from):
const APP_BASE = './src';
const ENTRY_FILE = `index.tsx`;
const OUTPUT_DIR = './build';
const OUTPUT_FILE = 'app.js';
const IS_DEV = false;
const TARGET = 'es2018';
@rw3iss
rw3iss / tmux.sh
Last active October 5, 2023 06:29
tmux.sh
#!/bin/sh
tmux new-session -d
tmux split-window -h
tmux select-pane -t 0
dir=$(PWD)
tmux send-keys -t 0 "cd client" Enter
tmux send-keys -t 0 "npm run dev" Enter
@rw3iss
rw3iss / esbuildEnvFilePlugin
Created February 15, 2021 18:13
esbuild local .env file loader plugin
let envFilePlugin = {
name: 'env',
setup(build) {
function _findEnvFile(dir) {
if (!fs.existsSync(dir))
return false;
let filePath = `${dir}/.env`;
if ((fs.existsSync(filePath))) {
@rw3iss
rw3iss / build.js
Last active June 10, 2023 20:29
esbuild script for node/server-side
// Config: relative to where npm command is run:
const APP_BASE = 'src';
const ENTRY_FILE = 'index.ts';
const OUTPUT_DIR = 'build';
const OUTPUT_FILE = 'app.js';
const IS_DEV = true;
const TARGET = 'es2018';
function build(entryFile, outFile) {
require('esbuild').build({
@rw3iss
rw3iss / launch.js
Last active April 11, 2021 01:35
browsersync script to hot reload any client project
const bs = require('browser-sync').create();
const url = require('url');
const fs = require('fs');
const path = require('path');
const PORT = 3300
const OUTPUT_DIR = './build'
const DEFAULT_FILE = "index.html"
bs.watch(`${OUTPUT_DIR}/**/*.js`, function (event, file) {
@rw3iss
rw3iss / config.js
Created March 2, 2021 17:14
Config file per environment loader
import { ENV } from 'env';
import fs from 'fs';
import path from 'path';
let prefix = './config/';
let configFile = 'config.local.json';
if (ENV == 'production') {
configFile = 'config.prod.json';
} else if (ENV == 'development') {