Skip to content

Instantly share code, notes, and snippets.

View nikmartin's full-sized avatar

Nik Martin nikmartin

View GitHub Profile
@nikmartin
nikmartin / A: Secure Sessions Howto
Last active April 7, 2024 21:56
Secure sessions with Node.js, Express.js, and NginX as an SSL Proxy
Secure sessions are easy, but not very well documented.
Here's a recipe for secure sessions in Node.js when NginX is used as an SSL proxy:
The desired configuration for using NginX as an SSL proxy is to offload SSL processing
and to put a hardened web server in front of your Node.js application, like:
[NODE.JS APP] <- HTTP -> [NginX] <- HTTPS -> [PUBLIC INTERNET] <-> [CLIENT]
Edit for express 4.X and >: Express no longer uses Connect as its middleware framework, it implements its own now.
@nikmartin
nikmartin / hubspot_csv.js
Last active November 23, 2022 02:10
A short example of how to use the hubspot api in node.js to get a full CSV export of your contacts
/**
hubspot API FULL CSV Export
A short example of how to use the hubspot api in node.js to get a full CSV export of your Hubspot contacts
The MIT License (MIT)
Copyright (c) 2015 Nik Martin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
@nikmartin
nikmartin / twiml.gs
Created November 9, 2015 21:38
Google Apps Script to produce Twilio TWIML
function doGet(e) {
var toNum = e.parameter.PhoneNumber;
var fromNum = e.parameter.CallerId;
var action = e.parameter.Direction;
var record = e.parameter.Record;
Logger.log(e);
var output = ContentService.createTextOutput();
var xml = createDialTWIML(fromNum, toNum, action);
@nikmartin
nikmartin / gist:a70f500a41b051a1bdd137d415d5d900
Last active December 30, 2019 16:05
Cleanup your mp3 directory
1. install mp3val
2. find . -name "*.mp3" -print0 | xargs -0 mp3val -si -f -t -nb
rename double extensions
shopt -s globstar
for i in **/*.mp3.mp3; do
echo mv -nv -- "$i" "${s/\.mp3\.mp3/\.mp3/g}"
done
@nikmartin
nikmartin / README.md
Last active November 9, 2018 17:27
High Performance Batched updates in Firestore

Batched updates in Firestore

This short script shows how to do a batched update of a very large data set in firestore.

The scenario is I have a large set of products, and a 'pool' of product codes that need to be assigned to them. This script loads the list of UPC codes from a firebase database, then updates a firestore collection, updating every doc with a UPC code. For each product, the next code docID is assigned (so it's reall a pointer to the code, not the code itself), then the code is updated to signify that is has been assigned.

@nikmartin
nikmartin / namecheap-ddns.sh
Last active April 5, 2018 13:52 — forked from dalhundal/namecheap-ddns.sh
Shell script to update namecheap.com dynamic dns for a domain with your external IP address
#!/bin/sh
# Shell script to update namecheap.com dynamic dns
# for a domain to your external IP address
HOSTNAME=yoursubdomain
DOMAIN=yourdomainname.com
PASSWORD=y0urp455w0rd
curl "https://dynamicdns.park-your-domain.com/update?host=$HOSTNAME&domain=$DOMAIN&password=$PASSWORD"
"use strict";
module.exports = function () {
return function (req, res, next) {
//do stuff here
debug("NEEEXT!");
return res.end();
@nikmartin
nikmartin / server.js
Last active December 19, 2015 13:29
Simple node.js web server - Now even simpler!
1. Create a directory, and cd to it:
~/myserver> mkdir myserver && cd myserver
2. install send:
~/myserver> npm install send
3. Create your server:
~/myserver> cat > server.js << EOF
"use strict";
var http = require('http'),
send = require('send'),
{"posts":[
{ "title": "title1", "date": "03-21-2013" },
{ "title": "title2", "date": "03-21-2013" },
{ "title": "title3", "date": "03-21-2013" },
{ "title": "title4", "date": "03-21-2013" }]
}
@nikmartin
nikmartin / GetNextUpcomingDate.js
Last active October 28, 2015 21:51
This javascript snippet gets the date of the next day requested
function getNextDate(whichDay) {
console.log(whichDay);
var today = new Date(); //Wed Oct 28 2015
var currentDayOfWeek = today.getDay(); //0-6
var thisWeeksSunday = today.getDate() - currentDayOfWeek; //1-31
var theDate = today;
//if whichDay has not happened this week yet:
if (whichDay > currentDayOfWeek) { //then get this weeks whichday