Skip to content

Instantly share code, notes, and snippets.

View AshKyd's full-sized avatar
🐳
a frood who really knows where his towel is

Ash Kyd AshKyd

🐳
a frood who really knows where his towel is
View GitHub Profile
@AshKyd
AshKyd / makelgbtlst.js
Last active August 29, 2015 14:04
Compile a dataset from the "LGBT rights by country or territory" wikipedia page. https://en.wikipedia.org/wiki/LGBT_rights_by_country_or_territory
var dataset = [];
/**
* Get an overall yes or no value for the cell. A no trumps a yes.
*/
function imgVal(cell){
var val;
$('img',cell).each(function(){
var alt = $(this).attr('alt');
if(alt === 'No'){
@AshKyd
AshKyd / makelanguagelist.js
Created July 26, 2014 15:01
Create a list of countries and languages spoken from the "List of official languages by state" page on Wikipedia https://en.wikipedia.org/wiki/List_of_official_languages_by_state
var countries = [];
// These states have no official languages, so override them with these ones.
var override = {
"United Kingdom": ['English'],
"United States": ['English'],
"Australia": ['English'],
"Mexico": ['Spanish'],
"Chile": ['Spanish'],
}
@AshKyd
AshKyd / go.sh
Last active August 29, 2015 14:15
Silverstripe with sqlite3 dev environment on Fedora (PHP 5.4+)
# Fedora-specific PHP environment setup
yum install php php-mbstring php-mysql php-gd
# Manually install composer via https://getcomposer.org/download/
# Install Silverstripe & sqlite driver
composer create-project silverstripe/installer ./ 3.1.10
composer require silverstripe/sqlite3 1.3.*@dev
# Launch the dev PHP server
@AshKyd
AshKyd / diff.py
Last active August 29, 2015 14:22
Nathan Hoad's git diff with meld script.
#!/usr/bin/python
# https://nathanhoad.net/how-to-meld-for-git-diffs-in-ubuntu-hardy
import sys
import os
os.system('meld "%s" "%s"' % (sys.argv[2], sys.argv[5]))
@AshKyd
AshKyd / random.js
Created August 17, 2015 23:03
Tiny seeded pseudorandom number generator.
function random(seed) {
var x = Math.sin(seed) * 10000;
return x - Math.floor(x);
}
var mySeed = 1234;
for(var i=0; i<10; i++){
console.log(random(mySeed++));
}
@AshKyd
AshKyd / README.md
Last active September 22, 2015 19:39
NPM-based project workflow

Had enough of Grunt and Gulp because they're difficult to configure and especially difficult to debug.

After a discussion with some BrisJS peers last month I've come up with a bunch of NPM scripts to do a bunch of common browserify+uglify+misc stuff. This is based around my own workflow and doesn't cover all the bases so ymmv, but it's been working for me for a while now so I figured I'd share.

Getting started

@AshKyd
AshKyd / gist:1202686
Created September 8, 2011 05:19
Determine if an IP address is coming from a local network.
/**
* Is this a local IP?
* @param {string} $ip The IP address you wish to checkk.
* @return {boolean} Whether the IP is visiting from a local network.
*/
function isLocalIp($ip){
// Some local IP ranges.
$ranges = Array(
Array('10.0.0.0','10.255.255.255'),
Array('172.16.0.0','172.31.255.255'),
// npm install wait-until --save-dev
waitUntil()
.interval(10)
.times(1000)
.condition(function(){
})
.done(function(){
});
@AshKyd
AshKyd / manifestgen.sh
Last active December 19, 2015 03:28
Generate a HTML5 manifest. Optionally checks for a (chrome app) manifest.json and increments version number/timestamp.
#!/bin/bash
# Generate a manifest file. Outputs to STDOUT.
# Usage: ./manifestgen.sh somefolder/
function scandir {
cd $1;
RELATIVEDIR=`pwd`;
if [ $BASEDIR == $RELATIVEDIR ]
then
RELATIVEDIR=""
else
@AshKyd
AshKyd / getContentType.js
Created December 6, 2013 14:47
Get the content type for a certain URL.
function getContentType(url,callback){
var oReq = new XMLHttpRequest();
oReq.onreadystatechange = function(){
if(this.readyState == this.DONE){
callback(this.getResponseHeader("content-type"));
}
};
oReq.open("head", url, true);
oReq.send();
}