Wednesday, May 14, 2014

Charity must begin at home

We have changed ourselves as a country and as a people when we think that the social safety net MUST come from government. When my grandparents came to Lynn in 1904 they came to a community that took them in and shared responsibility for them. If a kid was misbehaving, the first adult in the neighborhood to it would pass that information on to the parent. If someone was struggling their family was invited to dinner. Simple concepts that are rarely practiced any more.
Charity does more than help the recipient -- it integrates the giver into the community. We learn more about ourselves and our communities through our own acts of charity. In particular we learn that our society is not as hopeless as the doomsayers would have us believe. If we can all find a way to be a little more involved and have a closer relationship with our neighbors, we would find that we can solve more problems.
Sadly, some people would rather wash their hands of the responsibilities of humanity. When I hear people say "that's what I pay taxes for" as an excuse to look the other way -- it bothers me. There's a lot about our system that can be remedied if we can just work a little bit at being good towards each other and finding a way to be give of ourselves.
And that's what bothered me about this story. I think there is a concerted effort by some to make the social safety net be solely the responsibility of government. This doesn't work because government is whimsical. Today's charity is tomorrows pariah with a new majority in power. Republicans won't allow government funds to Democratic causes and vice versa.
But hopefully our hearts ARE constant. Where people want to step up and engage in charity, we should not punish them.

Friday, October 25, 2013

Public OpenPGP key of Daniel Fishman

Version: OpenPGP.js v.1.20130820


*** exported with ***P key of Daniel Fishman

Saturday, April 28, 2012

OSX single user repair permissions 10.6

After the Command-S startup, type the following on the command prompts, allowing time for each to do its thing:

/sbin/fsck -y<return> 
/sbin/mount -uw /<return> 
/sbin/autodiskmount -va<return> 

launchctl load /System/Library/LaunchDaemons/
/usr/sbin/diskutil repairPermissions / 

Thursday, March 08, 2012

mcp -- copying a file to multiple machines via scp

I have a series of 6 machines that I need to occasionally deploy the same file to in exactly the same place.  I got tired of it being such a pain so I wrote this little script I call  It's certainly easy enough for a shell script master to do this, but for me?  I struggled for 30 mins to get this right -- hopefully this saves you some pain.

I assume you have already passed your ssh key to the machines you want to connect to so you can scp without a password.  If not please read

You call with the absolute path to the file you want to copy, and it will copy it to exactly the same location on the target machine.

Put names of the machines (one per line) you want to update in the file hosts.txt

firstChar=`expr substr $1 1 1`
if [ -z $1 ]; then
        echo "usage mcp </absolute/path/to/file.txt>"
        exit 1
if [ $firstChar  != / ]; then
        echo "Must use absolute path"
        exit 1
for line in `cat hosts.txt`
 `scp $1 root@$line:$1`

improvement comments welcome

Monday, December 05, 2011

Using a Servlet to generate chart images for BIRT

I've been working with Google's chart tools -- specifically their Image Chart tools.  My problem -- I'm using BIRT as my PDF report engine, but I have a web interface.  I want the report to look the same on the web as it does in BIRT (which has it's own excellent native charting library).  I decided the easiest way is to use an
image tag, but I have the potential for copious data, so I have to use a POST instead of a GET.

Google lists an excellent hack using a form and an Iframe as a way to submit the post and that works for me from the web.   It does not work inside of BIRT -- because as far as I know there is no way to submit a form inside of a report.  Instead I decided to use an image tag which runs through a servlet I host.

So now I can write on my web page:

<img src="../chart/chart.png">

and I can include in a dynamic text in my BIRT report

"<img src='http://mywebserver/chart/chart.png'>"  //outside quotes required for BIRT dynamic text

And now I have the same chart in both!  Voila.


import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.Enumeration;
import java.util.Hashtable;

public class ChartServlet extends HttpServlet {

