Skip to content

Instantly share code, notes, and snippets.

View andris9's full-sized avatar
🇪🇪

Andris Reinman andris9

🇪🇪
View GitHub Profile
@andris9
andris9 / USAGE.md
Created September 1, 2016 08:43
Replace domain name in Wordpress database dump

wp-domain-change

Simple script to replace domain name in a Wordpress MySQL dump file. In addition to replacing domain names in standard string values, the script is able to correctly replace strings in serialized PHP values. This means that it should be safe to operate on data from wp_options table where plugins store data as serialized PHP

Usage

Run the script from command line. First argument is the domain name to replace and the second is the replacement. SQL dump is read from stdin and written to stdout

node wp-domain-change.js "http://source.domain" "http://dest.domain" < input.sql > output.sql

@andris9
andris9 / git-cache-meta.sh
Created March 5, 2012 13:15
git-cache-meta
#!/bin/sh -e
#git-cache-meta -- simple file meta data caching and applying.
#Simpler than etckeeper, metastore, setgitperms, etc.
#from http://www.kerneltrap.org/mailarchive/git/2009/1/9/4654694
#modified by n1k
# - save all files metadata not only from other users
# - save numeric uid and gid
# 2012-03-05 - added filetime, andris9
@andris9
andris9 / forwarder.js
Last active February 13, 2024 07:33
Process emails without data loss
'use strict';
// $ npm install nodemailer mailsplit libmime
// $ node forwarder.js
const nodemailer = require('nodemailer');
const mailsplit = require('mailsplit');
const libmime = require('libmime');
const Transform = require('stream').Transform;
@andris9
andris9 / onion.js
Created March 24, 2021 12:43
Generate onion v3 address from ed25519 public key
// npm install hi-base32 sha3
const base32 = require("hi-base32");
const { SHA3 } = require("sha3");
function verifyOnionAddress(addr) {
const suffixLength = ".onion".length;
if (!/\.onion$/i.test(addr) || addr.length != 56 + suffixLength) {
return false;
}
@andris9
andris9 / ratelimit.js
Created January 8, 2024 13:53
Vaese mehe rate limit 1 tund
'use strict';
const Redis = require('ioredis');
const redis = new Redis({
port: 6379,
host: '127.0.0.1'
});
async function rateLimitedIp(ip) {
const rlKey = 'ratelimits';
@andris9
andris9 / submit.sh
Created November 29, 2023 09:28
Example script to submit large attachments to EmailEngine
#!/bin/bash
# This example script submits large attachments
# Usage
# 1. Edit the variables below
# 2. Run the script
# $ bash ./submit.sh
## EDIT THE FOLLOWING VALUES
@andris9
andris9 / transport.js
Created March 4, 2023 16:54
Custom DNS resolving with Nodemailer
// The following example sets up Nodemailer in a way that it does not perform any DNS resolving on its own
const hostname = 'smtp.gmail.com';
const resolved = (await dns.promises.resolve(hostname))[0];
const transporter = nodemailer.createTransport({
host: resolved, // <- IP address of the SMTP server
name: 'my.machine.hostname', // <- PTR name of sender's public IP address, ends up in the Recieved: header
tls: {
servername: hostname, // <- hostname of the SMTP server, needed to verify TLS
@andris9
andris9 / README.md
Last active December 29, 2022 02:38
Extremely simple HTTP proxy for changing Host: header Useful when proxying requests to virtual hosts that require Host: header to be set.

Setup reverse tunnel

Run the following in your client machine

ssh -R EXPOSED_PORT:localhost:SERVICE_PORT USER@HOST

Where

  • EXPOSED_PORT is the port exposed to the internet in the proxy server
  • SERVICE_PORT is the port your application is listening in your machine
'use strict';
// npm install nodemailer nodemailer-smtp-pool
var nodemailer = require('nodemailer');
var smtpPool = require('nodemailer-smtp-pool');
// Create a SMTP transporter object
var transport = nodemailer.createTransport(smtpPool({
host: 'smtp.gmail.com',
port: 465,
secure: true,
@andris9
andris9 / mandrill.js
Last active August 10, 2022 20:38
Nodemailer using Mandrill
'use strict';
// Nodemailer: v2.0.0
// Ubuntu: 14.04
// node: v5.5.0
// npm: 3.3.12
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'Mandrill',