Skip to content

Instantly share code, notes, and snippets.

View sandcastle's full-sized avatar
🍦

Glenn Morton sandcastle

🍦
View GitHub Profile
@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 / iptables.sh
Last active April 30, 2018 12:55
Default firewall configuration using iptables for a fresh Ubuntu 14.04 server.
#!/bin/sh -x
# ==================================
# iptables default configuration script
#
# - this locks down our servers port access
# ==================================
# install fail2ban
sudo apt-get update
@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;
@sandcastle
sandcastle / ConfigurationHelpers.cs
Last active August 29, 2015 14:09
Helper methods for reading app.config values.
/// <summary>
/// Helper methods for reading configuration values.
/// </summary>
public static class ConfigurationHelpers
{
/// <summary>
/// Reads an enum value from configutation.
/// </summary>
/// <typeparam name="T">The enum type.</typeparam>
/// <param name="key">The configuration key.</param>
@sandcastle
sandcastle / oracle_guid_helpers.sql
Last active December 9, 2024 13:48
Oracle GUID helper functions for converting between GUID and RAW(16)
set serveroutput on;
declare
raw_guid raw(16);
guid varchar2(64);
begin
raw_guid := guid_to_raw ('88c6a267-65d2-48d6-8da2-6f45e2c22726');
guid := raw_to_guid('67A2C688D265D6488DA26F45E2C22726');
@sandcastle
sandcastle / default.conf
Created January 18, 2015 22:03
The default nginx configuration file.
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;