Coolscan 4000 on Windows 7

My Nikon Coolscan 4000 is the best thing I ever purchased, allowing me to scan 20 years of negatives high quality into my computer. However, with Nikon discontinuing support after Windows XP, when I found some negatives I had not scanned, I was quite upset. I was then lucky enough to run into this great instruction set: http://www.colorneg.com/XP/Vista/7/driver-for-64-Bit-Windows/Coolscan/Nikon-Scan/

To quote (in case his site ever goes down):

To get started download Nikon Scan 4.03 for Windows Vista 32 bit. Install the software on your 64 bit Windows 7 or Windows 8. Next we need to create a driver for your scanner that is 64 bit compatible. To do so create a new folder anywhere on your system you feel comfortable with. Depending on the scanner model you own copy the two files “NKScnUSD.dll” and “Nks1394.inf” or respectively “NksUSB.inf” which are to be found under “C:\Program Files (x86)\Common Files\Nikon\Driver\Scan1394” or “C:\Program Files (x86)\Common Files\Nikon\Driver\ScanUSB” into that folder. Open “Nks1394.inf” or respectively “NksUSB.inf” in a text editor of your choice to replace its contents. To do so click into the text box below and press Ctrl+A followed by Ctrl+C to copy the code. Next enter your text editor and press Ctrl+A followed by Ctrl+V to paste the code into the *.inf file.

;========================= Begin of scanners.inf ===============================
; scanners.inf - Windows Still Image Setup File
[Version]
Signature="$CHICAGO$"
Class=Image
ClassGUID={6bdd1fc6-810f-11d0-bec7-08002be2092f}
Provider=%Provider%
DriverVer=1/1/2009,1.0
[Manufacturer]
%Mfg%=Models,ntamd64
[Models]
; USB scanners
"Nikon LS-40" = USBScanner,USB\Vid_04b0&Pid_4000
"Nikon LS-50" = USBScanner,USB\Vid_04b0&Pid_4001
"Nikon LS-5000" = USBScanner,USB\Vid_04b0&Pid_4002
; Firewire scanners
"Firewire Scanner" = SBP2Scanner,SBP2\GenScanner
"Nikon SUPER COOLSCAN 4000 ED" = SBP2Scanner_NIKON,SBP2\NIKON___&LS-4000_ED______&CMDSETID104D8
"Nikon SUPER COOLSCAN 8000 ED" = SBP2Scanner_NIKON,SBP2\NIKON___&LS-8000_ED______&CMDSETID104D8
"Nikon SUPER COOLSCAN 9000 ED" = SBP2Scanner_NIKON,SBP2\NIKON___&LS-9000_ED______&CMDSETID104D8
;---------------- Duplicated from [Models]
[Models.ntamd64]
; USB scanners
"Nikon LS-40" = USBScanner,USB\Vid_04b0&Pid_4000
"Nikon LS-50" = USBScanner,USB\Vid_04b0&Pid_4001
"Nikon LS-5000" = USBScanner,USB\Vid_04b0&Pid_4002
; Firewire scanners
"Firewire Scanner" = SBP2Scanner,SBP2\GenScanner
"Nikon SUPER COOLSCAN 4000 ED" = SBP2Scanner_NIKON,SBP2\NIKON___&LS-4000_ED______&CMDSETID104D8
"Nikon SUPER COOLSCAN 8000 ED" = SBP2Scanner_NIKON,SBP2\NIKON___&LS-8000_ED______&CMDSETID104D8
"Nikon SUPER COOLSCAN 9000 ED" = SBP2Scanner_NIKON,SBP2\NIKON___&LS-9000_ED______&CMDSETID104D8
;---------------- USBScanner -------------------------
[USBScanner]
Include=sti.inf
Needs=STI.USBSection
SubClass=StillImage
DeviceType=1
DeviceSubType=1
Capabilities=0
[USBScanner.Services]
Include=sti.inf
Needs=STI.USBSection.Services
;---------------- SBP2Scanner ------------------------
[SBP2Scanner]
Include=sti.inf
Needs=STI.SBP2Section
SubClass=StillImage
DeviceType=1
DeviceSubType=2
Capabilities=0
[SBP2Scanner_NIKON]
Include=sti.inf
Needs=STI.SBP2Section
SubClass=StillImage
DeviceType=1
DeviceSubType=2
Capabilities=0
AddReg=NK1394SCN.AddReg
CopyFiles=NK1394SCN.CopyUSDFiles
[SBP2Scanner.Services]
Include=sti.inf
Needs=STI.SBP2Section.Services
[SBP2Scanner_NIKON.Services]
Include=sti.inf
Needs=STI.SBP2Section.Services
[NK1394SCN.AddReg]
HKR,,HardwareConfig,1,2
HKR,,DevLoader,,*NTKERN
HKR,,NTMPDriver,,"scsiscan.sys"
HKR,DeviceData,ICMProfile,1,0,0
HKR,,USDClass,,"{07C71AC0-FA90-11d3-B409-00C04F87578E}"
HKCR,CLSID\{07C71AC0-FA90-11d3-B409-00C04F87578E},,,"Nikon STI USD"
HKCR,CLSID\{07C71AC0-FA90-11d3-B409-00C04F87578E}\InProcServer32,,,%11%\NKSCNUSD.DLL
HKCR,CLSID\{07C71AC0-FA90-11d3-B409-00C04F87578E}\InProcServer32,ThreadingModel,,"Both"
[SourceDisksNames]
1=%DiskName%,,
[SourceDisksFiles]
NKSCNUSD.dll=1
[DestinationDirs]
NK1394SCN.CopyUSDFiles=11
[NK1394SCN.CopyUSDFiles]
NKSCNUSD.dll,,,32
;-----------------------------------------------------
[Strings]
Provider="steelchn@gmail.com"
Mfg="DIY Software"
DiskName="Nikon Scan 4 CD-ROM"
;========================= End of scanners.inf ===============================

