Backing up SQL Server (the hard way)

Here's 1 way to back up SQL Server database without access to the physical hardware.

1. Start Menu > Sql Server 2008 R2 > Import and Export Data (64-bit)
2. Data Source (source sql server & credentials)
3. Data Target (local sql server & credentials)
4. Select tables to export

Note, this only exports tables & their respective data.

If all you want is to copy the schema...

1. Right click on the database you want to export
2. Tasks > Generate Scripts...
3. Select ALL
4. Save to clipboard
5. Copy & paste clipboard contents to local database query window
6. Execute query

Note, if there are any custom data types, you'll probably have to create those manually

GIT: Using GITX with Manual Push

I'm new with GIT and GITX so please feel free to comment if there are more efficient ways of doing this outside of downloading plugins / other open-source versions of GITX such as GITX(L).

Versioning changes locally:
1. Goto Commit View
2. Under Unstaged Changes section, select the changes you wish to version
3. Right click and select Stage
4. The files should now appear in the Staged Changes section
5. Enter a Commit Message
6. Click Commit
7. Done

Promoting changes to git server:
1. Open Terminal
2. Goto head directory of git repo
3. Type git push
4. Once done, you should see a message:

To http://[git.server]/[git.path]/[git.repo].git
6a8ff81..72a89a7 master -> master

Reverting changes locally:
1. Goto History View
2. Drag the origin/HEAD and origin/MASTER to the revision you want
3. Now you can overwrite the bad changes by promoting a new one

XCODE4: Fail to build for iOS 4.0, 4.1

To begin, I'm running Xcode 4.0.2, Build 4A2002a

Nothing goes wrong when compiling my project for iOS 4.2/4.3. However, when using it to compile using iOS 4.0/4.1, I get lots of the following errors;

uint8_t not defined, uint16_t not defined, uintptr_t not defined, etc...

or

cc1plus: error: /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk/usr/include/c++/4.2.1/arm-apple-darwin10/v7: not a directory

or

ld: warning: ignoring file /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk/usr/lib/libSystem.dylib, file was built for unsupported file format which is not the architecture being linked (armv6)
ld: warning: symbol dyld_stub_binder not found, normally in libSystem.dylib
Undefined symbols for architecture armv6:




I believe all of these errors has to do with a faulty installation... For some reason, while installing xcode 4.0.2, it either forgets to set up the file-links properly, or maybe apple purposely left it out to drive developers to use the new OSs... either way, it caused about an hour of headache.



The solution for item #1, is to open up stdint.h... notice that the file contains no more than couple lines of crap... something along the lines of:

XSym
0027
88c0b7e54f82f10929bdfc91ac2dbefd
gcc/darwin/default/stdint.h

Where default obviously refers to GCC version... but the linkage went wrong somewhere, and so stdint.h was never included, thereby causing all your headache. The solution is to (1) manually include the stdint.h in your project, or (2) copy and paste the content into the file with the mumbo-jumbo above.


The solution for item #2 is to fix the symbolic links that somehow got corrupted. Any references to v6 and v7 are supposed to map to the following directories:

ln -s /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.#.sdk/usr/include/c++/4.2.1/armv6-apple-darwin10 v6
ln -s /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.#.sdk/usr/include/c++/4.2.1/armv6-apple-darwin10 v7


Obviously, don't forget to replace out the # sign in the commands above... or else, good luck with that command :P


The solution for item #3 is yet another failed symbolic link (ARGH!). libSystem.dylib is supposed to be a symbolic link to libSystem.B.dylib. But NO! Something happened and now it's just a file taking up space. Fix this symbolic link and you're back in business. At least, I am.

ln -s /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.#.sdk/usr/lib/libSystem.B.dylib libSystem.dylib

Again, don't forget about the # sign.

XCODE4: Stuck on Attaching to 'Appname'

CTRL+R usually runs the application on the Simulator automatically, but today it stopped suddenly. Instead, I just kept seeing "Attaching to Appname' message in the status window.

After some heavy googling, turns out it's scheme setting. To fix:

