PHP date format for MySQL DATETIME fields

date("Y-m-d H:i:s", $timestamp);

Posted in PHP | Tagged , | Leave a comment

Dump MySQL table or SELECT resultset into CSV or TSV file

Full table select:


SELECT * INTO OUTFILE '/tmp/file.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM `table`;

Variations(for instance select from derived table):

SELECT tbl.* INTO OUTFILE '/tmp/file.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM (
SELECT t1.category_name, t2.full_name
FROM table1 t1
LEFT JOIN table2 t2 ON t1.category_id = t2.category_id
) AS tbl;

To add a heading row into the exported by MySQL CSV file you can use UNION statement:

SELECT 'Column Name 1', 'Column Name 2'
UNION
(
SELECT tbl.column1, tbl.column2 INTO OUTFILE '/tmp/file.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM table1 tbl
);

Note: /tmp/file.csv must writable by mysql process

Posted in Just messing... | Leave a comment

Choosing Credit Card Fraud Detection Service: MaxMind® vs. FraudLabs™

Credit Card fraud detection service may seem like an unnecessary thing, but if you’re running(or building) an ecommerce site that may potentially have a lot of transactions it’s something that you may want to look into as a measure of minimizing your chargebacks and your processing fees as well.

There are bunch of companies that provide credit card fraud detection service, two of them I came across while searching for such service for our latest project. MaxMind and FraudLabs

Continue reading

Posted in PHP | Leave a comment

Remove all .svn folders recursively

From the inside of the working copy:

Linux, Mac OS X, *BSD:

find . -name .svn -exec 'rm -rf {}\;'

Solaris, AIX:

rm -rf `find . -name .svn`

Remove .svn folders from Mercurial repository:

find . -iname .svn | xargs hg rm

Posted in Linux/UNIX | Tagged , , | Leave a comment

Find and Replace Across Multiple Files

Need to replace broken links across 1000 html files?

If you’re using linux/unix/macosx it’s just fire up the terminal and use this:

find -iname "*.htm" -exec sed -i 's/search/replace/' {} \;

search – is regex(or a string in the simplest form) what you’re looking for

replace – is what you’re replacing your string with

If you’re on Windows, well then it’s a bit more complicated. There is a nice tool – TextCrawler, it’s free and does the trick.

Posted in 4QuickLookUp, Linux/UNIX | Tagged , , , | Leave a comment

mysqdump procedures/functions only

mysqldump -Rdt -u username -p dbname > sqlfile.sql

Posted in Just messing... | Leave a comment

svn rollback

Sometimes I just wonder why there is no svn rollback… Well, this one should do it:

svn merge -rHEAD:NNNN rep-url working-copy

  • working-copy – path to your working copy.
  • rep-url – URL or path to your repository
  • NNNN – revision you want to rollback to

For instance this command below will merge rev. 2348 into your working copy:

svn merge -rHEAD:2348 svn+ssh://yourname@yoursvn.com/repository/path /home/yourname/project/yourproject

Don’t forget to commit after all conflicts are resolved.

Posted in Just messing... | Tagged | Leave a comment

Setting up complex data types in WSDL

Putting SOAP service on PHP platform is a piece of cake. There are few nice articles out there that will pretty much guide you through the whole setup(which is in fact just putting together WSDL and server-side functions to handle a request), so after half an hour of messing around you can have your own SOAP thingie going. One draw back there – the article would get you as far as sending simple types(like strings and floats) back and force between client and server. Now, this isn’t very helpful if you’re trying to build something more object oriented.

The basic problem that I hit setting up SOAP server for a data-sharing application(pretty much content repository for a network of websites) – how to set up a custom complex data type without going through that whole WSDL spec?

Continue reading

Posted in PHP | Tagged | Leave a comment

How to notify Google, Yahoo and MSN about your new sitemap.xml?

The other day I needed to build a script that will notify Google, Yahoo(seemingly those 2 will soon become 1) and MSN. With Google you surely can do it manually using their Webmaster Tools, but that’s no use to your server-side script. Short research brought up the sort-of ‘sitemap pinging’ service they have, so basically to notify Google about your new and shiny sitemap you just need to send request(basically open up) this URL:

http://www.google.com/webmasters/sitemaps/ping?sitemap=http://www.yoursite.com/sitemap.xml

Where, obviously, www.yoursite.com is url of your site, and sitemap.xml is the filename of your sitemap(you can also use Gzipped sitemap). If you don’t know how to do this, read up about cURL

Yahoo! has similar service:

http://search.yahooapis.com/SiteExplorerService/V1/ping?sitemap=http://www.yoursite.com/sitemap.xml

The thing I like about Yahoo though is their API… I wonder why the heck Google has closed theirs, it was such a nifty thing…

MSN is screwy as usual:

http://api.moreover.com/ping?u=http://www.yoursite.com/sitemap.xml

I don’t think other folks(like Ask.com) play any important role, but just in case the following list of ping urls for sitemap.xml submission should be handy if you’re scripting something like sitemap generating module:

Ask.com

http://submissions.ask.com/ping?sitemap=http://www.yoursite.com/sitemap.xml

If you know ping urls for other search engines and willing to share, I’d be vastly grateful :)

Posted in SEO | Tagged | 1 Comment

ActionScript urldecode/urlencode

Ugh… After coding in Flash for sometime I started forgetting basics… terrible! Sometimes reading manuals actually helps…

Looking for PHPish urldecode/urlencode functions in Flash ActionScript? Checkout unescape/escape function in ActionScript refence

In short both take String as a parameter and will give you unescaped/escaped string back.

For exampe:

var test_string = "your unescaped string";

/* this will urlencode give you a string that = "your+unescaped+string" */
var escaped_string = escape(test_string); 

/* will urldecode and give you your unescaped string back  */
var unescaped_string = unescape(escaped_string);
Posted in ActionScript | Leave a comment