Skip to content

Instantly share code, notes, and snippets.

View halfninja's full-sized avatar
🌶️
spicy code

Nick Howes halfninja

🌶️
spicy code
View GitHub Profile
#!/bin/bash
PRIVATE_PEM=$(openssl genrsa 2048 2>/dev/null)
PUBLIC_PEM=$(echo "$PRIVATE_PEM" | openssl rsa -pubout 2>/dev/null)
echo "Public key:"
echo "$PUBLIC_PEM" | openssl rsa -pubin -pubout -inform PEM -outform DER 2>/dev/null | base64 -w0
echo
echo
echo "Private key:"
@halfninja
halfninja / TypelevelAuthz.scala
Created November 2, 2015 11:51
Prototype compile-time security checking. Checks are done outside of the service, but the compiler will prevent you from calling the methods unless you have acquired authorization from the auth service.
import scala.annotation.implicitNotFound
@implicitNotFound("Required authorization not found.")
case class Authorization[+A <: Role]()
object Authorization {
def of[T <: Role]: Authorization[T] = new Authorization[T]()
}
// Whatever set of roles you like
trait Role
@halfninja
halfninja / gulpfile.js
Created July 9, 2015 13:06
Gulp file for building LESS and ES6+JSX assets
'use strict';
var gulp = require('gulp');
var gutil = require('gulp-util');
var less = require('gulp-less');
var sourcemaps = require('gulp-sourcemaps');
var browserify = require('browserify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
module.exports = {
cache: true,
devtool: 'source-map',
entry: './app/assets/js/main.js',
output: {
filename: './target/web/public/main/js/bundle.js'
},
resolve: {
extensions: ['', '.js', '.sjs'],
fallback: __dirname
@halfninja
halfninja / proxy
Last active August 29, 2015 14:22
Nginx basic app proxy
upstream tomcats {
server localhost:8080;
}
server {
listen 443;
server_name $hostname.example.org;
ssl on;
ssl_certificate /var/org/ssl/personal.crt;

Keybase proof

I hereby claim:

  • I am halfninja on github.
  • I am nickhowes (https://keybase.io/nickhowes) on keybase.
  • I have a public key whose fingerprint is 0097 F726 8075 E88C 59C0 B689 87DE CF7D 5EE3 48CF

To claim this, I am signing this object:

class Dog
def bark
puts "Ruff"
end
end
class Tree
def bark
puts "Rough"
@halfninja
halfninja / bootstrap-shim.js
Last active August 29, 2015 14:14
Loads new jQuery and Bootstrap 3 if it's not detected on the page
/**
* If jQuery 1.8 or older is detected, loads a much newer jQuery and Bootstrap 3.
* After adding this script you must use the usual jQuery onready stuff to
* contain your code, otherwise it'll run before this has finished. e.g.:
* jQuery(function() {
* // new jQuery should work here
* });
*/
(function(){
var j = jQuery;
#!/bin/bash
# vi:syntax=bash
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
cd "${SCRIPT_DIR}/.."
# Install the required Puppet modules from a special Puppetfile into a special directory.
PUPPETFILE=Puppetfile.docs \
PUPPETFILE_DIR=docs_modules \
bundle exec r10k puppetfile install
money = 0
def get_rich
if Random.new.rand(100) > 90
money = money + 1000000
puts "Got rich."
true
else
false
end