1. Goto Product > Run...

2. On the left hand side, select Run appname.app

3. Select the info tab on the right

4. Select Launch --> Automatically

For some reason, neither Automatically nor 'wait for appname.app to launch were selected.

---

If your simulator screen is already stuck in darkness (black screen of death),

1. Stop your running demo (hit the STOP button)

2. Goto menubar > iOS Simulator > Reset content and settings...

3. Re-run following the steps above

UNIX: Bash password input

read -s -p "Password: " mypasswd

or

stty -echo
read -p "Password: " mypasswd
stty echo

CENTOS: Installing Git 1.7.4.4 on 5.5

Using CentOS for the first time today, and boy did it bring back horrible memories of Unix in the ucsd computer dungeon...

Anyway, since it was a new installation of CentOS 5.5, installation required LOTS of updates...

1. log into root (su root)
2. wget http://kernel.org/pub/software/scm/git/git-1.7.4.4.tar.gz
3. tar -zxf git-1.7.4.4.tar.gz
4. cd git-1.7.4.4

let's just run the installation so that we can see what libs we are missing...

5. make prefix=/where-ever-i-want/git all

if you receive the following kind of error, you need to update/install packages...

expat.h: No such file or directory (yum install expat-devel)
zlib.h: No such file or directory (yum install zlib-devel)
openssl/ssh.h: No such file or directory (yum install openssl-devel, yum install curl-devel)
openssl/err.h: No such file or directory

you get the idea...

6. once installation completes, now you can install libs/binaries to the prefix directory...

7. make prefix=/where-ever-i-want/git install

OSX: Adding new user on 10.6

dscl . -create /Users/username
dscl . -create /Users/username UserShell /usr/bin/false
dscl . -create /Users/username RealName "User description"
dscl . -create /Users/username UniqueID ###
dscl . -create /Users/username PrimaryGroupID ###
dscl . -create /Users/username NFSHomeDirectory /dev/null
dscl . -passwd /Users/username PASSWORD

view users' full configs:

dscacheutil -q user

view particular user's full config:

dscacheutil -q user -a name username

view user's uid only:

dscl . list /Users uid

view group's gid only:

dscl . list groups gid

OSX: Installing mysql on 10.6

1. Download mysql-5.0.92.tar.gz

2. Unpackage to /usr/local/mysql-5.0.92/

3. Create symlink mysql

cd /usr/local/
ln -s /usr/local/mysql-5.0.92/ mysql

4. Open Terminal and set temporary PATH

export PATH=$PATH:/usr/local/mysql/bin

5. Create 2 folders

mkdir tmp
mkdir var

6. Configure mysql
./configure --prefix=/usr/local/mysql \
--with-extra-charsets=all \
--enable-thread-safe-client \
--with-unix-socket-path=/usr/local/mysql/tmp/socket \
--with-mysqld-user=mysql \
--with-comment \
--with-debug

7. Install mysql

make
make install

8. If during the installation process you encounter the following error:
/usr/bin/install -c 'bench-count-distinct' '/usr/local/mysql/sql-bench/bench-count-distinct'
install: bench-count-distinct and /usr/local/mysql/sql-bench/bench-count-distinct are the same file
make[3]: *** [install-benchSCRIPTS] Error 64
make[2]: *** [install-am] Error 2
make[1]: *** [install-recursive] Error 1

You aren't alone, the problem is with the OS and directory name resolution. The fix is to simply ignore these errors.

option A. make -i install

option B. edit /usr/local/mysql/sql-bench/Makefile line 418

from:

$(...) "$$d$$p" "$(DESTDIR)$(benchdir)/$$f"; \

to:

$(...) "$$d$$p" "$(DESTDIR)$(benchdir)/$$f" 2>/dev/null | wc -l; \

9. installing the database

sudo /usr/local/mysql/bin/mysql_install_db --force

10. create mysql user

dscl . -create /Users/mysql
dscl . -create /Users/mysql UserShell /usr/bin/false
dscl . -create /Users/mysql NFSHomeDirectory /dev/null
dscl . -passwd /Users/mysql PASSWORD

