Skip to content

Instantly share code, notes, and snippets.

@adhipg
adhipg / colorYourProgress.js
Created December 25, 2009 18:28
Colour Your Progress
function colorThem ( domElement ) {
var green = parseInt ( ( domElement.text() / 100 ) * 255 );
var red = 255 - green;
greenString = green.toString ( 16 );
redString = red.toString ( 16 );
if ( greenString.length == 1 ) greenString = '0' + greenString;
if ( redString.length == 1 ) redString = '0' + redString;
<script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAEX95M5gKl7Nn_i4Mzl1TAhT4b5KCiYFj3ZfOJov1Qpq4YsRyghTrgMf7VDdXUg9oULkwfWhrlOumiQ" type="text/javascript"></script>
<script type="text/javascript">
var map = null;
var geocoder = null;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(29.427394,-98.624654), 15);
# Reset the panels in GNOME:
gconftool --recursive-unset /apps/panel
rm -rf ~/.gconf/apps/panel
pkill gnome-panel
@adhipg
adhipg / mask-credit-cards.php
Created February 17, 2011 12:02
Mask a Credit Card - keep the first character, last four characters and any non-numeric characters in the middle.
<?php
preg_replace('/(?!^.?)[0-9](?!(.){0,3}$)/', '*', $credit_card_number);
?>
@adhipg
adhipg / wordpress-update-posts-url.sql
Created March 10, 2011 06:57
SQL to update the posts table when we migrate websites from one site to another. Corrects the URLs of the attachments
UPDATE wp_posts SET post_content = REPLACE (post_content, 'oldlink', 'newlink');
@adhipg
adhipg / gist:1162478
Created August 22, 2011 14:16
MySQL Date to JavaScript Date
function getJavaScriptDate(timestamp) {
var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
var parts=drink.post_date.replace(regex,"$1 $2 $3 $4 $5 $6").split(' ');
return new Date(parts[0],parts[1]-1,parts[2],parts[3],parts[4],parts[5]);
}
@adhipg
adhipg / format_dates.php
Created September 12, 2011 11:10
Format a set of dates (timestamps) into a format like 1, 2, 3 Jan, 13 Feb, 15 Mar 2011
<?php
function formatDates( $dates ) {
$output = '';
$month = '';
$year = '';
sort( $dates, SORT_NUMERIC );
foreach ( $dates as $date ) {
@adhipg
adhipg / gist:1217103
Created September 14, 2011 17:01
Creating short URLs/hashes
<?php
function getHash( $n = '' ) {
if( $n == '' ) {
$n = rand();
}
$codeset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$base = strlen($codeset);
@adhipg
adhipg / countries.sql
Created January 12, 2012 11:41
Sql dump of all the Countries, Country Codes, Phone codes.
CREATE TABLE IF NOT EXISTS `country` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`iso` char(2) NOT NULL,
`name` varchar(80) NOT NULL,
`nicename` varchar(80) NOT NULL,
`iso3` char(3) DEFAULT NULL,
`numcode` smallint(6) DEFAULT NULL,
`phonecode` int(5) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
@adhipg
adhipg / removeemtpyhtml.php
Created January 19, 2012 10:18
remove empty html from a string
<?php
function removeEmptyHTML($html_replace="") {
while(preg_match("/<[^\/>]*>\s*<\/[^>]*>/", $html_replace)) {
$html_replace = preg_replace("/<[^\/>]*>\s*<\/[^>]*>/","",$html_replace);
}
return $html_replace;
}
?>