Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@joshlarsen
joshlarsen / server.js
Created October 19, 2018 18:11
Simple node.js proxy with dynamic route lookups via Redis
const http = require('http');
const httpProxy = require('http-proxy');
const redis = require('redis');
// listen port
const port = 5050;
// redis client
const client = redis.createClient();
@joshlarsen
joshlarsen / irb.rb
Created January 9, 2019 19:04
Ruby backtrace in IRB
begin
# Some exception throwing code
rescue => e
puts "Error during processing: #{$!}"
puts "Backtrace:\n\t#{e.backtrace.join("\n\t")}"
end
@joshlarsen
joshlarsen / app.js
Created March 19, 2019 18:38
Google Cloud Functions Node.js 8 Simple Emulator
/**
* Inspiration taken from here https://github.com/GoogleCloudPlatform/cloud-functions-emulator/issues/258#issuecomment-413786762
* Alternative: https://github.com/GoogleCloudPlatform/cloud-functions-emulator/issues/258#issuecomment-407996126
*
* Original: https://github.com/GoogleCloudPlatform/cloud-functions-emulator/issues/258#issuecomment-437080813
*/
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
@joshlarsen
joshlarsen / dns.sh
Created March 19, 2019 18:45
DNSimple dynamic IP update script
#!/bin/bash
#
# Update DNSimple DNS record if ISP IP changes
#
# Requirements:
# existing DNS record hosted with DNSimple
# curl in $PATH
#
# run from cron
#
@joshlarsen
joshlarsen / down.sh
Created June 16, 2020 15:46
Monitor IPS uptime by pinging an external IP
#!/bin/bash
#
# Ping external IP from wired network to monitor for ISP outtage
# 2020-06-16
#
# runs on pi-hole from cron every day
#
# kill any other instances running
# name log file day_of_month_down.txt
# remove todays log file if there is one, since it will be a month old
@joshlarsen
joshlarsen / app.rb
Last active February 28, 2021 15:45
Faktory polyglot speed tests
require 'connection_pool'
require 'faktory'
T = ARGV[0].to_i
puts "Starting #{T} jobs for each (ruby, node, python)"
puts Time.now()
SomeRubyWorker = Faktory::Job.set(queue: 'ruby', jobtype: 'RubyWorker')
SomeNodeWorker = Faktory::Job.set(queue: 'node', jobtype: 'nodeWorker')
SomePythonWorker = Faktory::Job.set(queue: 'python', jobtype: 'python_worker')
@joshlarsen
joshlarsen / netcat_web_server_one_liner.sh
Created April 22, 2021 20:48
netcat web server one liner
while true; do echo -e "HTTP/1.1 200 OK\n\n $(date)" | nc -l localhost 4000; done
@joshlarsen
joshlarsen / 0-opa-json-cheatsheet.md
Created August 20, 2021 20:30 — forked from onelittlenightmusic/0-opa-json-cheatsheet.md
Document for `jr`, `jb` or `jp`

jr, jp, jb (alias to opa eval): Cheatsheet

jr, jp and jb are commands for JSON modification.

Basic usages

$ data='{"name":"chris", "friends":["alice", "bob"]}'
# jr
$ echo $data | jr 'i.name'
@joshlarsen
joshlarsen / redis
Created October 13, 2021 20:05
Rails binstubs
#!/bin/bash
#
# Make sure to stop/start the Redis Docker container properly.
#
CONTAINER_NAME="redis-container"
DOCKER_START="docker start -ai ${CONTAINER_NAME}"
DOCKER_RUN="docker run --name ${CONTAINER_NAME} -p 6379:6379 redis"
# is there an existing container named 'redis'?
@joshlarsen
joshlarsen / cloudSettings
Last active February 3, 2022 22:19
vscode settings
{"lastUpload":"2022-02-03T22:19:36.554Z","extensionVersion":"v3.4.3"}