11. giving permission to mysql to write files

sudo chown -R mysql /usr/local/mysql

12. running the database (sudo is needed unless you are running from mysql account/root)

sudo /usr/local/mysql/bin/mysqld_safe --user=mysql &

13. creating a database root user

/usr/local/mysql/bin/mysqladmin -u root password rootpwd

14. stop running databases

/usr/local/mysql/bin/mysqladmin shutdown

15. as was the case with the tomcat server, here's a mini script that can simplify starting and shutting down the mysql server
#!/bin/bash
export PATH=$PATH:/usr/local/mysql/bin
if [ "$1" == "start" ]; then
sudo mysqld_safe -user=mysql &
elif [ "$1" == "stop" ]; then
sudo mysqladmin shutdown
elif [ "$1" == "info" ]; then
mysqladmin version
else
echo "Command: mysql [start|stop|info]"
fi

OSX: Installing tomcat on 10.6

TO INSTALL TOMCAT

1. Download jakarta-tomcat-x.x.xx.tar.gz

2. Unzip to /usr/local/tomcat-x.x.xx/

3. Create symlink tomcat

cd /usr/local/
ln -s /usr/local/tomcat-x.x.xx/ tomcat

4. Use the following script to start/stop tomcat
#!/bin/bash

export CATALINA_BASE=/usr/local/tomcat
export CATALINA_HOME=/usr/local/tomcat
export CATALINA_TMPDIR=/usr/local/tomcat/temp
export JRE_HOME=/*dir to java home*/
export CLASSPATH=/usr/local/tomcat/bin/bootstrap.jar

if [ "$1" == "start" ]; then
$CATALINA_HOME/bin/startup.sh
elif [ "$1" == "stop" ]; then
$CATALINA_HOME/bin/shutdown.sh
else
echo "Command: tomcat [start|stop]"
fi

5. Assuming the script's path is ~/tomcat, start the server using

~/tomcat start

6. Assuming the script's path is ~/tomcat, stop the server using

~/tomcat stop

OSX: Making symbolic links (folder aliases)

If you navigate to /Library/Java, you will notice there's a folder alias in there called Home, which maps to /System/.../Home

If you do an ls -l on the /Library/Java directory, you will see the following:

lrwxr-xr-x 1 xxxx xxxx xx xxx xx xx:xx Home -> /System/.../Home

This is a symbolic link, NOT to be confused with Aliases, and creating one is actually much easier than I thought.

First, to create an Alias, you just right click on a folder, and select Make Alias. This creates a 'shortcut file', not a symbolic link. Case in point, try typing the ls command on the folder shortcut you just made, Terminal will complain that the alias is NOT A DIRECTORY.

To create the symbolic link, you'd type the following:

ln -s /actual/dir/location/ linkname

Now you can ls on the linkname which will spit out the structure for /actual/dir/location/

VIM: How to type ^M character in GVIM

Kept seeing posts that say the character is typed by using C-V C-M, but obviously C-V = paste.

Instead, in GVIM, the key stroke is: C-Q, C-M

(C-Q = control+Q)

REGEX: Cleaning up sourcecode

remove comment lines
[\s\t]+//.+

remove multi-comment
\/\*([\s\S]*?)\*\/

remove empty lines
^\s*[\r\n]+

XP: Registry hack for JAD files

couple things I like to add to the context menu when I right click the jadfile:

1. open with wtk
2. open with vim

here's how to accomplish these things with a simple regedit hack:

STEP 1: Set up the open with...

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jad\OpenWithList]
"a"="gvim.exe"
"MRUList"="ab"
"b"="emulator.exe"

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jad\OpenWithProgids]
"jadfile"=hex(0):

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jad\UserChoice]
"Progid"="jadfile"

STEP 2: Set up the jadfile attribute

[HKEY_CLASSES_ROOT\jadfile\shell\vim]
@=">> vim"

[HKEY_CLASSES_ROOT\jadfile\shell\vim\command]
@="\"c:\\program files (x86)\\Vim\\vim73\\gvim.exe\" \"%1\""

[HKEY_CLASSES_ROOT\jadfile\shell\wtk]
@=">> wtk"

[HKEY_CLASSES_ROOT\jadfile\shell\wtk\command]
@="c:\\WTK2.5.2_01\\bin\\emulator.exe -Xheapsize:5M -Xdescriptor:\"%1\""

ANDROID: Factory Flash DroidX

Motorola Droid X SBF
http://www.multiupload.com/NYV7593UM3
http://www.multiupload.com/HS3Q4U95CG
http://rootzwiki.com/

Instructions (Linux)
1. Unzip the SBF and place VRZ_MB810_1.13.6.2_1FF_01.sbf and sbf_flash in the downloads folder
2. Put the Droid X in bootloader and connect it via usb.
3. Open a terminal window.
4.Change your directory: CD Downloads
5. Then type: ./sbf_flash VRZ_MB810_1.13.6.2_1FF_01.sbf
6. Wait and finish!

ANDROID: Superuser + Shared JNI LIBs

If you need access to system libs (in my case, uinput), you will usually need to do one of 2 things:

1. create another unix executable (binary), which will call uinput, and invoke it with su (super user). Put this file in the /raw directory, and copy it to the device during run-time. This seems to be the easier method. The source is as such:

your_copy_binary(R.raw.your_binary, getFilesDir().getAbsolutePath()+"/your_binary");
Process sh = Runtime.getRuntime().exec("su");
OutputStream os = sh.getOutputStream();
os.write("chmod 777 " + getFilesDir().getAbsolutePath() + "/your_binary" + "\n", "ASCII");
os.write(getFilesDir().getAbsolutePath() _ "/your_binary", "ASCII");

2. create a unix shared library embedded within your android app, call open(...) to directly access the system lib, give the manifest SUPERUSER permissions, and finally set the lib to chmod 777.

Here's the JNI sourcecode:
int success = open("/dev/input", O_WRONLY | O_NONBLOCK);

Here's the Manifest added permission:
< uses-permission android:name="android.permission.ACCESS_SUPERUSER" />

Here's the final step to chmod
chmod 777 /dev/uinput


I prefer the second method, because it's closer to how the android NDK was intended to run.

ANDROID: Eclipse J2EE Helios & Code Assist

Code assist is EXTREMELY slow for whatever reason on the HELIOS J2EE build. This wasn't happening before on Galileo. So I did some researching and found this nifty note on the interweb...