Save the file. Turn on your scanner and connect it to your computer. Go to Window’s Control Panel and select System > Device Manager. On Windows 8 first follow the instructions at the end of this page which eventually take you to the Device Manager, too.
On Device Manager’s device list your scanner is located in the imaging devices category. The corresponding entry will be named “Firewire Scanner” or something like that. Right click this entry and select “Update Driver Software”. Next select “Browse My Computer” and specify the folder you created before. A warning message will be displayed which you will need to disregard, telling the system to go on with the installation. Afterwards your scanner should be listed under its correct name like “Nikon SUPER COOLSCAN 8000 ED”. When you start Nikon Scan 4.03 after doing this it will detect your scanner and you should be good to go.

boto and load autoscaling groups

In boto, get_all_groups has a max return of 100. to get past that, you use tokens:

asconn = boto.ec2.autoscale.connect_to_region(self.region_name)
# This will load all groups.
# Source: http://stackoverflow.com/questions/29317526/how-can-i-retrieve-more-than-50-autoscaling-groups-via-python-boto
all_groups = []
rs = asconn.get_all_groups()
all_groups.extend(rs)
while rs.next_token:
    rs = asconn.get_all_groups(next_token=rs.next_token)
    all_groups.extend(rs)
for asg in all_groups:
    print self.stack_name + " = " + asg.name

python commit and push to git in Jenkins

I’ve looked all over the internet and can’t find anything regarding pushing to a remote repo via python…. particularly in Jenkins where your upstream is not set.

So I finally found the only helpful link and it was saying: don’t use gitpython.

But after trying multiple methods, I finally got this working. Note: It uses a few args from Jenkins && the point of this script is nothing more than to modify a file and commit it. With this functionality, I can now do real work.

import git
import os
import time
import yaml
import sys
import re
from git import Repo
print os.environ["GIT_BRANCH"]
workspace=os.environ['WORKSPACE']
m = re.search("origin/(.*)", os.environ["GIT_BRANCH"])
if m:
    git_branch = m.group(1)
else:
    sys.exit("COULD NOT LOAD SOURCE BRANCH")
# UPDATE VERSION FILE
with open(workspace + '/deploy_automation/config/int/versions.yaml', 'r') as f:
    versions_yaml = yaml.load(f)
versions_yaml["a.component"] = time.time()
with open(workspace + '/deploy_automation/config/int/versions.yaml', 'w') as f:
    yaml.dump(versions_yaml, f, default_flow_style=False)
# OTHER WAY
git_repo = Repo(workspace + "/deploy_automation")
git_repo.git.status()
git_repo.git.add(workspace + '/deploy_automation/config/int/versions.yaml')
git_repo.git.config('--global', "user.name", "user name")
git_repo.git.config('--global', "user.email", "user@domain.com")
git_repo.git.status()
git_repo.git.commit(m=' DEPLOY SCRIPT Updating versions.yaml for ENV jamestest2 and Service test')
git_repo.git.push('--set-upstream', 'origin', git_branch)

					

Multiline find / replace

I need to configure Jenkins jobs, which are currently configured to run anywhere to work on a specific label. Sure I could do it via the gui but in a SOA, I don’t want to manually do this in 100+ jobs.
So the files currently has in it:

   </scm>
   <canRoam>true</canRoam>
   <disabled>false</disabled>

I want it to be:

   </scm>
   <canRoam>false</canRoam>
   <disabled>false</disabled>

I run:

server:~/jenkins/jobs> perl -pi -e 'BEGIN{undef $/;} s/<\/scm>.+?true<\/canRoam>/<\/scm>\nbuild<\/assignedNode>\nfalse<\/canRoam>/smg' app*/config.xml

