Skip to content

Instantly share code, notes, and snippets.

View johnathan-sewell's full-sized avatar

Johnathan Sewell johnathan-sewell

  • BLAST
  • Copenhagen
View GitHub Profile
@johnathan-sewell
johnathan-sewell / deploy
Created April 29, 2014 12:50
OpenShift deploy hooks for Ghost
#!/bin/bash
echo "Creating persistent Ghost data directory"
if [ ! -d "$OPENSHIFT_DATA_DIR/content/data" ]; then
mkdir -p $OPENSHIFT_DATA_DIR/content/data
fi
echo "Creating persistent Ghost images directory"
if [ ! -d "$OPENSHIFT_DATA_DIR/content/images" ]; then
mkdir -p $OPENSHIFT_DATA_DIR/content/images
fi
@johnathan-sewell
johnathan-sewell / gist:6052453
Created July 22, 2013 09:07
ISO 8601 Date Example
2013-07-01T10:00:00.000Z
@johnathan-sewell
johnathan-sewell / RibbonXMLPersistance.cs
Created November 29, 2012 14:24
Example of saving XML to the Excel document file from a VSTO Excel Ribbon Addin
public void AddCustomXmlPartToWorkbook()
{
var workbook = Globals.ThisAddIn.Application.ActiveWorkbook;
const string xmlString = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
"<employees xmlns=\"http://myapi.com\">" +
"<employee>" +
"<name>Karina Leal</name>" +
"<hireDate>1999-04-01</hireDate>" +
"<title>Manager</title>" +
using System;
namespace Example.ExcelAddin
{
public partial class ThisAddIn
{
[Microsoft.VisualStudio.Tools.Applications.Runtime.Cached()]
public String MyCachedData;
@johnathan-sewell
johnathan-sewell / sublime-jasmine-find-replace
Created October 16, 2012 15:59
Sublime Text Find and Replace for Jasmine specs
Find:
^it (.*)$
Replace:
it('$1', function(){});
@johnathan-sewell
johnathan-sewell / factorial.js
Created May 17, 2012 07:59
Loop and recursive functions for generating factorial
"use strict";
function fact(start){
var factorial = 1;
for (var i = 1; i <= start; i++)
{
factorial = factorial * i;
}
return factorial;
}
@johnathan-sewell
johnathan-sewell / episerver-recursive-methods.cs
Created May 13, 2012 13:59
EPiServer tree recursive methods
protected static void FindDescendantsOfType<T>(PageData page, ICollection<T> descendants) where T : class
{
var children = DataFactory.Instance.GetChildren(page.PageLink);
foreach (var child in children)
{
if (child is T)
{
descendants.Add(child as T);
}
FindDescendantsOfType(child, descendants);
@johnathan-sewell
johnathan-sewell / constructor.js
Created April 29, 2012 20:00
Example of a constructor function in JavaScript
//define a function
var BaristaFunction = function(name){
this.myName = name;
};
//define a method
BaristaFunction.prototype.sayHi = function(){
alert('Hi I\'m ' + this.myName);
};
@johnathan-sewell
johnathan-sewell / LowercaseUrlRewriteProvider.cs
Created April 26, 2012 13:19
EPiServer URL Rewrite Provider to make URLs lowercase
public class LowercaseUrlRewriteProvider : FriendlyUrlRewriteProvider
{
public override bool ConvertToExternal(UrlBuilder url, object internalObject, System.Text.Encoding toEncoding)
{
base.ConvertToExternal(url, internalObject, toEncoding);
url.Path = url.Path.ToLower();
return true;
}
}
@johnathan-sewell
johnathan-sewell / breakout.js
Created April 23, 2012 12:08
JavaScript iframe breakout
var isFrame;
try {
if (top.location.href !== window.location.href) {
isFrame = true;
}
} catch (e) {
// if you're in an iframe in a different domain, the top.location check
// results in a security exception
isFrame = true;
}