Skip to content

Instantly share code, notes, and snippets.

View sandcastle's full-sized avatar
🍦

Glenn Morton sandcastle

🍦
View GitHub Profile
@sandcastle
sandcastle / change_object_owner.sql
Last active December 14, 2015 11:28
A PostgreSQL helper script for changing the owner of all objects in a schema.
-- change the "new_owner" role before running
SELECT 'ALTER TABLE '|| schemaname || '.' || tablename ||' OWNER TO new_owner;'
FROM pg_tables WHERE NOT schemaname IN ('pg_catalog', 'information_schema')
ORDER BY schemaname, tablename;
SELECT 'ALTER SEQUENCE '|| sequence_schema || '.' || sequence_name ||' OWNER TO new_owner;'
FROM information_schema.sequences WHERE NOT sequence_schema IN ('pg_catalog', 'information_schema')
ORDER BY sequence_schema, sequence_name;
@sandcastle
sandcastle / drop_all_user_objects.sql
Created February 26, 2015 06:53
Generates an oracle script to drop all objects within a schema.
select 'drop '||lower(object_type)||' '|| object_name||decode(object_type,'TABLE',' cascade constraints;',';')
from user_objects;
@sandcastle
sandcastle / oracle_recompile_objects.sql
Created April 15, 2015 01:57
Recompile all Oracle objects (requires access to dba_objects). If running as a user schema, you can use user_objects instead.
set heading off;
set feedback off;
set echo off;
Set lines 999;
spool run_invalid.sql
select 'ALTER ' || OBJECT_TYPE || ' ' || OWNER || '.' || OBJECT_NAME || ' COMPILE;'
from dba_objects
where status = 'INVALID'
@sandcastle
sandcastle / cli.js
Created May 4, 2015 10:49
A basic node.js REPL written in ES6.
import readline from 'readline';
import util from 'util';
import chalk from 'chalk';
let terminal = readline.createInterface(process.stdin, process.stdout);
export default function cli(commands){
return (new CLI(commands)).repl();
@sandcastle
sandcastle / DebugNestSearch.cs
Created May 14, 2015 02:24
The basics for debugging a NEST.Net search query.
static Main(){
var client = {INSERT_HERE};
var search = {INSERT_HERE};
var json = Encoding.UTF8.GetString(client.Serializer.Serialize(search));
Console.WriteLine(json);
}
@sandcastle
sandcastle / DateTimeExtensions.cs
Created November 4, 2015 15:49
Convert dates to friendly text relative to the current time.
public static class DateTimeExtensions
{
static readonly Dictionary<double, Func<TimeSpan, string>> RelativeDateMap;
static DateTimeExtensions() {
RelativeDateMap = new Dictionary<double, Func<TimeSpan, string>> {
{0.75, x => "less than a minute"},
{1.5, x => "about a minute"},
{45, x => string.Format("{0} minutes", Math.Round(Math.Abs(x.TotalMinutes), 0))},
{90, x => "about an hour"},
@sandcastle
sandcastle / uuid.js
Created November 5, 2015 12:40
Generates a new UUID in js.
function getUuid() {
function _p8(s) {
var p = (Math.random().toString(16) + "000000000").substr(2, 8);
return s ? "-" + p.substr(0, 4) + "-" + p.substr(4, 4) : p;
}
return _p8() + _p8(true) + _p8(true) + _p8();
};
@sandcastle
sandcastle / Currency.cs
Created November 29, 2015 23:35
A data provider for all ISO countries in C#
public class Currency
{
/// <summary>
/// Gets or sets the ID of the currency.
/// </summary>
public Guid Id { get; set; }
/// <summary>
/// Gets or sets the ISO currency code.
/// </summary>
@sandcastle
sandcastle / TapjoyIntegration.cs
Created January 15, 2016 08:21
Sample TapJoy Unity integration from the TapJoy website.
using UnityEngine;
using System.Collections;
using TapjoyUnity;
public class TapjoyIntegration {
public static TJPlacement placementAppLaunch;
public static TJPlacement placementAppClose;
public static GameObject bgmObject;
@sandcastle
sandcastle / aurora_cluster.tf
Created March 25, 2016 09:44
Creates a AWS RDS Aurora Cluster with Terraform
########################
## Variables
########################
variable "environment_name" {
description = "The name of the environment"
}
variable "vpc_id" {