Skip to content

Instantly share code, notes, and snippets.

View Xophmeister's full-sized avatar

Christopher Harrison Xophmeister

View GitHub Profile
@Xophmeister
Xophmeister / long2ip.sql
Last active September 24, 2022 23:46
Oracle SQL and PL/SQL function to convert proper IPv4 address (i.e., 32-bit integer) into the standard, "dotted" format
-- We have a table (ip_log) of proper IPv4 addresses (ip)
select bitand(ip / 16777216, 255) || '.' || bitand(ip / 65536, 255) || '.' || bitand(ip / 256, 255) || '.' || bitand(ip, 255) ip
from ip_log;
-- ...or a function to do the same:
create or replace function long2ip(ip in number)
return varchar2 deterministic
as
begin
return bitand(ip / 16777216, 255) || '.' ||
@Xophmeister
Xophmeister / unique.js
Created February 26, 2013 13:28
Urg! IE8...
// The easy way to get unique items from an array
Array.prototype.unique = function() {
return this.filter(function(s, i, a){ return i == a.lastIndexOf(s); });
};
// Translated into jQuery, so it works in IE8 :P
Array.prototype.unique = function() {
var array = this;
return $.grep(array, function(v, i) { return $.inArray(v, array, i + 1) == -1; });
};
(function() {
var isWord = function(word) { return /^[a-z]+$/i.test(word); },
exceptions = {
man: 'men',
woman: 'women',
child: 'children',
mouse: 'mice',
tooth: 'teeth',
goose: 'geese',
@Xophmeister
Xophmeister / gist:4585482
Created January 21, 2013 11:39
toCamelCase()
String.prototype.toCamelCase = function() {
return this.toLowerCase()
.replace(/[^\w\s]/g, '')
.replace(/\s+(\w)/g, function(match, $1) { return $1.toUpperCase(); });
};
@Xophmeister
Xophmeister / gist:4506689
Created January 10, 2013 23:26
Practising my C... Very straightforward, but always good to refresh one's memory!
#include <stdio.h>
typedef struct {
char* haystack;
char* needle;
int found;
} unitTest;
int strstr(char* haystack, char* needle) {
int i = 0,
@Xophmeister
Xophmeister / gist:4442858
Last active December 10, 2015 13:48
JavaScript ordinals
Number.prototype.ordinal = function() {
return this < 0 ? undefined
: this + ['th', 'st', 'nd', 'rd'][this % 10 < 4 ? (this % 10) * (parseInt(this / 10, 10) % 10 == 1 ? 0 : 1) : 0];
}
@Xophmeister
Xophmeister / gist:4298357
Created December 15, 2012 19:20
ADO wrapper for VBA
' ADO Abstraction Class for VBA
' Christopher Harrison
' This is meant for simple, read-only access to an ODBC database (e.g., for
' report writing in Excel, etc.). It constructs parameterised queries, with
' optional varchar parameters (ordered, not named) passed as a collection.
' (SELECT statements, at least, are weakly typed (or can be casted), so using
' strings isn't really a concern.)
' Notes:
@Xophmeister
Xophmeister / negativeSpace.py
Created December 4, 2012 16:13
Linguistic White Noise Generator
import random
import itertools
import bisect
BNC = [
('the', 6187267),
('be', 4239632),
('of', 3093444),
('and', 2687863),
('a', 2186369),
@Xophmeister
Xophmeister / gist:3878629
Created October 12, 2012 10:37
Deserialise the query string in JavaScript
if (!window.query) {
(function () {
var match,
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(/\+/g, ' ')); },
query = window.location.search.substring(1);
window.query = {};
while (match = search.exec(query)) {
window.query[decode(match[1])] = decode(match[2]);
@Xophmeister
Xophmeister / gist:3175460
Created July 25, 2012 10:28
OCI wrapper class for simplified Oracle handling
<?php
require_once "error.php";
class Oracle {
private $connection;
private $connected;
function __construct($connectionString, $username, $password) {
global $err;