Skip to content

Python script for engineering format

21-Oct-11
# -*- coding: cp1252 -*-
from math import tan, pi, sqrt, log, floor

def eng(x, sigfigs=3):
    m = floor(log(x)/log(10)/3)*3
    LUT = {
       -18: "a",
       -15: "f",
       -12: "p",
       -9: "n",
       -6: "µ",
       -3: "m",
        0: "",
        3: "k",
        6: "M",
        9: "G"
    }
    return ("{0:.{1}g}{2}").format(x*10.0**(-m), sigfigs, LUT[m])

I’m not sure what grief the µ character is going to cause people. Feel free to change it to “u”.

DHCP trouble in DD-WRT due to broken dnsmasq

20-Oct-11

I’ve been debugging why my printer won’t receive an IP from my dd-wrt router. (This is a beta version of Buffalo’s branded dd-wrt firmware: DD-WRT v24SP2-EU-US (05/25/11) std – build 17135.) I actually “upgraded” to the beta version while debugging this problem. Originally, I had the release version of Buffalo’s DD-WRT.

Anyway, to summarize, it seems like using dnsmasq as the DHCP server breaks things. When I set it back, all my clients get DHCP licenses. I learned this the hard way. First, my printer wasn’t getting an IP. So, I finally gave it a static IP. Then, an Android phone wasn’t getting an IP. At that point, I started dhcpdump and started snooping. Basically, it’d get an “address not available” error. I finally traced it down to the setting for dnsmasq on the dd-wrt page. Once I chose the regualar DHCP server (udhcpd) rather than dnsmasq, everything worked well:

Turn off "Use dnsmasq as DHCP"

 

My dd-wrt crontab

12-Oct-11

here it is:

0       0       *       *       *       root    [ ! -f /tmp/wrtbwmon ] && wget "http://pastebin.ca/raw/2088536" -O /tmp/wrtbwmon && sed -i -e"s/.$//" /tmp/wrtbwmon && chmod +x /tmp/wrtbwmon
*/5     *       *       *       *       root    /tmp/wrtbwmon setup br0
*/30    0-3     *       *       *       root    /tmp/wrtbwmon update /tmp/usage.db peak
*/30,59 4-8     *       *       *       root    /tmp/wrtbwmon update /tmp/usage.db offpeak
*/30    9-23    *       *       *       root    /tmp/wrtbwmon update /tmp/usage.db peak
45      */2     *       *       *       root    /tmp/wrtbwmon publish /tmp/usage.db /tmp/www/usage.htm
0       0       *       *       *       root    [ ! -f /tmp/ct2htm ] && wget http://pastebin.ca/raw/2089248 -O /tmp/ct2htm && sed -i -e"s/.$//" /tmp/ct2htm && chmod +x /tmp/ct2htm
*       *       *       *       *       root    /tmp/ct2htm

Couple of customizations here. First, I’ve modified the wrtbmon script to not rely on sort, since it doesn’t exist in Buffalo’s DD-WRT. Also, I’ve set up a small script to format ip_conntrack as HTML. This is so I can keep tabs to see if my QoS settings are working.

HP L7600/L7650 and Samba/FreeBSD

02-Oct-11

This all-in-one printer can scan to a Windows share. I have a Windows share hosted by Samba on FreeBSD.

Unfortunately, the printer/scanner intermittently (and pretty often) says it can’t find my FreeBSD machine when I–or more importantly my wife tries to scan a document.

I went pretty deep on this and took a packet capture:

More…

Fixing CrashPlan (in the presence of native JDK/JRE)

14-Sep-11

I recently installed subsonic, which has a Java dependency. The www/subsonic port installed Java.

Unfortunately, this (or something else I did) broke CrashPlan (which uses the Linux Java in the java/linux-sun-jre16 port).

I had to take a few unexpected steps to fix this.
More…

ZFS / NFSv4 ACL’s for a public Samba share

27-Aug-11

