Skip to content

Instantly share code, notes, and snippets.

View mllrjb's full-sized avatar

Jason Miller mllrjb

View GitHub Profile
function htmlEncode(value){
//create a in-memory div, set it's inner text(which jQuery automatically encodes)
//then grab the encoded contents back out. The div never exists on the page.
return $('<div/>').text(value).html();
}
function htmlDecode(value){
return $('<div/>').html(value).text();
}
angular.injector(['ng', 'ngSanitize']).get('$sanitize')('asdf<script>FooBar</script>')
@mllrjb
mllrjb / ngName
Last active December 23, 2015 11:19
Angular directive to support expressions in `input.name`, pending merge of https://github.com/angular/angular.js/pull/3135.
.directive('ngName', function() {
return {
restrict: 'A',
require: ['^form', 'ngModel'],
link: function($scope, ele, attr, ctrl) {
var formCtrl = ctrl[0];
var ngModel = ctrl[1];
var name = $scope.$eval(attr.mppName);
if (ngModel.$name != name) {
formCtrl.$removeControl(ngModel);
@mllrjb
mllrjb / ant-installers.groovy
Created October 12, 2016 21:12
Jenkins init.groovy.d Ant Installer
import jenkins.model.*
import hudson.model.*
import hudson.tasks.*
import hudson.tools.*
def inst = Jenkins.getInstance()
def desc = inst.getDescriptor("hudson.tasks.Ant")
def versions = [
@mllrjb
mllrjb / Jenkinsfile-GitHubCommitStatusSetter
Created October 13, 2016 18:42
Jenkinsfile Github Commit Status Example
#!groovy
step([$class: 'GitHubCommitStatusSetter',
contextSource: [$class: 'ManuallyEnteredCommitContextSource', context: 'preflight-build'],
statusResultSource: [$class: 'ConditionalStatusResultSource',
results: [[$class: 'AnyBuildResult', message: 'Preflight build successful', state: 'SUCCESS']]]])
@mllrjb
mllrjb / Jenkinsfile
Created October 20, 2016 20:46
Jenkinsfile-gitUrl
#!groovy
node() {
// checkout clean code
stage("checkout") {
checkout scm
sh "git clean -fdx"
}
stage("gitUrl" ) {
@mllrjb
mllrjb / Jenkinsfile
Created October 20, 2016 20:48
Jenkinsfile-kitchen-sink
#!groovy
/**
* Requires tool definitions for nodejs, jdk, maven, and ant
* Requires config files .npmrc and maven-settings.xml
*/
node() {
// checkout clean code
stage("checkout") {
checkout scm
@mllrjb
mllrjb / migrate.js
Created December 5, 2016 18:03
Umzug Migration
const path = require('path')
, Umzug = require('umzug')
, Bluebird = require('bluebird')
const db = {
// sequelize instance
sequelize: null,
// Sequelize constructor
Sequelize: null
};
@mllrjb
mllrjb / pipe.js
Created December 5, 2016 18:10
Piping Expressjs to another API via requestjs
'use strict';
const request = require('request');
module.exports = function forward(req, res, next) {
var myRequest = request({
url: req.url,
headers: req.headers
});
req.pipe(myRequest)
@mllrjb
mllrjb / _utility.spacing.scss
Created January 7, 2017 21:10
Sass padding and margin utilities
/*
Spacing
- - - - - - - - - - - - - - - - - - - - - - - - -
Helper classes for spacing like margin and padding.
Class names follow this convention:
.[type][direction][size]