Many thanks to aks and StackOverflow for the help

rename cmd on osx

One thing I missed when moving to osx was the rename cmd. Sure you can you mv but when I’m dealing with thousands of files, rename makes it much easier.

To get it on mac, all you need is

  1. Install Homebrew
  2. Install rename
    brew install rename 
    

That simple!!!

AWS / Ansible Dynamic Inventory

I’ve been working to manage dynamic inventory in AWS for Ansible deploys… then I came across this stack overflow link & ches’ answer.

Ansible looks for executables and flat files in a directory and merges their results.

=> tree inventory/staging
inventory/staging
-- base
-- ec2.ini
-- ec2.py
-- group_vars -> ../group_vars

The base file looks like:

=>  more inventory/staging/base
[localhost]
# I need to tell Ansible which Python on my system has boto for AWS
127.0.0.1 ansible_python_interpreter=/usr/local/bin/python

# The EC2 plugin will populate these groups, but we need to add empty entries
# here to make aliases for them below.
[tag_Stage_staging]
[tag_Role_webserver]

[staging:children]
tag_Stage_staging

[webservers:children]
tag_Role_webserver

You then just point to the directory for inventory:

$ ansible -i inventory/staging webservers -m ec2_facts
# OR
$ export ANSIBLE_HOSTS=inventory/staging
$ ansible webservers -m ec2_facts

AWS via Ansible – use private key

With AWS ssh, you need to use a private key. When working on a new script, I didn’t want to deal with my private account having a “build box” which was already on the VPC. So I was using my box & giving the destination a public IP. I know… totally insecure but considering I was killing the VM every few minutes I didn’t care.

So to call ansible-playbook & provide a private key:

ansible-playbook -i envs/localhost elasticsearch.yml -vvvv --private-key=~/.ssh/mykeyname.pem 

aws cmd line tool – use profiles

I’ve got a home account & a work account. I need to easily swap between the 2.
Add 2 sets of creds
~/.aws/credentials

[default]
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

[work]
aws_access_key_id=AKIAI44QH8DHBEXAMPLE
aws_secret_access_key=je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY

Add 2 sets of region / outputs
~/.aws/config

[default]
region=us-west-2
output=json

[profile work]
region=us-east-1
output=text

Then to use a profile:

export AWS_PROFILE=work

OR

aws ec2 describe-instances --profile work

SOURCE

Ubuntu – edit iptables

As a CentOS user, Ubuntu was driving me crazy with no /etc/sysconfig/iptables and this odd workaronud where you are to create multiple files to load on boot in order to save your iptables. Then I found iptables-persistent

  1. Install iptables-persistent
    root monitoring:~# apt-get install iptables-persistent
    
  2. Now configure your iptables (for v4… if using v6, replace end of filename)
    root monitoring:~# vi /etc/iptables/rules.v4
    

Now when I reboot, the appropriate rules are in place.

Monitor Disk I/O

[/share/MD0_DATA] # dstat -tdD total,md0 30
----system---- -dsk/total----dsk/md0--
  date/time   | read  writ: read  writ
25-02 15:06:03|  18M 2937k:  17M 2367k
25-02 15:06:33|  11M   11M:9976k 9446k
...

-t for timestamps
-d for disk statistics
-D to specify the exact devices to report
30 to average over 30 seconds. The display is updated every second, but only once per 30 seconds a new line will be started.

[/share/MD0_DATA] # iostat -x 1
                             extended device statistics                       
device mgr/s mgw/s    r/s    w/s    kr/s    kw/s   size queue   wait svc_t  %b 
sdx        0     0    0.0    0.0     1.6     0.0   74.9   0.0   13.9   7.6   0 
sda       25   124   35.5    4.9  3132.5   512.9   90.3   1.0   23.6   3.6  15 
sdb       25   123   33.6    4.5  3115.8   516.4   95.4   0.4   11.7   3.6  14 
sdc       25   123   35.3    5.0  3121.1   512.9   90.1   0.9   22.8   3.5  14 
sdd       25   123   33.4    4.5  3109.8   510.2   95.5   0.5   12.3   3.6  14 
sde       25   123   35.4    5.0  3122.5   513.0   90.1   0.9   21.6   3.0  12 
sdf       25   123   33.9    4.5  3111.8   510.2   94.3   0.4   10.3   3.0  11 
md9        0     0    0.1    0.0     1.5     0.1   17.9   0.0    0.0   0.0   0 
md13       0     0    2.1    1.8   123.9     7.2   34.0   0.0    0.0   0.0   0 
md6        0     0    0.0    0.2     0.2     0.8    4.0   0.0    0.0   0.0   0 
md0        0     0  334.2   52.8 18498.3  2479.4   54.2   0.0    0.0   0.0   0 
                             extended device statistics