Skip to content

Instantly share code, notes, and snippets.

@jnaskali
jnaskali / gist:2000163
Created March 8, 2012 10:20
JavaScript: Input onFocus onBlur change
<script type="text/javascript">
function myFocus(element) {
if (element.value == element.defaultValue) {
element.value = '';
}
}
function myBlur(element) {
if (element.value == '') {
element.value = element.defaultValue;
}
@jnaskali
jnaskali / gist:2000168
Created March 8, 2012 10:21
JavaScript: HTML form post in new window
<form action="file.php" method="post" target="foo" onSubmit="window.open('', 'foo', 'width=450,height=300,status=yes,resizable=yes,scrollbars=yes')">
@jnaskali
jnaskali / gist:2000173
Created March 8, 2012 10:22
htaccess: Maintenance mode, allow own ip through
# FOR MAINTENANCE ONLY
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/maintenange.html$
RewriteCond %{REMOTE_HOST} !^000\.000\.000\.000
RewriteRule $ /maintenance.html [R=302,L]
# REMOVE FOR MAINTENANCE ONLY
@jnaskali
jnaskali / gist:2000180
Created March 8, 2012 10:23
htaccess: Change timezone
php_value date.timezone Europe/Helsinki
SetEnv TZ Europe/Helsinki
@jnaskali
jnaskali / gist:2000188
Created March 8, 2012 10:24
htaccess: Generic canonization (both no-www2www and www2no-www)
Non-www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]
@jnaskali
jnaskali / gist:2000221
Created March 8, 2012 10:27
htaccess: allow ip through htpassword protection
Deny from all
Order deny,allow
AuthType Basic
AuthName “Restricted”
AuthUserFile /path_to_password/.htpasswd
Require valid-user
Allow from 192.168.1.10
Satisfy Any
@jnaskali
jnaskali / gist:2000247
Created March 8, 2012 10:29
htaccess: Host domain in subdirectory
# IF newdomain AND not subdir THEN redirect to subdir
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com
RewriteCond %{REQUEST_URI} !^/domain
Rewriterule ^(.*)$ /domain/$1 [L]
@jnaskali
jnaskali / gist:2000279
Created March 8, 2012 10:31
CSS: Image Replace
.imageReplace {
border:0;
font: 0/0 a;
text-shadow:none;
background-color:transparent;
}
@jnaskali
jnaskali / gist:2006108
Created March 9, 2012 11:13
MYSQL: Select min/max row from each category
SOURCE: http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/
+--------+------------+-------+
| type | variety | price |
+--------+------------+-------+
| apple | gala | 2.79 |
| apple | fuji | 0.24 |
| apple | limbertwig | 2.87 |
| orange | valencia | 3.59 |
| orange | navel | 9.36 |
@jnaskali
jnaskali / gist:2021345
Created March 12, 2012 11:45
bash: Test disk I/O speed from console/ssh
dd if=/dev/zero of=test bs=64k count=16k conv=fdatasync && rm test