Skip to content

Instantly share code, notes, and snippets.

View Xophmeister's full-sized avatar

Christopher Harrison Xophmeister

View GitHub Profile
@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: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(); });
};
(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 / 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; });
};
@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 / gist:6461994
Created September 6, 2013 10:12
Prime numbers in Oracle :)
select level p
from dual
where not regexp_like(rpad('#', level, '#'), '^#?$|^(##+?)\1+$')
connect by level <= 1000;
@Xophmeister
Xophmeister / sierpinski.hs
Last active April 25, 2018 13:29
Sierpinski Triangle in Haskell
sumPairs :: [Integer] -> [Integer]
sumPairs (x:y:s) = (x + y) : sumPairs (y:s)
sumPairs _ = []
pascal :: Integer -> [Integer]
pascal 0 = [1]
pascal n = sumPairs $ [0] ++ (pascal $ n - 1) ++ [0]
sierpinski :: Integer -> String
sierpinski n = concat $ map (ascii . odd) $ pascal n
@Xophmeister
Xophmeister / gist:7138830
Created October 24, 2013 15:03
Gimmicky Names for OCaml Projects
abnormal -> abnor.ml
abysmal -> abys.ml
acetylthymol -> acetylthy.ml
actinostomal -> actinosto.ml
adiathermal -> adiather.ml
alemmal -> alem.ml
alismal -> alis.ml
Alumel -> Alu.ml
Alvissmal -> Alviss.ml
amil -> a.ml
@Xophmeister
Xophmeister / gist:7369778
Last active December 27, 2015 18:29
Simple E-Mailing Wrapper around Oracle's utl_smtp
create or replace procedure email(
sender in varchar2,
recipients in varchar2,
carbon in varchar2,
subject in varchar2,
text in clob,
html in clob default null)
as
connection utl_smtp.connection;
smtpHost varchar2(30) := 'mail.example.com';
@Xophmeister
Xophmeister / authenticate.py
Last active December 31, 2015 05:39
*Really* simple Python-LDAP wrapper for query and authentication
import ldap
# *Really* simple Python-LDAP wrapper for query and authentication
# myLDAPServer = LDAP('ldap://ldap.example.com', 'o=foo')
# me = myLDAPServer.person('jbloggs')
#
# try:
# me.authenticate('abc123')
# except: