Skip to content

Instantly share code, notes, and snippets.

@adhipg
adhipg / me.sh
Created September 19, 2012 19:07 — forked from papercreatures/me.sh
rewrite locations to vim urls
node <script> 2>&1 | gist.sh
#!/bin/sh
sed -Ee "s#[(]?(/[^:]*/([^ ]*)):([0-9]+):([0-9]*)[)]?#[\2:\3:\4] mvim://open/?url=file://\1\&line=\3\&column=\4#g"

Just to make sure that I have all of this understood...

On the client side the code will look something like the following on the constructor:

save: =>
  errors = validator.validateMeeting(@toJSON())
  return super if not errors
  # there were errors - handle them.
@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;
}
?>
@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 / 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 / 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: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 / 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 / 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);
?>
# Reset the panels in GNOME:
gconftool --recursive-unset /apps/panel
rm -rf ~/.gconf/apps/panel
pkill gnome-panel