Thursday, September 8, 2016

Install Spark on Mac

Minor Edit from

  • Install Java
    - Download Oracle Java SE Development Kit 7 or 8 at Oracle JDK downloads page.
    - Double click on .dmg file to start the installation
    - Open up the terminal.
    - Type java -version, should display the following 

    java version "1.7.0_71" 
    Java(TM) SE Runtime Environment (build 1.7.0_71-b14) 
    Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)  
  • Set JAVA_HOME 
export JAVA_HOME=$(/usr/libexec/java_home) 

  • Install Homebrew 
  • Install Scala
brew install scala 
export SCALA_HOME=/usr/local/bin/scala  
export PATH=$PATH:$SCALA_HOME/bin 

  • Install Spark 
sudo chown -R $(whoami) /usr/local
brew install apache-spark 
  • Add $SPARK_HOME/python/build to PYTHONPATH 
export SPARK_HOME=/usr/local/Cellar/apache-spark/2.0.0
export PYTHONPATH=$SPARK_HOME/libexec/python:$SPARK_HOME/libexec/python/build:$PYTHONPATH

  • Fire up the Spark 
For the Scala shell: 
For the Python shell: 
  • Run Examples 
Calculate Pi: 
./bin/run-example org.apache.spark.examples.SparkPi 
MLlib Correlations example: 
./bin/run-example org.apache.spark.examples.mllib.Correlations 
MLlib Linear Regression example: 
--class org.apache.spark.examples.mllib.LinearRegression 
examples/target/scala-*/spark-*.jar data/mllib/sample_linear_regression_data.txt  

How to install Spark on Mac OS X 
How To Set $JAVA_HOME Environment Variable On Mac OS X 
Homebrew - The missing package manager for OS X 

Sunday, January 6, 2013

Use Razr M on ATT/T-mobile

Note, this does not unlock nor root the phone, it only flashes the radio to Aussie (so that you can use ATT/T-mobile in US). You need a windows computer and a zip software (such as winrar), and I've only tested following steps on Razr M that's already on Jelly Bean 4.1.1.
  1. Get past the initial Verizon setup screen, which attempts to prevent you from proceeding unless there's a Verizon SIM already in the device. You do this by touching four corners of the screen. I did it with the phone in portrait mode (top left -> top right -> bottom right -> bottom left), and here is an idea how to do it in landscape mode.
  2. Skip through all the setup wizards and enable USB Debugging.
  3. Download and install the Motorola usb driver on windows machine, reboot windows
  4. Download and install RSDLite6.1.4 on the windows machine.
  5. Download (close to 600M)
  6. Download NON-HLOS.bin from the Aussie Razr M (dropbox link). This file is 102.4K, which is twice the size of the corresponding NON-HLOS.bin file from the above file.
  7. Replace the 49K NON-HLOS.bin in your above with the 102.4K file, and keep it in the zip format. If you have WinRar, just open the zip file with WinRar, navigate to the folder that contains the original NON-HLOS.bin, drag the new NON-HLOS.bin and choose replace and save.
  8. Open RSDLite6.1.4, choose your updated file, and unpack it within RSDLite6.1.4.
  9. Power off Razr M, and boot it in fastboot mode. To do this, hold three keys (power, volume up, volume down) together, until you see a menu; then use volume down to navigate to fastboot, and use volume up (not power) to select. Do this fast, otherwise the phone will boot itself into normal mode.
  10. Now connect the phone with the original usb cable to your windows machine, and RSDLite should detect the phone, click start, then wait about 15 minutes (yes, it's slow, but at least RSDLite will tell you it's working on it). If RSDLite couldn't detect the phone, make sure you installed moto usb driver, and turned on USB debugging. The phone will reboot itself into normal mode, and RSDLite will tell you the status of the flash.
  11. Power off the phone, and insert your micro-sim card (this is the middle size sim card that's used in iPhone4 or Nexus4, not the smaller nano-sim in iPhone5, nor the larger mini-sim in Galaxy Nexus or Nexus S). If you have a regular mini-sim, it's relatively easy to cut it with a micro-sim card cutter like this. You can still use your new micro-sim card as a regular mini-sim card, by just putting it into the remaining piece when you cut the card (warning, keep your original frame from the cut, and do not use so-called sim-card converter frames, which are usually thicker and couldn't be put back in the phone without damaging it).
  12. When you power up the phone, it may still complain about the sim card, and you need to dismiss the message that sim is not recognized, but it should just work now.
I only tested T-mobile, which worked fine with phone call and edge data (3G is not supported now, until T-mobile switches to the rumored 3.5G that uses 1700 mhz). ATT is also supposed to work, but I don't have ATT sim card for testing.

After this step, the phone will be useful for T-mobile/ATT in US. However, the phone still has the same old verizon/motorola crap-wares. If you want to flash the OS, you could consider root it, install safestrap, and try CM10. Note, CM10.1 is still buggy (such as camera not working) at the time of this writing. An alternative way is to install an unlocked bootloader using RSDLite, then simply do fastboot flash modem NON-HLOS.bin


Saturday, December 29, 2012



Wednesday, February 15, 2012

Converting PDF to Black and White

On Linux:
gs \
 -sOutputFile=output.PDF \
 -sDEVICE=pdfwrite \
 -sColorConversionStrategy=Gray \
 -dProcessColorModel=/DeviceGray \
 -dCompatibilityLevel=1.4 \
  input.PDF < /dev/null

Thursday, April 28, 2011

Windows 7 Laptop SSD Upgrade

What: replace 500G HDD to 120G SSD for Acer Laptop pre-installed with Windows 7.

  1. Make sure the 'content' on the primary drive is less than the SSD size.
  2. Physically reduce the primary partition to a size that is less than the SSD size. Goto control panel, search for disk partition, use the windows 7 disk manager to 'shrink' the primary disk.
    Caveat: need to turn off back ups, shadow disks etc, and even do a disk de-fragmentation if necessary. In my case, the minimal shrink size is 160G after turning off back ups, even though the used size is only 30G. I used the trial version of Perfect Disk 11 to do the de-frag, and then it can be shrinked to 30G.
  3. Back up the current system on an external hard drive. Do not use the regular back up disk to avoid pure incremental backup, which does not tak advantage of the newly partitioned smaller drive. Goto control panel and search for back up, very easy to set up.
  4. Burn a windows 7 recovery disk (again, search on control panel). A regular CD would suffice (only 100-200 M).
  5. Insert the recovery disk, disconnect the external hard drive, reboot.
  6. Wait until the computer boots from the recovery disk, connect the backup external hard drive, recover from there. Easy steps following the on-screen instructions.
    Caveat: in case it fails, try the command line tool
    > diskpart
    > select disk=0
    > detail disk
    > clean
    > exit
    > exit
  7. Reboot after everything is done. Congratulations!
Boot time decreased from 100 seconds to 50 seconds.

  • Never try it when the primary disk is bigger than ssd disk.
  • Acronis Image Tool now does not provide clone function for the trial version, don't waste your time there.
  • Don't try to recover from the Factory Reset Disks. After reset, the ssd would not be bootable. Maybe a windows os disk can 'fix' it later, but I haven't tried it.
  • Remember de-fragmentation in order to shrink the primary disk, especially your machine is kind of old. The disk allocation is really not that efficient.

Sunday, September 12, 2010