Skip to content

Instantly share code, notes, and snippets.

@GideonPARANOID
GideonPARANOID / vanity-url-finder.py
Last active December 19, 2015 20:09
Identifying vanity URLs in the Unix dictionary.
ending = ['.asia', '.be', '.biz', '.ch', '.co', '.co.uk', '.de', '.es', '.eu', '.fr', '.gr', '.im', '.info', '.io', '.it', '.me', '.me.uk', '.org', '.org.uk', '.pro', '.pt', '.ru','.se', '.tel', '.tv', '.us', '.so']
file = open('/usr/share/dict/words', 'r')
for line in file:
for domain in ending:
if line == line[:-(len(domain))] + domain.replace('.', '') + '\n':
print line[:-(len(domain))] + domain.replace('.', '')
@GideonPARANOID
GideonPARANOID / nice-join.js
Last active December 25, 2015 12:09
Ahh, nicer array joining for string concatenation.
Array.prototype.nice_join = function(sep) {
return this.length > 1 ?
this.slice(0, this.length - 1).join(sep) + ' & ' + this[this.length - 1] :
this.join(' ' + sep + ' ');
}
@GideonPARANOID
GideonPARANOID / index.html
Last active December 25, 2015 19:19
Canvas ImageData manipulation with dynamic parallelisation.
<html>
<head>
</head>
<body>
<style>
#main {
position : absolute;
z-index : -1;
}
@GideonPARANOID
GideonPARANOID / work-it.js
Last active December 26, 2015 20:58
Creating, dispatching & receiving a web worker inline.
/**
* web worker manager
* @param fun function to carry out in the web worker
* @param mes message to send to the web worker
* @param com function to do on completion
* @param err (optional) function to do on error
*/
function wor(fun, mes, com, err) {
var wor = new Worker(URL.createObjectURL(new Blob([
'self.onmessage = ' + fun.toString()], {
@GideonPARANOID
GideonPARANOID / intersection.js
Created November 23, 2013 17:58
Detects whether two lines (represented as four points ({x : int, y : int}) intersect.
/**
* @param one point start of the first line
* @param two point end of the first line
* @param three point start of the second line
* @param four point end of the second line
* @return boolean whether the lines intersect or not
*/
function intersection(one, two, three, four) {
var x = ((one.x * two.y - one.y * two.x) * (three.x - four.x) -
(one.x - two.x) * (three.x * four.y - three.y * four.x)) /
@GideonPARANOID
GideonPARANOID / contains.js
Created December 12, 2013 15:18
I'm sure other people get confused as much as I do sometimes with using indexOf to search lists.
/*
* @param item what to look for in the array
* @return boolean whether the item is in the list or not
*/
Array.prototype.contains = function(item) {
return this.indexOf(item) >== 0;
}
@GideonPARANOID
GideonPARANOID / mouse-position.js
Last active December 31, 2015 12:39
As I always forget how to effectively do this.
/**
* @param eve an event object from function listening on the element, such as mousedown
* @return object describing the position of the mouse on the canvas
*/
function mouse_pos(eve) {
var rect = eve.target.getBoundingClientRect();
return {
y : eve.clientY - rect.top,
x : eve.clientX - rect.left
};
@GideonPARANOID
GideonPARANOID / snakes-and-ladders.sh
Created December 27, 2013 13:48
Generates a snakes & ladders board in the form of a folder structure, using symbolic links for snakes & ladders. Snakes & ladders are taken from a file in the format: <start> <end>\n
#!/bin/bash
# @author gideon mw jones
# @created 2013-12-27
# @version 1
# creates a directory structure board for snakes & ladders
BRDSZ=100
# initialising board & links
@GideonPARANOID
GideonPARANOID / copy-directory-structure.sh
Last active January 3, 2016 11:29
Copies a directory structure sans files.
#!/bin/bash
# usage:
# copy-directory-structure.sh <target> <destination>
if [ ! -d $2 ]; then
mkdir $2
fi
find $1 -type d > $2/.lst
@GideonPARANOID
GideonPARANOID / var-dump-js.php
Last active January 4, 2016 03:39
I'm getting really tired of PHP's rubbish variable printing, using the JS terminal is far easier.
/**
* @param $dat a php array or variable
* prints the parameter to the javascript console, only suitable for use inside dom elements
*/
function var_dump_js($dat) {
echo '<script type=\'text/javascript\'>console.log(' . json_encode($dat) . ');</script>';
}