Skip to content

Instantly share code, notes, and snippets.

View mbenford's full-sized avatar

Michael Benford mbenford

View GitHub Profile
@mbenford
mbenford / spring-cleaning.js
Last active April 17, 2017 09:06
ngTagsInput spring cleaning script
const path = require('path');
const GitHubApi = require('github');
const jsonfile = require('jsonfile');
const moment = require('moment');
const async = require('async');
const config = require('./config.json');
const github = new GitHubApi({ protocol: 'https' });
github.authenticate({ type: 'oauth', token: config.token });
@mbenford
mbenford / bit-manipulation.js
Created April 15, 2015 00:16
Bit manipulation in Javascript
function setBitOn(number, bit) {
return number | 1 << bit;
}
function setBitOff(number, bit) {
return number & ~(1 << bit);
}
function toggleBit(number, bit) {
return number ^ 1 << bit;
@mbenford
mbenford / SetReleaseParameters.ps1
Created August 11, 2014 01:12
Powershell script for TeamCity that sets some parameters to be used with Octopus Deploy based on the current branch
function Is-Default-Branch {
return "%teamcity.build.branch.is_default%" -eq "true"
}
function Set-TeamCity-Parameter($name, $value) {
Write-Host "##teamcity[setParameter name='$name' value='$value']"
}
if (Is-Default-Branch) {
$releaseNumber = "%octopus.master.releaseNumber%"
public static class MappingExtensions
{
public static void Unflatten<T>(this IMemberConfigurationExpression<T> config)
{
config.ResolveUsing(resolutionResult =>
{
var context = resolutionResult.Context;
var prefix = context.MemberName;
var destProperties = context.DestinationType.GetProperties();
var dest = Activator.CreateInstance(context.DestinationType);
@mbenford
mbenford / Bootstrap.bat
Created May 27, 2013 19:09
Bootstrap script to register a Tentacle with an Octopus server and deploy a release to its environment/role. Requires a Tentacle installer and Octo.exe in the same directory of the script.
start /wait msiexec /i Octopus.Tentacle.<version>.msi /quiet INSTALLLOCATION=C:\Octopus
cd C:\Octopus\Agent
tentacle configure --appdir="C:\Applications" --port=10933 --trust=<server-thumbprint>
tentacle new-certificate
tentacle install
tentacle register-with --server=<server-url> --environment=<environment> --role=<role> --apikey=<some-user-apikey>
octo deploy-release --project=<project-name> --deployto=<environment-to-deploy> --version=<version-to-deploy> --server=<server-url> --apikey=<some-user-apikey>
@mbenford
mbenford / ngTranscludeAppend.js
Last active December 29, 2015 05:39
AngularJS directive that re-creates the old ngTransclude behavior
app.directive('ngTranscludeAppend', function() {
return function(scope, element, attrs, ctrl, transcludeFn) {
if (!transcludeFn) return;
transcludeFn(function(clone) {
element.append(clone);
});
};
});
@mbenford
mbenford / SimpleTagsInputDemo.html
Created September 1, 2013 06:35
Simple Tags Input Demo
<body ng-init="tags=['some','cool','tags']">
<tags-input ng-model="tags"></tags-input>
</body>
var sumsOfDivisors = from i in Enumerable.Range(1, 10000)
select new { Number = (long)i, SumOfDivisors = Toolbox.GetProperDivisors(i).Sum() };
var amicableNumbers = from a in sumsOfDivisors
join b in sumsOfDivisors on new { x = a.Number, y = a.SumOfDivisors } equals
new { x = b.SumOfDivisors, y = b.Number }
where a.Number != b.Number
select a.Number;
@mbenford
mbenford / .bash_aliases
Last active August 29, 2015 14:21
My .bashrc file
alias la="ls -a"
alias psa="ps aux"
@mbenford
mbenford / get-permutations.js
Created April 30, 2015 03:15
Generate all permutations of the given set
function getPermutations(set) {
var result = [];
permutate(set);
return result;
function permutate(set, subset) {
if (!subset) subset = [];
if (set && !set.length) {
result.push(subset);
return;