Skip to content

Instantly share code, notes, and snippets.

View montanaflynn's full-sized avatar

Montana Flynn montanaflynn

View GitHub Profile
@montanaflynn
montanaflynn / port.go
Created January 7, 2016 08:21
Port package which finds available ports or checks if a port is available
package port
import (
"net"
"strconv"
)
// New gets an available port
func New() (port int, err error) {
@montanaflynn
montanaflynn / check_for_dependencies.sh
Last active January 23, 2023 13:39
Checking for dependencies in a shell script
# Easy way to check for dependencies
checkfor () {
command -v $1 >/dev/null 2>&1 || {
echo >&2 "$1 required";
exit 1;
}
}
checkfor "ffmpeg"
@montanaflynn
montanaflynn / kong-dns.md
Last active March 2, 2022 12:46
Example of using Kong with DNS

Kong

Kong is a powerful proxy built on nginx. By taking a request and passing it to an upstream server and then returning the result to the client Kong can perform his magic. To know which requests go to which service Kong looks for a Host header to match against. There's a few other ways Kong can match requests to services but for now that's the most basic route. Pun intended.

Start

Assuming everything has been installed and setup, such as dependencies and config files which can be found in the docs, it's time to turn Kong on. The first time Kong runs you'll see some Kong config values and initial migrations to the datastore.

kong start
@montanaflynn
montanaflynn / calculator.js
Created August 24, 2014 07:35
Simple calculator in javascript
function Calculator(num){
return {
answer : num ? num : 0,
equals : function() {
return this.answer
},
add : function(num) {
this.answer += num ? num : 1
return this
},
@montanaflynn
montanaflynn / api.js
Last active October 19, 2021 00:35
Simple express api to get website meta data
// API stuff like routing, etc...
var express = require('express')
// To get the meta data, custom
var getMetaData = require("./meta.js")
// Create express api and route
express().get('/', function(req, res) {
// Get the query parameter url
@montanaflynn
montanaflynn / setup.md
Last active September 16, 2021 12:10 — forked from fortunto2/setup.md
Setup Amazon AWS EC2 g2.2xlarge instance with OpenCV 3.1, Cuda 7.5, ffmpeg, OpenFace
@montanaflynn
montanaflynn / poker.go
Last active May 1, 2021 20:08
Generate a deck of cards, shuffle it and then deal them out in Golang
package main
import (
"fmt"
"math/rand"
"os"
"time"
)
// Card holds the card suits and types in the deck
@montanaflynn
montanaflynn / README.md
Last active March 9, 2021 00:45
Docker logs to ELK stack

Three steps to viewing docker logs in kibana

1) Save this to ./logstash.conf:

# Docker can send logs in gelf format
input {
  gelf { }
}
@montanaflynn
montanaflynn / BENCHMARK.md
Last active January 29, 2021 13:27
Kong Benchmark Setup

To reproduce Kong's benchmark please follow these instructions.

Create AWS Instances

Spin up three m3.medium EC2 ubuntu 14.04 instances with public DNS enabled and configure them for high network traffic by increasing these limits:

Added fs.file-max=80000 to /etc/sysctl.conf

Added the following lines to /etc/security/limits.conf

@montanaflynn
montanaflynn / promise-timeout.js
Last active January 26, 2021 03:52
Example of running all parallel promises with a race timeout promise in javascript
const promise1 = new Promise((resolve, reject) => {
setTimeout(resolve, 50, 'one');
});
const promise2 = new Promise((resolve, reject) => {
setTimeout(resolve, 60, 'two');
});
const promise3 = new Promise((resolve, reject) => {
setTimeout(resolve, 70, 'three');