Skip to content

Instantly share code, notes, and snippets.

@fatgy
fatgy / gist:726606
Created December 3, 2010 05:10
Handy Hack:Perl DBI count rows returned from select statment
#From http://alecthegeek.wordpress.com/2007/02/09/handy-hackperl-dbi-count-rows-returned-from-select-statment/
#In theory it’s a bad thing to assume a select will return a single scalar value instead of multiple attributes and rows, however with a count #clause we should be pretty safe. N.B. using the $dbh->rows() function or similar is not correct on a select statement.
my $rowCount = $dbh->selectrow_array(
qq{
SELECT count(*)
FROM my_table
WHERE attr1 = ?
}, undef, $myValue);
@fatgy
fatgy / gist:732927
Created December 8, 2010 05:20
for loop
var anchors = document.getElementsByTagName("a");
for (var i = 0, j = anchors.length; i < j; i += 1) {
// do some stuff here
}
var anchors = document.getElementsByTagName("a");
for (var i = anchors.length; i > 0; i -= 1) {
// do some stuff here
}
@fatgy
fatgy / sortObj.js
Created December 14, 2010 10:36
How to Sort an Associative Array (object) in Javascript
// http://www.latentmotion.com/how-to-sort-an-associative-array-object-in-javascript/
function sortObj(arr){
// Setup Arrays
var sortedKeys = new Array();
var sortedObj = {};
// Separate keys and sort them
for (var i in arr){
sortedKeys.push(i);
@fatgy
fatgy / gist:740253
Created December 14, 2010 10:39
Javascript sort Object by value
/*
http://nemojkliknut.com/blog/javascript-sort-object-by-value/55
a simple bubble sort algorithm on an object
*/
function bubbleSortObject(object) {
for (i in object) {
for (k in object) {
@fatgy
fatgy / gist:743092
Created December 16, 2010 05:56
Regular Expression that splits the last line in an address into it's funtional parts.
//http://wiki.cdyne.com/index.php/City_State_Zip_Regex
^(?<city>[A-Za-z\s]*)(?:,\s?(?<state>[\sA-Za-z]+)|\s(?<state>[A-Za-z]{2}))
(?:
(?:\d{1,4})|
(?<zip>\d{5})(?:-\d{0,3})|
(?<zip>\s\d{5})-(?<zip4>\d{4})|
(?<zip>\s\d{5})|
(?<pc>\s[AaBbCcEeGgHhJjKkLlMmNnPpRrSsTtVvXxYy]\d[A-Za-z]\s?\d[A-Za-z]\d)|
)$
@fatgy
fatgy / circle_as_marker.js
Created March 10, 2011 04:54
Esa's Google Maps API v3 experiments. Circle overlay as a marker.
// http://koti.mbnet.fi/ojalesa/boundsbox/makemarker_circle.htm
/**
* makeMarker() ver 0.3
* creates Marker and InfoWindow on a Map() named 'map'
* now creates alternatively a Circle if 'radius' option property is given
* creates sidebar row in a DIV 'sidebar'
* saves marker to markerArray and markerBounds
* @param options object for Marker, InfoWindow and SidebarItem
* @author Esa 2009, 2010
*/
@fatgy
fatgy / gist:879082
Created March 21, 2011 05:42
get marker's coordinates (latitude,longitude,zoom,mercator,container,div) http://www.william-map.com/20100416/1/map.htm
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var map;
var marker;
var overlay;
@fatgy
fatgy / gist:1250371
Created September 29, 2011 09:16
Pentagon polygon on Google maps
<html>
<head>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var paths = [[
new google.maps.LatLng(38.872886, -77.054720),
new google.maps.LatLng(38.872602, -77.058046),
new google.maps.LatLng(38.870080, -77.058604),
new google.maps.LatLng(38.868894, -77.055664),
new google.maps.LatLng(38.870598, -77.053346)
@fatgy
fatgy / dabblet.css
Created December 21, 2011 05:03
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
background: white;
background-image: repeating-linear-gradient(-45deg,
rgba(255, 0, 0, 1) 25%,
transparent 25%,
transparent 50%,
rgba(0, 0, 255, 1) 50%,
@fatgy
fatgy / dabblet.css
Created December 22, 2011 08:44
Logo of some exhibition http://goo.gl/EK4Yp
/* Logo of some exhibition http://goo.gl/EK4Yp
from https://www.facebook.com/iCAREClub?ref=ts
*/
body {
font-size: 16px;
background-color: #DFE0E2;
color: #BA9254;
}