Skip to content

Instantly share code, notes, and snippets.

View sandcastle's full-sized avatar
🍦

Glenn Morton sandcastle

🍦
View GitHub Profile
@sandcastle
sandcastle / logstash-syslog-elasticsearch.conf
Created April 18, 2016 00:02
Logstash Syslog to Elasticsearch configuration via docker
input {
syslog {
port => 12345
type => "docker"
}
}
output {
elasticsearch {
hosts => [ "elasticsearch" ]
@sandcastle
sandcastle / GeoData.cs
Created May 4, 2016 14:30
A Unity 3D behaviour for Geo location lookup via IP address
using UnityEngine;
using System.Collections;
using Newtonsoft.Json;
/// <summary>
/// The Geo data for a user.
///
/// http://ip-api.com/docs/api:json
///
@sandcastle
sandcastle / count_words_per_file.sh
Last active June 13, 2016 07:33
Finds the number of times a word occurs per file in a directory and its subdirectories
#!/bin/sh
# LOGIC:
#
# 1. Find all *.ts files the current directory and all subdirectories
#
# for f in $(find . -name '*.ts');
#
# 2. Loop through all files and do an action
#
@sandcastle
sandcastle / b64toBlob.js
Created July 10, 2016 18:21
Convert base 64 to blob
b64toBlob(b64Data, contentType, sliceSize) {
contentType = contentType || '';
sliceSize = sliceSize || 512;
let byteCharacters = atob(b64Data);
let byteArrays = [];
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
let slice = byteCharacters.slice(offset, offset + sliceSize);
let byteNumbers = new Array(slice.length);
@sandcastle
sandcastle / product_brands_dropdown.php
Created September 29, 2016 05:18
A Product Sub-Category Dropdown
<?php
/**
* Shortcode for creating a dropdown for all brands.
*
* Doc:
* https://codex.wordpress.org/Function_Reference/wp_dropdown_categories
*
* Inspiration:
@sandcastle
sandcastle / woocommerce_recently_viewed_products.php
Last active October 14, 2016 16:26
Recently viewed product tracking on woocommerce with a shortcode and cookies
/**
* https://github.com/woocommerce/woocommerce/issues/9724#issuecomment-160618200
*/
function custom_track_product_view() {
if ( ! is_singular( 'product' ) ) {
return;
}
global $post;
@sandcastle
sandcastle / wpwhitespacefixer.php
Created October 16, 2016 14:01
A handy php whitespace fixer I found from Michal "Wejn" Jirků
<?php
/*
Wordpress leading whitespace fix
================================
Ever got the infamous "xml declaration not at start of external
entity" error instead of your RSS feed when using Wordpress?
Well, you're not alone. I've spent couple hours tracking down
which of the active Wordpress plugins/themes broke my RSS feed.
@sandcastle
sandcastle / guid.ts
Last active February 18, 2018 04:33
A useful type GUID class definition.
const GUID_EMPTY: string = '00000000-0000-0000-0000-000000000000';
const GUID_FORMAT: RegExp = /\{?([a-z0-9]{8}(?:-[a-z0-9]{4}){3}-[a-z0-9]{12})\}?/i;
/**
* A unique identifier.
*/
export class Guid {
private _id: string;
@sandcastle
sandcastle / LogToScreen.cs
Last active April 27, 2017 10:32
Log messages to the screen in Unity.
using System;
using System.Text;
using UnityEngine;
public class LogToScreen : Singleton<LogToScreen>
{
const int Lines = 18;
static string[] _lastItems = new string[Lines];
static string _message = string.Empty;
@sandcastle
sandcastle / nginx.default.conf
Created July 15, 2017 02:47
A default for nginx configuration file.
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
charset utf-8;
index index.html;