If you are using the JEE edition of HELIOS, the assists can be speeded up by turning off JAX-WS assist in the edit/advanced preference (Window->Preferences->Java->Editor->Content Assist->Advanced. It also appears that the assists cycle through a list of suggestion sources, starting with a different one each time, which would explain why the assists are not always slow.

Sped things up, but still slow... so then I checked for more links and ended with this one: https://bugs.eclipse.org/bugs/show_bug.cgi?id=317979

It states the bug is fixed in newer release of the Eclipse SDK. Too bad this still doesn't work!

Finally I reverted to GALILEO, and the issue is no more. It must be an issue on Android end, and not eclipse.

MACPORT: 1.9.1 + OSX 10.6.4

While attempting to install Android environment, it prompted me to install MACPORT, followed by this command:

POSIXLY_CORRECT=1 sudo port install gmake libsdl git-core gnupg

Which crashes when attempting to install db46, with a jni.h not found error. Some quick searching on the interweb later, I found this issue exists (probably) with the java sdk installed with Snow Leopard... and the fix is to install this dmg:

https://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/getSoftware?bundleID=20719

or direct link to the dmg:

http://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/getSoftware?fileID=26495&wosid=3h7EYNxPvekL2pGKzaKoAl6riR9



Edit: So this doesn't actually work for me, and I suspect it's because I'm on 10.6.4, not 10.6.3... but either way, I figured out how to get past db46:

copy and paste the content in:
/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Headers

into:
/opt/local/include

After db46 is installed, be sure to remove these additional header files... it's a bad hack.

IPHONE: Binary Submission + Invalid Binary

Kept getting this odd INVALID BINARY error message today whenever I'd try to submit my binary.

The problem is I submitted my binary earlier this week as a iPhone-ONLY application, but wanted to go back and change it to be a 'Universal' build.

There used to be an option in Itunes Connect to choose which devices you wanted to target, but now it's all just handled in your application building process.

Anyway here's the settings for the ORIGINAL build that was an 'acceptable' build:
- Architecture: Standard (armv6 armv7)
- Base SDK iOS: Device 4.1
- Targeted Device Family: iPhone
- iOS Deployment Target: iOS 4.0

Here's what I tried to change the build to, which caused the INVALID BINARY error:
- Architecture: Standard (armv7)
- Base SDK iOS: Device 3.2
- Targeted Device Family: iPhone/iPad
- iOS Deployment Target: iOS 3.2

Here's what finally worked (universal build):
- Architecture: Standard (armv6 armv7)
- Base SDK iOS: Device 4.1
- Targeted Device Family: iPhone/iPad
- iOS Deployment Target: iOS 3.2

Too lazy to test exactly what was the cause of the issue, but it's obviously between the 'Architecture' or the 'Base SDK iOS'. My guess is the Architecture over Base SDK... but who knows.

JNI + MAC OS X: Simple sample

Couple things to be aware of:

#1. for MAC OS X, the binaries end with .dylib or .jnilib (not .so, .dll)
#2. when compiling the shared lib, you should split up the compilation from the linking
#3. when compiling the shared lib in MAC OS X, be sure to specify the JavaVM framework

The code is like every other JNI example, so I wont post it here. The actual problem was in the command-prompt commands... which should go something like this:

javac HelloWorld.java
javah -jni HelloWorld
cc -c -I/Library/Java/Home/include helloworld.c
cc -dynamiclib -o libhelloworld.jnilib helloworld.o -framework JavaVM
java HelloWorld

5 simple lines...

Do not use the following line to compile for MAC OS X, it will give you all sorts of complaints:
[g]cc -dynamiclib [-G] [-m32] -o helloworld.dylib -I/Library/Java/Home/include [-arch i386] helloworld.c

Again.. DO SEPARATE the COMPILATION and the LINKING steps!!!

These are common error messages that spawn from the above command...

Exception in thread "main" java.lang.UnsatisfiedLinkError: no helloworld in java.library.path (missing javavm definition)

Exception in thread "main" java.lang.UnsatisfiedLinkError: no suitable image found. Did find: ... mach-o, but wrong architecture (ironically, not really caused by wrong architecture)

Exception in thread "main" java.lang.UnsatisfiedLinkError: no suitable image found. Did find: ... can't map (happens when you use wrong architecture)

ld: library not found for -l..., collect2: ld returned 1 exit status

Undefined symbols: "_main", referenced from: start in crt1.10.6.o, ld: symbol(s) not found, collect2: ld returned 1 exit status



PRINTER: Sharing a printer over WAN

On a mac, sharing printers over LAN is easy, and only involves a single checkbox. Sharing over WAN is more difficult...

1. Under Utilities > Print & Fax, remove the printer from the "server" (the machine physically connected to the printer)

2. In terminal, type the following lines:
cupsctl --remote-any
cupsctl --remote-printers
cupsctl --share-printers

3. Now go into the terminal on the "client" Mac

4. In terminal, type the following lines:
cupsctl --share-printers
cupsctl --no-remote-printers
cupsctl BrowsePoll=SERVERIP:631
cupsctl 'BrowseLocalProtocols="CUPS"'
cupsctl 'BrowseRemoteProtocols="CUPS"'

Edit... if this works, but then fails again, try the following (in this order):
A. Turn off the printer, and back on again (the QUEUE may be backed up)
B. Remove the printer from the Printer & Fax setup screen, and add it back again
C. Clear the Printer & Fax settings by holding OPTION while clicking the MINUS sign
D. Repeat step C for both Client & Server machines
E. Repeat steps 1-4 above and make sure all attributes are correct by using cupsctl