Skip to content

Instantly share code, notes, and snippets.

View davidwaterston's full-sized avatar

David Waterston davidwaterston

View GitHub Profile
@davidwaterston
davidwaterston / Javascript now() function
Created June 24, 2012 09:00
A cross-browser Javascript shim function to return the number of milliseconds elapsed since either the browser navigationStart event (using performance.now or browser equivalent) or the UNIX epoch, depending on availability.
var now = (function() {
// Returns the number of milliseconds elapsed since either the browser navigationStart event or
// the UNIX epoch, depending on availability.
// Where the browser supports 'performance' we use that as it is more accurate (microsoeconds
// will be returned in the fractional part) and more reliable as it does not rely on the system time.
// Where 'performance' is not available, we will fall back to Date().getTime().
// jsFiddle: http://jsfiddle.net/davidwaterston/xCXvJ
@davidwaterston
davidwaterston / Geolocating IP Addresses for free using geoPlugin.net and ColdFusion
Created July 8, 2012 00:05
A ColdFusion function to grab geolocation details for an IP address using the free geoPlugin.net service.
<cfcomponent name="geoPlugin" output="no">
<cffunction name="ipLocation" access="remote" returntype="struct" displayname="ipLocation" output="no">
<!---
This function takes an IP address and passes it to http://www.geoplugin.net, a free GeoLocation service that
returns info about where that IP address is located i.e. city, country, etc. The returned data from geoPlugin
is cleaned up and returned as a ColdFusion structure.
Where the IP address is not passed in then geoPlugin.net will use the IP of the calling page. The IP used is
always returned in the 'geoplugin.request' variable.
@davidwaterston
davidwaterston / gist:3741543
Created September 18, 2012 06:21
MySQL: Check if a table exists - version 1
select table_name as found
from information_schema.tables
where table_schema = '__database_name__'
and table_name = '__table_name__'
@davidwaterston
davidwaterston / gist:3741564
Created September 18, 2012 06:27
MySQL: Check if a column exists in a table
select column_name
from information_schema.columns
where table_schema = '__database_name__'
and table_name = '__table_name__'
and column_name = '__column_name__'
@davidwaterston
davidwaterston / gist:3741571
Created September 18, 2012 06:30
MySQL: Check if a table exists - version 2
show tables like '__table_name__'
@davidwaterston
davidwaterston / gist:3741590
Created September 18, 2012 06:35
MySQL: Check if a table contains any data
select 1
from __table_name__
limit 1
@davidwaterston
davidwaterston / gist:3742116
Created September 18, 2012 08:54
MySQL: Check if a table exists - version 3
select table_name as found
from information_schema.tables
where table_schema = SCHEMA()
and table_name = '__table_name__'
@davidwaterston
davidwaterston / gist:3755412
Created September 20, 2012 11:37
Oracle: Check if a table exists
select table_name
from user_tables
where table_name = '__TABLE_NAME__'
@davidwaterston
davidwaterston / gist:3755420
Created September 20, 2012 11:39
Oracle: Check if a column exists in a table
select column_name as found
from user_tab_cols
where table_name = '__TABLE_NAME__'
and column_name = '__COLUMN_NAME__'
@davidwaterston
davidwaterston / gist:3755428
Created September 20, 2012 11:40
Oracle: Check if a table contains any data
select 1
from __TABLE_NAME__
where rownum = 1