Skip to content

Instantly share code, notes, and snippets.

View jimthedev's full-sized avatar

Jim Cummins jimthedev

View GitHub Profile
@jimthedev
jimthedev / .zshrc
Created July 24, 2016 17:22
Hacky first attempt at create-react-app but for https://github.com/HenrikJoreteg/hjs-webpack
# Creates a git and github repo in the projects folder
# and changes the current directory to it
proj() {
echo "Changing directory to ~/projects"
cd ~/projects
echo "Creating directory for project"
mkdir -p "$@"
echo "Changing directory to ~/projects/$@"
cd $@
echo "Creating git repo"
@jimthedev
jimthedev / .zshrc-partial
Created July 27, 2016 22:17
.zshrc fun with hub, git, npm, react, hjs-webpack
# Creates a git and github repo in the projects folder
# and changes the current directory to it
proj() {
echo "Changing directory to ~/projects"
cd ~/projects
echo "Creating directory for project"
mkdir -p "$@"
echo "Changing directory to ~/projects/$@"
cd $@
echo "Creating git repo"
@jimthedev
jimthedev / howto.md
Last active January 22, 2019 18:54
digital ocean, dokku, rethinkdb, lets encrypt, horizon

NOTE: THESE ARE INCOMPLETE AND THE STEPS LISTED HERE WILL ABSOLUTELY LEAVE YOU VULNERABLE TO ATTACK. THIS IS WORK IN PROGRESS AS I WORK ON HARDENING THE SERVER

Overview

The following are steps to help you configure and run your own Heroku-like server which can support multiple Horizon.io / RethinkDB applications including support for Lets Encrypt (SSL) on Digital Ocean.

Limitations

Recommend keeping your domain scheme to subdomain.domain.com and no deeper. If you try to go further then it makes Let's Encrypt a little trickier.

@jimthedev
jimthedev / nvm-node-on-do-dokku-debian.md
Created August 9, 2016 14:33
Nvm-node-on-do-dokku-debian
sudo apt-get update && sudo apt-get install build-essential libssl-dev
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.4/install.sh | bash

You will likely get an error during install. Don't worry, it took but you need to change your bashrc file slightly. Add the following line to the bottom of /home/dokku/.bashrc:

source ~/.nvm/nvm.sh
@jimthedev
jimthedev / .env
Created August 11, 2016 12:51
dokku rethink provision script
ROOT_IP=
ROOT_DOMAINNAME=
DO_KEY_READ=
DO_KEY_WRITE=
@jimthedev
jimthedev / app.js
Created September 1, 2016 15:04
simple node static server
var fs = require("fs");
var host = "0.0.0.0";
var port = 80;
var express = require("express");
var app = express();
app.use(express.static(__dirname + "/public")); //use static files in ROOT/public folder
app.listen(port, host);
@jimthedev
jimthedev / app.js
Last active September 1, 2016 21:37
Express with vhost and http proxy support
/**
* The following is an example of how to use virtual hosts in Express.
* Additionally, there is an example of using virtual hosts with an http
* proxy. This means that this config itself defines 4 express apps.
*
* Why 4?
* For vhosts to work in express, you need to define a parent express app
* (in our case that is `app`) and child express apps (`portfolioapp`,
* `demoapp`, and `finalapp`). portfolioapp is just a regular express
* app that is displayed at the domain root.
@jimthedev
jimthedev / kingmaker.js
Created September 26, 2016 22:02
Given an array, loop and return a winner. Uses a single elimination strategy.
/**
* Find the largest power of two below the given num
*/
function maxPow2Below(num){
return Math.pow(2, Math.floor(Math.log(num)/Math.log(2)));
}
/**
* Create an empty bracket given a number of teams entering the round
* This will prefer acheiving a square bracket by taking remainders
@jimthedev
jimthedev / index.js
Created October 26, 2016 17:15
Get a string from a numerator and denomentator
function getFractionString(numerator, denomenator) {
// if we can divide the numerator and the denomenator
// by the highest possible number without a remainder
if ( (numerator % denomenator) === 0 ) {
console.log('denomenator goes into numerator evenly');
return numerator/denomenator;
} else {
console.log('denomenator does not go in evenly');
return Math.floor(numerator/denomenator) + " " + numerator % denomenator + "/" + denomenator
}
@jimthedev
jimthedev / using-push-only.js
Created November 1, 2016 15:59
The dangers of Array.prototype.push without splicing first
// THIS ONE HAS UNEXPECTED RESULTS!
// BILL AND JIMS GARAGES ARE THE SAME! WHAT?!
var billsGarage = [];
// Someone stole a car, store it in the garage
function storeCarInGarage(myGarage, car) {
// At the end of the day, the car that was stolen
// should be stored in my garage