    public void service(HttpServletRequest request, HttpServletResponse response) {
        response.setHeader("content-type", "image/png");
        try {
            // Construct data
            Hashtable dataHash = new Hashtable();
            dataHash.put("cht", "lc");
            dataHash.put("chtt", "This is my chart");
            dataHash.put("chs", "600x300");
            dataHash.put("chxt", "x");
            dataHash.put("chd", "t:40,20,50,20,100");
            StringBuilder postBuffer = new StringBuilder();
            Enumeration enumeration = dataHash.keys();
            boolean first = true;
            while (enumeration.hasMoreElements()) {
                String key = (String) enumeration.nextElement();
                String value = (String) dataHash.get(key);
                String prefix = "&";
                if (first) {
                    prefix = "";
                    first = false;
                postBuffer.append(getURLPair(prefix, key, value));
            String params = postBuffer.toString();
            // Send data
            URL url = new URL("");
              //?chid=a"+String.valueOf(Math.random()).substring(2)); to avoid caching
            URLConnection conn = url.openConnection();
            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream(),"UTF-8");
          // Get the response and write it directly to your response
            IOUtils.copy(conn.getInputStream(), response.getOutputStream());
        } catch (Exception e) {

    public static String getURLPair(String prefix, String key, String value) {
        try {
            String parameterString = prefix + URLEncoder.encode(key, "UTF-8") + "=" 
            + URLEncoder.encode(value, "UTF-8");
return parameterString;
        } catch (UnsupportedEncodingException e) {
        return null;


Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License.

Sunday, August 21, 2011

Followup to the Integer toggle code

My good friend Greg mentioned that I should use bitwise operators to perform a toggle, as opposed to my earlier method of using integer math to manipulate the state.  I had not done that because the bitwise implementation is imho not comprehensible by a developer who does not have a CS degree.

As an example it is not at ALL clear to most people that ~2<<10 != ~(2<<10)

Although I suppose that's the point of a method name.

 * A simple way to implement a toggle switch using an integer to store the state
 * and bitwise operators to manipulate the toggle
 * @author Dan Fishman
 * This code released to the public under the CreativeCommons 3.0 license by
 * the author on 8/21/2011

public class TestToggle {

  public static int toggleState=0;
  public static void main(String argv[]){
      for(int x=0;x<32;x++){
        System.out.println(x+":"+Integer.toBinaryString(2 << x));
        System.out.println("isOn "+x+" == "+toggleIsOn(x));
        toggle (false,x);
        System.out.println("isOn "+x+" == "+toggleIsOn(x));
      //PAY ATTENTION TO THESE TWO LINES  order of operations can be tricky in bitwise
      // see

  * if onOff==true we set the value at pos == 1 aka on
  * else we set it to 0;
  * @param onOff
  * @param pos
 public static void toggle(boolean onOff, int pos){
         toggleState |= 2 << pos;
         toggleState &= ~(2<<pos);
 public static boolean toggleIsOn(int x){
     return (toggleState & 2<<x) == 2<<x;

Saturday, August 20, 2011

Using an integer to implement a binary toggle switch in Java

We were talking about a way to use an integer to indicate teh state of a series of switches.  e.g. if there were 5 switches and the first 3 were on we would say think of that as 11100, or 28

Not a bad method -- you can very quickly toggle switches on and off by calling

toggle(boolean on,int position)

and you can quickly check it the toggle at a position is on by calling

toggleIsOn(int position);

The code snippet is below, comments welcome.  you have to declare toggleState yourself of course...;

public int toggleState=0;

     * if onOff==true we set the value at pos == 1 aka on
     * else we set it to 0;
     * @param onOff
     * @param pos
    public void toggle(boolean onOff, int pos){
                //do nothing, already on
                //we want it on, and it is currently off
                //It's on, and we want it off
                //it's off and we want it off -- do nothing
    public boolean toggleIsOn(int pos){
        if(toggleState==null || toggleState < (2^pos)) return false;
        //divide toggle state
        int multiple=toggleState/(2^pos);
                //if the switch is on, multiple will be an odd number, otherwise it will be even.
        return multiple%2==1;