Author: John Huh

Posted on: October 7, 2010 Posted by: John Huh Comments: 0

Autoload classes

Takes a bite out of including all your class files… http://php.net/manual/en/language.oop5.autoload.php http://www.codeforest.net/autoload-your-classes-in-php

Posted on: October 1, 2010 Posted by: John Huh Comments: 0

Adding form on the fly and submitting

[code lang=”js”] function post_to_url(path,params,method){ method=method||"post"; var form=document.createElement("form"); form.setAttribute("method",method); form.setAttribute("action",path); for(var key in params){ var hiddenField=document.createElement("input"); hiddenField.setAttribute("type","hidden"); hiddenField.setAttribute("name",key); hiddenField.setAttribute("value",params[key]); form.appendChild(hiddenField); } document.body.appendChild(form); form.submit(); } [/code] Consume it: <a title=”Title” href=”javascript:post_to_url(‘http://www.domain.com’,{‘rsit’:’3528′,’sit’:’2726′})”>Link</a>

Posted on: October 1, 2010 Posted by: John Huh Comments: 0

Regex

Detect subdomain and rewrite the front part of the subdomain: .htaccess [sourcecode] RewriteCond %{HTTP_HOST} ^auto(.*)domain.com >RewriteRule ^(.*)$ http://quotes%1domain.com/$1 [R=301,L] RewriteCond %{HTTP_HOST} ^auto(.*)domain.comRewriteRule ^(.*)$ http://quotes%1domain.com/$1 [R=301,L] [/sourcecode] Search and replace the domain only: [sourcecode] /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#?=~_|!:,.;]*[-A-Z0-9+&@#%=~_|]\/)/i [/sourcecode]

Posted on: September 28, 2010 Posted by: John Huh Comments: 0

Limit what?

How do you start at a certain row and limit it? Used for paging perhaps, but here it is how: [sourcecode language=”sql”] SELECT Description, Date FROM (SELECT ROW_NUMBER() OVER (ORDER BY Date DESC) AS Row, Description, Date FROM LOG) AS LogWithRowNumbers WHERE Row >= 11 AND Row <= 20 [/sourcecode]

Posted on: September 28, 2010 Posted by: John Huh Comments: 0

Postgresql 9.0 Cheatsheet

PostgreSQL 9.0 has been released. Here’s a cheatsheet for it: http://www.postgresonline.com/journal/archives/177-postgresql90_cheatsheet.html

Posted on: September 22, 2010 Posted by: John Huh Comments: 2

SSD or not?

I’ve been contemplating about getting a SSD (solid state drive) for my Macbook pro. Been reading many, many articles/blogs and the conclusion is… what am I willing to pay for the speed gain versus less storage space? So, then the next question is… Do I want to give up the …

Posted on: September 22, 2010 Posted by: John Huh Comments: 1

Microsoft SQL Xtype?

XType Datatype —————- 34 image 35 text 36 uniqueidentifier 48 tinyint 52 smallint 56 int 58 smalldatetime 59 real 60 money 61 datetime 62 float 98 sql_variant 99 ntext 104 bit 106 decimal 108 numeric 122 smallmoney 127 bigint 165 varbinary 167 varchar 173 binary 175 char 189 timestamp 231 …

Posted on: September 22, 2010 Posted by: John Huh Comments: 0

Tables and Fields dump

Here’s a quick way to see the user tables and fields within a database. [sourcecode language=”sql”] select s.id, s.name as table_name, c.[name] as column_name, t.name as datatype, c.length, c.xprec from sysobjects s inner join syscolumns c on c.id = s.id inner join systypes t on t.xtype = c.xtype where s.type …