Monday, March 14, 2011

recursively removing files with wildcard in linux

If you are a Linux rookie as me, you might expect this to work, as well as I did:
rm -r *.class

Bozinga! this only deletes the *.class under wherever you are, because wildcards are expanded before executing the commands.

here is a non-trivial command that does the seemingly trivial magic you wish:
find /path_to_search -type f -name "*the_patern*" -exec rm {} \


Thursday, March 10, 2011

Installing Ubuntu 10.10 on my Thinkpad T60

Just for future reference. Should write a bash script to automate this.
  • Ubuntu Screen flickering/flashing problem with ATI x1300/x1400
    cat /etc/modprobe.d/radeon-kms.conf 
    options radeon modeset=1
    reboot
  • Install Java
    Turn on "Partner" in repo list
    sudo apt-get update  
    sudo apt-get install sun-java6-jdk
  • Install Aptitude
  • Install chrome, dropbox, eclipse
  • Sync VI configuration, Sync Terminal configuration, Sync .bash_aliases
  • Layout Dev, Workspaces, git clone, etc

Thursday, January 27, 2011

Windows Command Line args to get file paths

%~0 - expands %I removing any surrounding quotes (")
%~f0 - expands %I to a fully qualified path name
%~d0 - expands %I to a drive letter only
%~p0 - expands %I to a path only
%~n0 - expands %I to a file name only
%~x0 - expands %I to a file extension only
%~s0 - expanded path contains short names only
%~a0 - expands %I to file attributes of file
%~t0 - expands %I to date/time of file
%~z0 - expands %I to size of file

The flags can be combined.

Friday, January 21, 2011

Accessing 32bit Registry under 64bit machine (non-wow location)

Starting from .Net 4.0, there is actually RegistryView used for this purpose. For any .Net version earlier than that, here is the rule:

"The rules are pretty straightforward:

  • .NET app compiled for "x86":
    • Always 32-bit
    • On 32-bit platforms, accesses 32-bit registry
    • On 64-bit platforms, accesses 32-bit registry (inside Wow6432Node)
      • 64-bit registry inaccessible (without doing something weird)
  • .NET app compiled for "x64":
    • Always 64 bit
    • On 32-bit platforms, won't run
    • On 64-bit platforms, accesses 64-bit registry (not inside Wow6432Node)
      • If you want to get to the 32-bit registry, you need to do something weird
  • .NET app compiled for "AnyCpu"
    • Either 32 or 64 bit depending on platform
    • On 32-bit platforms, accesses 32-bit registry
    • On 64-bit platforms, accesses 64-bit registry (not inside Wow6432Node)
      • If you want to get to the 32-bit registry, you need to do something weird

"Something weird" technically requires passing a special flag to RegOpenKeyEx to obtain the alternate registry view. .NET doesn't expose any function that will do this nicely, so you'd have to drop to p/invoke to get there."

Reference: http://social.msdn.microsoft.com/forums/en-US/netfx64bit/thread/92f962d6-7f5e-4e62-ac0a-b8b0c9f552a3

Saturday, December 4, 2010

Git Gotta

>> mkdir foo
>> git init
Initialized empty Git repository in /home/jianlu/repos/web/foo/.git
>> git branch master
fatal: Not a valid object name: 'master'.

// How to fix this?
// make an arbitrary checkin by git submit. You are done.

Update:
git commit --allow-empty -m "initial commit"

Source of this update: (thanks to Mohamed Meligy's tip)

>> git branch
master.

Git claims this to be by design because before the user makes the first initial commit, there is nothing to be branched.

This kinda makes sense but not always a valid restriction. It is not a rare case that you want to lay out your repository structure because you know the repro structure should be like that even before you write the first line of your project code.

and btw, this is a terrible error message. It barely says anything about the real cause of this failure, or any suggestion on possible fixes.

Sunday, November 28, 2010

Some random mysql pitfalls.

Constraints
Only PK, FK, Nullability, Unique are enforced in InnoDB. Check (expression) is not. So don't expect the following check constraint to help you catch any insertion/update with foo.value <= 20.



FK
both sides of your FK should have exactly the same signature. Otherwise you get errno 150, which indicates a syntax error in FK definition.

Monday, September 27, 2010

Uninstalling MySQL on Mac OS X

Source: http://steveno.wordpress.com/2009/03/26/uninstall-mysql-on-mac-os-x/

  • sudo rm /usr/local/mysql
  • sudo rm -rf /usr/local/mysql*
  • sudo rm -rf /Library/StartupItems/MySQLCOM
  • sudo rm -rf /Library/PreferencePanes/My*
  • edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
  • sudo rm -rf /Library/Receipts/mysql*
  • sudo rm -rf /Library/Receipts/MySQL*