mobile - Conditional Viewport - Serve different viewports to different clients

I had a situation where I needed to serve different viewports to different mobile devices.

A little php makes this a trivial affair, as long as you know the user-agents that your targeting.

<?php

if(stristr($_SERVER['HTTP_USER_AGENT'], 'iPad')) {

//Probably an iPad

     echo '<meta name="viewport" content="width=980;user-scalable=yes;" />';

}

else{

     echo '<meta name="viewport" content="width=1150;user-scalable=yes;" />';

}

?>

Filed under  //  mobile   php  
Comments (0)
Posted

Disable Cache for Mobile Safari (and others)

<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="pragma" content="no-cache">

Filed under  //  html   meta   mobile  
Comments (0)
Posted

CSS - Spot unsized images during development

Add this to stylesheet to find all unsized images

img:not([width]):not([height]) {
  border: 2px solid red !important;
}

Thanks for the tip, 37signals. Link to their original post.

Filed under  //  css  
Comments (0)
Posted

SQL - Replace Text

No matter how many times I use this command, I always have to look it up.  Be careful, it's maddenly easy to wreak havok with this one.

update TABLE set COLUMN=replace(COLUMN, 'old string', 'new string');

Filed under  //  mysql   sql  
Comments (0)
Posted

Shell - Gzip all files of a certain type

The following command will gzip all the .sql files in a directory using xargs.

find . -name '*.sql' | xargs -n1 gzip

Side note: I've reduced 1.5GB folders of database backups to under 200MB using the exact command.

 

Filed under  //  batch   shell   xargs  
Comments (0)
Posted

Shell - Bulk change file extension

You can adapt this for any filename find/replace, but I find it most useful for changing a directory of .html files to .php files.

for file in *.html ; do mv $file `echo $file | sed 's/\(.*\.\)html/\1php/'` ; done

Filed under  //  shell  
Comments (0)
Posted

Apache - Make Yslow Happy (on MediaTemple)

Add these lines to .htaccesss:

Enable GZIP/DEFLATE: (http://wiki.mediatemple.net/w/GS:Mod_gzip)

AddOutputFilterByType DEFLATE text/html text/plain text/xml
AddOutputFilterByType DEFLATE text/css application/x-javascript
AddOutputFilterByType DEFLATE text/css text/html text/plain text/xml text/javascript

Enable etags (if you are on a single server/gridserver):

FileETag MTime Size

Disable etags (if you are on multiple servers):

Header unset ETag FileETag None

Filed under  //  apache   speed  
Comments (0)
Posted

Shell - Zip a file from the command-line

zip -b . myfile.zip myfile

Filed under  //  shell  
Comments (0)
Posted

SSH - Passwordless Logins and Shortcuts

When you're logging in and out of servers all day, typing logins and passwords gets old quick. This is especially helpful if you have different usernames on different systems.

 

Let's turn:

[user@home] $ ssh user@server.com
user@server.com's password: xxxxxxxxxxxxxxxxxxxxx
[user@server.com] $

into:

[user@home] $ ssh shortcut
[user@server.com] $

Get rid of the password:

Make yourself an ssh key if you haven't already (defaults are fine, don't specify passphrase)

$ ssh-keygen

Copy the key to the server:

$ cat ~/.ssh/id_rsa.pub | ssh user@server.com "cat - >> ~/.ssh/authorized_keys"

At this point, this command will work without a password:

[user@home]$ ssh user@server.com

Make the shortcut

Create the file ~/.ssh/config

Use the following format:

Host shortcut
User user
Port 22
HostName server.com

Now this command will work:

[user@home]$ ssh shortcut

Filed under  //  ssh   unix  
Comment (1)
Posted

SQL - Duplicate Table

CREATE TABLE newtable LIKE oldtable;INSERT newtable  SELECT * FROM oldtable;

Filed under  //  mysql   sql  
Comments (0)
Posted