Permanently remove Mac’s “Downloaded from Internet” warning

Posted: January 29th, 2012 | Author: | Filed under: OS X | No Comments »
defaults write com.apple.LaunchServices LSQuarantine -bool NO

Of course, you should know what you are doing.


Apache VirtualDocumentRoot for wildcard virtualhosts

Posted: January 27th, 2012 | Author: | Filed under: Development | No Comments »
<VirtualHost *:80>
    UseCanonicalName Off
    VirtualDocumentRoot /mnt/projects/%1/public
    ServerName subdomains.starfall.local
    ServerAlias *.starfall.local
</VirtualHost>

<Directory /mnt/projects/*/public>
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

Now you might run into infinite redirect issue if use together with mod_rewrite. Add this line in the mod_rewrite .htaccess file for each folder under /mnt/projects to stop this.

RewriteBase /

Achieve wildcard custom domain via Automatic Proxy Configuration

Posted: January 27th, 2012 | Author: | Filed under: System | No Comments »

This allows to point multiple wildcard domain names (canonical or not) to a particular ip or hostname.

First create a Automatic Proxy Configuration file say wildcard.pac, which is basically a javascript file:

function FindProxyForURL(url, host)
{
    if (dnsDomainIs(host, ".customhost.local")) {
        return "PROXY customhost";
    }

    return "DIRECT";
}

Note:
“.customhost.local” is basically the pattern to detect
The “customhost” in “return “PROXY customhost”;” is whatever solvable hostname you want, or it can be an ip.

You can use this to config multiple local fake domain names for development purpose, pointing them (e.g. project1.myhost.local, project2.myhost.local to an apache server at 192.168.1.2).

Now to load this pac file, each browser/os is slightly different.
Safari/IE/Chrome: use system network setting, just find the Automatic Proxy Configuration and load the pac file just created.
Firefox/Opera: use their own network config in Preferences


Config Mac OSX Lion’s Samba share

Posted: January 27th, 2012 | Author: | Filed under: OS X | No Comments »

smb.conf no longer work. The actual configuration is stored at /System/Library/LaunchDaemons/com.apple.smbd.plist

To make Lion’s samba share follow symbolic link, you need to modify “ProgramArguments”
from:

<key>ProgramArguments</key>
<array>
     <string>/usr/sbin/smbd</string>
</array>
</code>

to:

<key>ProgramArguments</key>
<array>
     <string>/usr/sbin/smbd</string>
     <string>--no-symlinks</string>
     <string>false</string>
</array>

vimrc smart indent and tab with 4 spaces

Posted: January 26th, 2012 | Author: | Filed under: System | No Comments »

set smartindent
set tabstop=4
set shiftwidth=4
set expandtab ts=4 sw=4 ai


Push local git repo to a remote server

Posted: January 23rd, 2012 | Author: | Filed under: Development | No Comments »

So this is how to put local repository onto a remote “central” version control repository:

On remote server (note the “–bare” is important otherwise you won’t be able to push):

mkdir /home/vincent/projects/repo.git
cd /home/vincent/projects/repo.git/
git init --bare

On local, cd into the local repo directory first

git remote add origin ssh://username@remoteserver/home/vincent/projects/repo.git
git push origin master

In future you can just clone:

git clone ssh://username@remoteserver/home/vincent/projects/repo.git

jQuery Performance Tips

Posted: December 15th, 2011 | Author: | Filed under: JavaScript | No Comments »

http://dumitruglavan.com/jquery-performance-tips-cheat-sheet/

Some notes from reddit:

#6 There is little to no performance difference between a cached selector and chaining. The ONLY difference would be shorter code (less bandwidth used?).

#9 This is just plain wrong. DOM manipulation can be extremely fast if you know what you are doing. He uses this example

The faster way to do this would be

frag = $('<ul id="menu"></ul>');
listItem = $('<li></li>')
for (var i = 1; i < 100; i++) {
  frag.append(listItem.clone().text(i));
}
$('#header').prepend(frag);

#14 Use jQuery’s utility functions
“.each(), for example, relies on anonymous function calls. This can be REALLY slow”

#15 not really much of a performance tip
#16 is REALLY finicky and hard to profile.


Git deploy script

Posted: November 25th, 2011 | Author: | Filed under: Development | No Comments »

The script grab new files (after “git add”) and modified files and copy them to a new directory “deploy”.

git status | grep "modified\|new file" | awk '{print $3}' | while read file; do mkdir -p `dirname deploy/"$file"`; cp $file deploy/$file; done

Or, use this to create the deploy folder for commits done in the last 2 days: (the code may generate some error output saying certain files don’t exist, because it’s trying to copy the files you deleted in commits, they are harmless just too lazy to put check in)

git whatchanged --since "2 days ago" | grep ^: | awk '{print $6}' | sort | uniq -c | awk '{print $2}' | while read file; do mkdir -p `dirname deploy/"$file"`; cp $file deploy/$file; done

Two interesting jQuery plugins

Posted: November 21st, 2011 | Author: | Filed under: JavaScript | No Comments »

jScrollPane

ColorBox


Highcharts

Posted: November 14th, 2011 | Author: | Filed under: JavaScript | No Comments »

http://www.highcharts.com/


How to time machine

Posted: November 11th, 2011 | Author: | Filed under: OS X | No Comments »

http://blog.interlinked.org/tutorials/rsync_time_machine.html


Django production server

Posted: November 10th, 2011 | Author: | Filed under: Development, Python | 1 Comment »

Install

sudo apt-get install python-django libapache2-mod-wsgi python-mysqldb python-setuptools

Virtualhost

<VirtualHost *:80>
ServerName tang.local
WSGIDaemonProcess snake display-name=%{GROUP}
WSGIProcessGroup snake
WSGIScriptAlias / /mnt/host/snake/apache/django.wsgi

Alias /static  /mnt/host/snake/static
</VirtualHost>

WSGI script

import os
import sys
sys.path.append('/mnt/host')
sys.path.append('/mnt/host/snake')
os.environ['DJANGO_SETTINGS_MODULE'] = 'snake.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Sftp upload with lftp/mirror

Posted: November 2nd, 2011 | Author: | Filed under: Linux | No Comments »
lftp -c "open -u USERNAME,PASSWORD sftp://REMOTE_HOST/PATH/TO/ ; mirror -R /LOCAL/PATH/TO/."

Generate git change log

Posted: October 31st, 2011 | Author: | Filed under: Development | No Comments »
git whatchanged --since "2 month ago" | grep ^: | awk '{print $6}' | sort | uniq -c | awk '{print $2}' > change.log

Mount samba share on Mac Lion

Posted: October 18th, 2011 | Author: | Filed under: System | 1 Comment »
mount.cifs //griffith/vincent/Projects /mnt/projects -o user=vincent,password=1234,nounix,noserverino,sec=ntlmssp,uid=33,gid=1001,file_mode=0664,dir_mode=0775

Note: only need sec=ntlmssp for Mac


phpMyAdmin config.inc.php

Posted: October 15th, 2011 | Author: | Filed under: Linux | No Comments »
<?php

// Load secret generated on postinst
include('/var/lib/phpmyadmin/blowfish_secret.inc.php');

// Load autoconf local config
include('/var/lib/phpmyadmin/config.inc.php');

$i = 0;
$i++;

if (is_readable('/etc/phpmyadmin/config-db.php')) {
    require('/etc/phpmyadmin/config-db.php');
} else {
    error_log('phpmyadmin: Failed to load /etc/phpmyadmin/config-db.php.'
        . ' Check group www-data has read access.');
}

if (!empty($dbname)) {
    $cfg['Servers'][$i]['auth_type'] = 'cookie';
    if (empty($dbserver)) $dbserver = 'localhost';
    $cfg['Servers'][$i]['host'] = $dbserver;

    if (!empty($dbport) || $dbserver != 'localhost') {
        $cfg['Servers'][$i]['connect_type'] = 'tcp';
        $cfg['Servers'][$i]['port'] = $dbport;
    }
    $cfg['Servers'][$i]['extension'] = 'mysqli';
    $cfg['Servers'][$i]['controluser'] = $dbuser;
    $cfg['Servers'][$i]['controlpass'] = $dbpass;
    $cfg['Servers'][$i]['pmadb'] = $dbname;
    $cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark';
    $cfg['Servers'][$i]['relation'] = 'pma_relation';
    $cfg['Servers'][$i]['table_info'] = 'pma_table_info';
    $cfg['Servers'][$i]['table_coords'] = 'pma_table_coords';
    $cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages';
    $cfg['Servers'][$i]['column_info'] = 'pma_column_info';
    $cfg['Servers'][$i]['history'] = 'pma_history';
    $cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords';
    $cfg['Servers'][$i]['tracking'] = 'pma_tracking';
    $cfg['Servers'][$i]['userconfig'] = 'pma_userconfig';
    $cfg['Servers'][$i]['hide_db'] = '^information_schema|mysql|phpmyadmin$';
    $cfg['Servers'][$i]['AllowNoPassword'] = true;
    $cfg['Servers'][$i]['CountTables'] = true;

    $i++;
}

$cfg['DefaultLang'] = 'en';
$cfg['DisplayDatabasesList'] = 1;
$cfg['ServerDefault'] = 1;
$cfg['GZipDump'] = false;
$cfg['BZipDump'] = false;
$cfg['AllowUserDropDatabase'] = true;
$cfg['AllowArbitraryServer'] = true;
$cfg['LoginCookieValidity'] = 60000;
$cfg['LeftFrameDBSeparator'] = '';
$cfg['LeftDisplayTableFilterMinimum'] = 100;
$cfg['UserprefsDisallow'] = array('LeftFrameDBSeparator');
$cfg['ShowPhpInfo'] = true;
$cfg['ShowAll'] = true;
$cfg['MaxRows'] = 100;
$cfg['Order'] = 'ASC';
$cfg['LimitChars'] = 30;
$cfg['PropertiesIconic'] = true;
$cfg['Import']['charset'] = 'utf-8';
$cfg['Import']['ods_col_names'] = true;
$cfg['Export']['quick_export_onserver'] = true;
$cfg['Export']['quick_export_onserver_overwrite'] = true;
$cfg['Export']['charset'] = 'utf-8';
$cfg['Export']['sql_include_comments'] = false;
$cfg['Export']['sql_drop_table'] = true;
$cfg['Export']['sql_utc_time'] = false;
$cfg['Export']['csv_columns'] = true;
$cfg['Export']['excel_columns'] = true;
$cfg['Export']['htmlword_columns'] = true;
$cfg['Export']['ods_columns'] = true;
$cfg['Export']['texytext_columns'] = true;

Setup ubuntu on VMWare Fusion 4

Posted: October 15th, 2011 | Author: | Filed under: System | No Comments »

This is how to set up a ubuntu dev box on VMWare Fusion 4.02.

1. Add new Linux 64 machine, then edit the config with more memory and cpu

2. After installing Ubuntu, install the necessary software

sudo apt-get install vim ssh git-core build-essential lamp-server^ phpmyadmin

3. Now add new group dev, put main user and www-data to the group, update umask

4. Mount VMWare Tools cd in top menu “Virtual Machine -> Install WMWare Tools”. It will ask you to download the iso if you haven’t got it locally. (Also, if you run into problem mounting the iso, try re-enable CD/DVD and select the linux.iso in drop down list – it will appear after you downloaded it)

5. Now mount the cd and install it in Linux

sudo mkdir /mnt/cdrom; sudo mount /dev/cdrom /mnt/cdrom;
sudo cp /mnt/cdrom/VMwareTools-xxxxxxxxx[tab to find this] ~/
cd
tar -xzvf VMwareTools-xxxxxxxxx[tab to find this]
cd vmwarexxxxxxxx[tab]
./vmware-install.pl
## Now just answer the question and let it compile

6. Shutdown, turn on “Sharing” and add your local folder on Mac

7. After reboot a /mnt/hgfs will appear, however not in correct ownership. http://communities.vmware.com/thread/328819 has some solution. But we will using a slightly different approach: mount another with our own:

sudo mkdir /mnt/host
# Edit /etc/rc.local and add the following line before "exit 0"
mount -t vmhgfs .host:/ /mnt/host -o rw,uid=33,gid=1001,sync

7update: ok the build-in share sucks, do a samba share on Mac instead.

8. Now to config fixed ip address for the virtual machine by its MAC address (config MAC address in VMware’s “Network Adapter -> Advanced Options”)

# On Mac host
sudo vim "/Library/Preferences/VMware Fusion/vmnet8/dhcpd.conf"
# Add something like this ()
host <linux machine hostname> {
    hardware ethernet <MAC address of linux machine>;
    fixed-address <The static IP address you want>;
}
# Now modify your /etc/hosts with the new static ip

Geektool Scripts – Geeklets

Posted: October 7th, 2011 | Author: | Filed under: OS X | No Comments »

CPU Usage.glet
Date.glet
Quote of the day.glet
Time.glet
Top Processes.glet
Weather.glet


ShiftIt build

Posted: October 1st, 2011 | Author: | Filed under: OS X | No Comments »

This is a build based on fikovnik’s version.

By pressing hotkeys you can resize any window to one of the 10 position/size combinations. Of course this is mac only.


Monospaced Fonts for Programming

Posted: September 29th, 2011 | Author: | Filed under: Development | No Comments »

Some nice monospaced fonts.

  • Consolas.ttf
  • Mensch.ttf
  • Terminus.ttf
  • Inconsolata.ttf
  • Monaco.ttf