Skip to content

Instantly share code, notes, and snippets.

View iolloyd's full-sized avatar
💭
Busy bee

Lloyd Moore iolloyd

💭
Busy bee
View GitHub Profile
@iolloyd
iolloyd / diffArrays.php
Created December 16, 2013 13:35
difference of sorted sets
function setDiff($a, $b, $out=[])
{
if ($a == [] || $b == []) {
foreach ($a as $v) {
$out[] = $v;
}
return $out;
}
$headA = $a[0];
@iolloyd
iolloyd / justElements..js
Last active December 31, 2015 12:39
remove non-elements and re-attach in random order
<!DOCTYPE html>
<html>
<head>
<title>permuteChildren()</title>
<script type="text/javascript">
function isElementType(node) {
return document.getElementById(node).nodeType == 1;
}
@iolloyd
iolloyd / threeseconds.js
Last active December 31, 2015 13:09
Produce random squares given a max number and constraints of box size. Make the squares change colour and move somewhere away from the mouse if mouse over for at least 3 seconds.
<<!DOCTYPE html>
<html>
<head>
<title>rectangles.html</title>
<script type="text/javascript">
var nRectangles = 10,
containerWidth = 600,
containerHeight = 600,
@iolloyd
iolloyd / setdiff.php
Last active December 31, 2015 13:39
set differences order dependant
<<?php
function setDiff($a, $b, $out=[])
{
if ($a == [] || $b == []) {
foreach ($a as $v) {
$out[] = $v;
}
return $out;
}
@iolloyd
iolloyd / non-recursive-diff.php
Last active December 31, 2015 15:19
non-recursive method to diff sorted sets of ints
<?php
function tail(array $a)
{
$out = [];
unset($a[0]);
foreach ($a as $v) {
$out[] = $v;
}
return $out;
@iolloyd
iolloyd / remove-non-elms.html
Last active November 24, 2016 09:42
remove non-elements from parent node
<!DOCTYPE html>
<html>
<head>
<title>permuteChildren()</title>
<script type="text/javascript">
// receives the id of the parent
function permuteChildren(nodeId) {
// Check if node is of the type 'Element'
@iolloyd
iolloyd / .ctags
Created January 8, 2014 08:49
go compatibility for ctags
--langdef=Go
--langmap=Go:.go
--regex-Go=/func([ \t]+\([^)]+\))?[ \t]+([a-zA-Z0-9_]+)/\2/f,func/
--regex-Go=/var[ \t]+([a-zA-Z_][a-zA-Z0-9_]+)/\1/v,var/
--regex-Go=/type[ \t]+([a-zA-Z_][a-zA-Z0-9_]+)/\1/t,type/
@iolloyd
iolloyd / callable_class.py
Created January 31, 2014 10:11
An example of how to make a class callable as an instance in python
class Foo:
def __call__(self):
print 'you called me'
caller = Foo()
caller()
@iolloyd
iolloyd / rename-zip.php
Created February 4, 2014 14:15
Rename the files in a zip
<?php
$zipFile = $argv[1];
$newName = $argv[2];
if (!($zipFile && $newName)) {
die('You need to specify a zip file to rename and a new filename');
}
$ext = pathinfo($zipFile, PATHINFO_EXTENSION);
@iolloyd
iolloyd / truesort.sql
Created February 25, 2014 15:08
Correctly sort a list where the entries are composed of a mix of letters and numbers
SELECT foo, length(foo) l
FROM someTable
ORDER BY order by l, foo;