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 / 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'),
@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();
}
@AshKyd
AshKyd / get-colours-in-page.js
Last active December 31, 2015 11:59
Find all the colours in a page.
function rgbStrToHex(str){
function rgbToHex(r,g,b){
var bin = r << 16 | g << 8 | b;
return '#'+(function(h){
return new Array(7-h.length).join("0")+h
})(bin.toString(16).toUpperCase())
}
if(!str){
return;
@AshKyd
AshKyd / isvisible.js
Last active January 3, 2016 12:59
Is a given element on the screen at this time?
/**
* Check whether an element is visible
* @param {jQuery} elm jQuery element
* @return {Boolean} True if any part of the element is on the screen.
*/
function isVisible( ele ) {
var viewportTop = $(window).scrollTop();
var viewportBottom = viewportTop + $(window).height();
var eleTop = $(ele).offset().top;
var eleBottom = eleTop + $(ele).height();
@AshKyd
AshKyd / isScrolling.js
Created January 17, 2014 01:40
Is the document scrolling right now? Prevent jank by pausing stuff while the user's trying to navigate the document.
var isScrolling = false;
$(document).ready(function(){
var scrollTimeout = false;
var scrollTimeoutFn = function(){
isScrolling=false;
scrollTimeout = false;
}
jQuery(window).bind('scroll', function(){
isScrolling = true;
if(scrollTimeout){
@AshKyd
AshKyd / rfc2822.js
Last active October 7, 2023 19:42
A momentjs RFC2822 formatted date string.
var DATE_RFC2822 = "ddd, DD MMM YYYY HH:mm:ss ZZ";
moment().format(DATE_RFC2822);
@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'],
}