Skip to content

Instantly share code, notes, and snippets.

View BrainBacon's full-sized avatar

Brian Jesse BrainBacon

  • San Diego, CA
View GitHub Profile
@BrainBacon
BrainBacon / server.clj
Created October 4, 2012 22:38
Cheshire binding in middleman
(ns pitchit.server
(:require [cheshire.core :as json]
[cheshire.factory :as factory]
[noir.server :as server]
[pitchit.views common welcome]
[pitchit.models db]))
(server/load-views-ns 'pitchit.views)
(defn -main [& m]
@BrainBacon
BrainBacon / hash.clj
Created February 15, 2013 21:43
Hash password for Clojure-Java interop
(ns hash
(:import [java.security MessageDigest]
[org.apache.commons.codec.binary Base64]))
(defn hash-password [pass]
(String.
(org.apache.commons.codec.binary.Base64/encodeBase64
(->
(doto
(java.security.MessageDigest/getInstance "SHA-256")
@BrainBacon
BrainBacon / barcrawl.clj
Last active December 15, 2015 15:39
Bar crawl in Clojure. Just for fun.
(def input {:type alcohol})
(defn itBarCrawl [ITMajor]
(while (. ITMajor isStanding)
(let [bar (. ITMajor getLocation)]
(cond
(= bar "Pub II") (. ITMajor drink "Pitchers")
(= bar "Mulligans") (. ITMajor drink "Long Islands")
(= bar "Drifters") (. ITMajor drink "Mixed Drinks")
(= bar "Fat Jacks") (if (<= 6 (. ITMajor getDrunkLevel))
(. ITMajor drink "Rum Dumps")
# -*- mode: ruby -*-
# vi: set ft=ruby sts=2 ts=2 expandtab sw=2:
Vagrant.configure("2") do |config|
puppet_nodes = [
{
:hostname => 'clusternode',
:ip => '192.168.2.202',
:ram => 1024
@BrainBacon
BrainBacon / httpPromiseMock.js
Created August 2, 2013 05:55
Angular HttpPromise Mock
'use strict';
/**
* @ngdoc function
* @name ngMock.$mockHttpPromise
* @function
* @param {object} mockSuccess The object to return to the .success() callback function
* @param {object} mockError The object to return to the .error() callback function
* @requires $q
*
@BrainBacon
BrainBacon / config.js
Last active August 29, 2015 14:14
Example routes in AngularJS
var getPath = function(path) {
return '/i' + (path.indexOf('/') === 0 ? path : '/' + path);
};
var config = {
when: function(path, route) {
if(route.overrideRoot) {
$routeProvider.when(path, route);
} else {
var redirect = angular.copy(route);
delete redirect.templateUrl;
@BrainBacon
BrainBacon / CrossDomain.java
Last active August 29, 2015 14:19
CORS with JAX-RS and CDI with preflight
package com.example.interceptor;
import javax.interceptor.InterceptorBinding;
import java.lang.annotation.*;
@Inherited
@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface CrossDomain {
@BrainBacon
BrainBacon / a.directive.js
Last active October 8, 2015 22:11
An angular directive to modify links for simultaneous browser and Cordova native app support
angular.module('myApp').directive('a', function(
PhonegapConstant,
$window
) { 'use strict';
return {
priority: 1,
restrict: 'E',
link: function($scope, $element, $attrs) {
if(PhonegapConstant) {
$attrs.$observe('href', function(value) {
@BrainBacon
BrainBacon / unbounce.js
Created November 5, 2015 00:02
Modified unbounce embed script to allow global `_ubaq` variable declaration inside a closure
window._ubaq = window._ubaq || [];
window._ubaq.push(['trackGoal', 'convert']);
(function() {
var ub_script = document.createElement('script');
ub_script.type = 'text/javascript';
ub_script.src =
('https:' == document.location.protocol ? 'https://' : 'http://') +
'd3pkntwtp2ukl5.cloudfront.net/uba.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ub_script, s);
@BrainBacon
BrainBacon / .env
Created January 15, 2016 19:20
sample bn-mentors env
{
"pg": {
"user": "admin",
"pass": "secret"
},
"node" : {
"env": "dev"
},
"port": 8081
}