I’ve finally taken the time to figure things out step-by-step. NFSv4 ACL’s, which are supported by ZFS on FreeBSD (and Solaris) are pretty cool. However, I’ve never really understand how they work. By taking the time to use the command-line, I’ve figured out what I think is a good approach for a public share–one where I store old Recorded TV shows.

More…

Samba and ZFS (NFSv4) ACL settings for FreeBSD

27-Apr-11

My latest security schemees that I’ve mapped the Samba guest user to a new user “samba_guest”. I’ve made nobody the owner of public shares. I’ve removed the allow settings for the “nobody” user. I then enable everyone to read:

owner@:--------------:------:deny
group@:-w-p----------:------:deny
group@:r-x-----------:------:allow
everyone@:----Dd-A-W-Co-:f-----:deny
everyone@:rwxp--a-R-c--s:-d----:allow

Note that I’ve set up Samba with the ZFS ACL module. For each share, I’ve added the following entries:

  vfs objects = zfsacl
  nfs4:mode = special
  nfs4:acedup = merge
  nfs4:chown = yes

Crashplan running on FreeBSD

07-Apr-11


Just gathering bits of information on how to get this done:

The first set of instructions (for FreeBSD 7.x) was here:CrashPlan on FreeBSD HOWTO

This didn’t work that well on FreeBSD 8.x. There was some problem with epoll. The breakthrough came from Aaron here:

Add -Djava.nio.channels.spi.SelectorProvider=sun.nio.ch.PollSelectorProvider to the bin/run.conf for the engine.

Finally, here’s an rc.d startup script for Crashplan running on FreeBSD – 1st Byte Solutions.

When I tried starting crashplan manually, it initially had a hard time finding my /tank mount point. Seems like linux compat on FreeBSD didn’t want to mount it. I played around with a bunch of stuff, including trying out nullfs (I didn’t have that kernel module built, so I had to rebuild it). I’m not sure what I did (maybe built the nullfs module) but eventually, it was able to find my /tank mount point without doing anything fancy.

graphic of selecting files to upload, including those in /tank ZFS pool

Putting freebsd /tmp and /var on a memory disk (md)

14-Feb-11

I’ve installed a FreeBSD system using gmirror onto a couple of USB drives. I’ve noticed that there’s a considerable lag when I’m doing certain things (running top for example). I’ve narrowed it down to the /tmp and /var file systems. These two file systems get written to often during normal system operation. I’ve recently aleviated this problem using the md facility–which creates a ramdisk.

Since I’m using USB drives for the root (a d the default /tmp and /var), the write latency is higher than read latency. In addition, gmirror exacerbates this tendency.
More…

Kingston DataTraveler 101 Gen 2 4GB USB 2.0 Flash Drive Speed Test

14-Feb-11

Testing these drives: Newegg.com – Kingston DataTraveler 101 Gen 2 4GB USB 2.0 Flash Drive (Cyan) Model DT101G2/4GBZ

I got them free with some RAM. Here are the results:


-----------------------------------------------------------------------
CrystalDiskMark 3.0.1 (C) 2007-2010 hiyohiyo
                           Crystal Dew World : http://crystalmark.info/
-----------------------------------------------------------------------
* MB/s = 1,000,000 byte/s [SATA/300 = 300,000,000 byte/s]

           Sequential Read :    22.563 MB/s
          Sequential Write :     6.475 MB/s
         Random Read 512KB :    23.013 MB/s
        Random Write 512KB :     0.628 MB/s
    Random Read 4KB (QD=1) :     5.609 MB/s [  1369.3 IOPS]
   Random Write 4KB (QD=1) :     0.005 MB/s [     1.3 IOPS]
   Random Read 4KB (QD=32) :     6.126 MB/s [  1495.6 IOPS]
  Random Write 4KB (QD=32) :     0.006 MB/s [     1.5 IOPS]

  Test : 1000 MB [F: 29.4% (1099.7/3737.0 MB)] (x9)
  Date : 2011/02/09 2:02:07
    OS : Windows 7 Ultimate Edition [6.1 Build 7600] (x86)