Skip to content

Instantly share code, notes, and snippets.

View sandcastle's full-sized avatar
🍦

Glenn Morton sandcastle

🍦
View GitHub Profile
@sandcastle
sandcastle / company-slug.js
Created February 9, 2014 00:45
Converts a company name into a site slug - for SaaS applications.
/**
* Converts a company name into a site slug.
* @param {String} value
* @returns {string}
*/
var createSlug = function(value) {
if (_.isEmpty(value)) { //lodash call
return '';
}
@sandcastle
sandcastle / node.sh
Created February 26, 2014 23:16
Setup file for node.js 0.10.* on Ubuntu 12.04
# https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
sudo apt-get update
sudo apt-get install -y python-software-properties python g++ make
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get --purge remove node
sudo apt-get --purge remove nodejs
sudo apt-get install nodejs
@sandcastle
sandcastle / app.sh
Created February 26, 2014 23:23
Script to be able to build source on Ubuntu 12.04
sudo apt-get install git
sudo apt-get install npm
npm install -g bower
npm install
bower install
@sandcastle
sandcastle / QueryStringBuilder.cs
Created March 19, 2014 14:03
Simple query string builder for clients.
public class QueryStringBuilder : NameValueCollection
{
public QueryStringBuilder()
: base(StringComparer.InvariantCultureIgnoreCase) { }
public QueryStringBuilder(NameValueCollection collection)
: base(StringComparer.InvariantCultureIgnoreCase)
{
Add(collection);
}
@sandcastle
sandcastle / Platform.cs
Last active August 29, 2015 14:00
Platform check for Mono and Windows
/// <summary>
/// Helper methods for determining the platform.
/// </summary>
public static class Platform
{
/// <summary>
/// Gets if the platform is Windows NT or later.
/// </summary>
public static bool IsWindows
{
@sandcastle
sandcastle / AdHelper.cs
Last active August 29, 2015 14:01
Helper for accessing the always unique Active Directory user ID (ObjectGUID).
public class AdHelper
{
public WindowsAccount GetWindowsAccount(string username = "")
{
// NOTE: If the username is not specified, use the current users account
// The username should also include the domain if available
var identity = String.IsNullOrWhiteSpace(username)
? WindowsIdentity.GetCurrent().Name
: username;
@sandcastle
sandcastle / ImageMagick.cs
Last active August 29, 2015 14:01
Native wrapper for Image Magick using the Linux Share Object Library.
public class ImageMagick : IDisposable
{
IntPtr _wand;
public ImageMagick(string file)
{
var data = File.ReadAllBytes(file);
Initialise(data);
}
@sandcastle
sandcastle / TimeExtensions.cs
Created October 20, 2014 01:40
To Unix Time from DateTime
public static class TimeExtensions
{
// Good website for conversions:
// http://www.epochconverter.com/
// ToUnixTime(DateTime.Parse("20/10/2014 12:00:00 AM")) - should equal 1413734400
public static long ToUnixTime(this DateTime date)
{
return (date.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
@sandcastle
sandcastle / clean.ps1
Created October 27, 2014 01:37
Cleans all sub directories that contain bin, obj and resharper folders.
Get-ChildItem .\ -include bin,obj,_ReSharper* -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }
@sandcastle
sandcastle / delete_object.sql
Created October 27, 2014 02:05
Helper Oracle procedure for dropping objects.
create or replace procedure delete_object(object_name varchar2, object_type varchar2)
is
v_counter number := 0;
begin
if object_type = 'TABLE' then
select count(*) into v_counter from user_tables where table_name = upper(object_name);
if v_counter > 0 then
execute immediate 'drop table ' || object_name || ' cascade constraints';
dbms_output.put_line('table ' || object_name || ' deleted');
end if;