Monday, March 29, 2010

CanoScan LiDE 30 on OS X (10.4 - 10.7) - as easy as Linux (almost)!

Any scanner that works in Linux should work in OS X using the twain-sane drivers. No more running PhotoShop in Rosetta mode (I've never done it, but that's what I've read others have had to do).

[Edit: February 16, 2011] put steps 2 and 3 in the correct order
[Edit: April 21, 2011] added note to remove canon software
[Edit: August 14, 2011] began looking at fixes for Lion
[Edit: February 11, 2012] highlighted comments addressing fixes


OS X 10.7 Lion
  1. Manually remove any Canon software / drivers you may have installed previously
  2. Install libusb.pkg (Lion)
  3. unzip OSX_Lion_SANE (sane-backends for Lion) and follow the readme
  4. Install SNAC [direct download] (optional)
    Note: you may have to uninstall and reinstall if you already have it installed.
Skewing problems in Lion

https://discussions.apple.com/message/17563201#17563201 - actiyo
I had the same skewed scans problem. The button was on the unlock position at the bottom of the scanner. I found that you must select "Detect Enclosing Box" and set the rotation angle to 0. Then the scan is fine even at 300 dpi. -achille


OS X 10.6 Snow Leopard

On OS X 10.6 twain-sane doesn't install properly via macports so you have to download and go through several next-next-finish clicks (painful, I know)
  1. Manually remove any Canon software / drivers you may have installed previously
  2. Install libusb.pkg (Snow Leopard) 
  3. Install sane-backends.pkg (Snow Leopard
  4. Install twain-sane interface.pkg
  5. Reboot (yes, you must do this)
  6. Open Image Capture
    open /Applications/Image\ Capture.app
  7. Click SANE
  8. Rock and Roll (and scan)

OS X 10.5 Leopard
  1. sudo port install twain-sane sane-backends # as easy as Linux :-P

OS X 10.4 Tiger
  1. Use the drivers supplied by Canon?
  2. Or follow the 10.6 instructions using these twain-sane drivers?
  3. Or use fink?

Thursday, March 18, 2010

Prolific USB to Serial PL2303 and OS X 10.4-10.7

Updates: 
  • [Feb 28th 2012] Info for OS X 10.7
OS X 10.7 - Lion

  1. Download and install osx-pl2303-0.4.1-failberg.pkg from failberg's github project
    (you will need to reboot)
  2. Login to Apple Developer Center - developer.apple.com/downloads/index.action
  3. Download and Install command_line_tools_for_xcode_.dmg
  4. Install Homebrew
    /usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
  5. Install minicom
    brew install minicom

OS X 10.6 - Snow Leopard

  1. Install MacPorts for your version of OS X
    (1.8.2 - Snow Leopard at the time of this writing)
    distfiles.macports.org/MacPorts/
    Download and open the dmg. Run the pkg.

    sudo port -v selfupdate

  2. Install the USB to Serial Adapter
    (0.3.1 marked for 10.4, tested working with 10.6)
    sourceforge.net/projects/osx-pl2303/
  3. Ignore the request to restart as well as the modem which appears in network connections
  4. Install and configure minicom
    wiki.openmoko.org/wiki/MacOS_X#USB_Serial_with_minicom

    sudo port install minicom # lrzsz for file xfer will also be installed
    ls /dev/cu. # should reveal /dev/cu.PL2303-0000101D or similar
    sudo minicom -s

    > Serial Port Setup
      Device: /dev/cu.PL2303-0000101D
      [enter][enter]

    >Modem and Dialing
      Init string: [empty string]
      Reset string: [empty string]
      Hang-up string: [empty string]
      [enter][enter]

    > Save the setup as default ("dfl")
    [enter][enter]

    > Exit
    [enter]

  5. To exit use
    [CTRL-A], [Z], [X]
  6. To connect again

    sudo minicom
    [enter][enter]

Key Words

Prolific USB to Serial PL2303
Prolific Serial to USB PL2303
OS X Tiger 10.4, OS X Leopard 10.5, OS X Snow Leopard 10.6, OS X Lion 10.7, OS X Mountain Lion 10.8

Friday, March 12, 2010

cyg-apt: apt-get for cygwin

You want to be able to apt-get intall stuff in cygwin?
Enter cyg-apt2.

First Install cygwin on WinBox with these packages:
wget
python


Then install cyg-apt

# Installing cyg-apt
start > run > cmd > cd c:\cygwin\
cygwin.bat
cd / # yes, you need to be at root
wget http://github.com/snaka/cyg-apt/raw/master/cyg-apt2 -o /usr/local/bin
wget http://github.com/snaka/cyg-apt/raw/master/cyg-apt -o /usr/local/bin
vim /usr/local/bin/cyg-apt2
# replace mirror with http://mirrors.rcn.net/pub/sourceware/cygwin (or some similar working mirror)
cyg-apt2 setup
cyg-apt2 update





# Installing the handy-dandy toolbox
cyg-apt2 install openssh rsync screen vim emacs nano


Appendix A
Older methods of installing cyg-apt, which no longer work include:
# The original
# wget http://www.lilypond.org/~janneke/software/cyg-apt -o /usr/local/bin/cyg-apt

# chmod a+xr /usr/local/bin/cyg-apt
# cyg-apt2 --mirror=http://mirror.mcs.anl.gov/cygwin update
# cyg-apt setup
# A newer method
# wget http://cyg-apt.googlecode.com/files/cyg-apt-1.0.7-1.tar.bz2
# tar xf cyg-apt-1.0.7-1.tar.bz2
# cd cyg-apt-1.0.7-1
# ./install-cyg-apt.sh



Appendix B
http://www.saltycrane.com/blog/2007/11/cygwin-install-tips/

Thursday, March 11, 2010

How do I tell which version of Ubuntu I'm running?

Here ya go:

#!/usr/bin/env sh
#/usr/local/bin/version
echo `head -n 1 /etc/apt/sources.list | cut -d' ' -f 3` `cat /etc/issue | cut -d' ' -f 1-2`

Go ahead and put that in /usr/local/bin/version to call at your goodwill and pleasure.

By Name: head -n 1 /etc/apt/sources.list | cut -d' ' -f 3
By Number: cat /etc/issue
By Kernel: uname -r

Other methods:
lsb_release -a
cat /etc/lsb-release

Appendix A:
http://ubuntu-tutorials.com/2007/01/27/how-to-find-your-ubuntu-or-kernel-version/

Tuesday, March 9, 2010

ssh-copy-id on OS X

[Edit Dec 16th 2011] Take your pick:

    brew install ssh-copy-id

OR


    sudo port install openssh +ssh_copy_id

OR
    wget http://blog.christopherpitzer.com/wp-content/uploads/ssh-copy-id \
      -O /usr/bin/ssh-copy-id
    sudo chmod +x /usr/bin/ssh-copy-id





Supposedly if you install macports for Snow Leopard, Leopard, or Tiger and then modify your PATH then you can get the "real" version of OpenSSH like so:
sudo port install openssh
# to start sshd (the server) on boot:
# sudo launchctl load -w /Library/LaunchDaemons/org.macports.OpenSSH.plist

But as far as I can tell, this doesn't actually include ssh-copy-id either.

Monday, March 8, 2010

Polymorphic Associations in Rails

I've already done this once before, but I didn't blog it, so I forgot it. (You have to teach something in order to really learn it).


Essentially: The "belongs_to :arbitrary_name" means what you're going to call all of the different things to which this item can belong. It's arbitrary. The "has_many" of the owner has to include "as :arbitrary_name"


Let's say you're doing asynchronous uploads using cors_uploads and PaperClip and you don't know what something is going to be attached at the time you upload it.

Scenario:
Professors can create assignments and attach several files are necessary for students to have in order to complete the assignment.

Likewise, Students can upload multiple files with an assignment.

When they add a file it begins to upload immediately.
When the file completes a callback adds its ID to a hidden field in the form.
If the form is submitted before the uploads are complete the callback updates the upload with the assignment ID instead of adding its ID to the form.
If the browser window is about to be closed it will warn the user if uploads are still in progress.

One solution is to have a model for student uploads and another for professor uploads... but that leads to a possibly messy file system as you add more and more types of uploads.

Instead we create one model for assets which can belong_to anything "attachable". We define that assignments and submissions can have many assets as an attachable.

class Asset < ActiveRecord::Base
    belongs_to :attachable, :polymorphic => true
  end

  class Assignment < ActiveRecord::Base
    has_many :assets, :as => :attachable         # The :as option specifies the polymorphic interface to use.
  end 
 
class Submission < ActiveRecord::Base
    has_many :assets, :as => :attachable         # The :as option specifies the polymorphic interface to use.
  end
 
 
# Then something like 
if params[assignment]
@asset.attachable = Assignment.find(params[assignment][:id])
elsif params[submission]
@asset.attachable = Submission.find(params[submission][:id]) 
end 
# Or
@assignment.assets << Asset.find(params[asset][:id])  

Rails Documentation (see the Polymorphic Association section):
http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html