Monday, January 15, 2018

automatically building when saving on mac

Playing with Batari BASIC, I thought it would be great to be able to run the build shell command every time I saved.

"fswatch" had lots of Google juice, but I couldn't get the xargs part to work.

filewatcher seemed a lot more straightforward.

I suppose I already had Ruby and RubyGems on my system (one of the weird things about having an old laptop, especially one that used to be a work machine, is that you lose track of what comes preinstalled and what was there from some previous task)

I had to
sudo gem install filewatcher
and then my command (run in the work folder) was something like

filewatcher '*bas' '2600basic.sh $FILENAME'

Easy-peasy!

Saturday, January 13, 2018

bad artists copy (and make animated gifs in imagemagick)

This morning I made the animation you see to the right - actually there's a mildly interactive p5.js app badartistscopy.

It might seem mildly interesting, but ultimately is far less cool than the inspiration, Line Girl, by Low Sugar Eye Candy who seems to have a lot of experience playing with "Girl with the Pearl Earring"

I haven't done much image processing in Processing or P5 - in p5, it is hella slow... watching it loop through and grab each pixel from the image felt like watching a BASIC program on a Commodore 64. I ended up having to take have a variable and just sample every "X" pixels.

I snagged an in-progress version and called it a prototype and it hints at how it's all done - I go through and take an RGB sample, and then average it to get a gray tone. Each particle then looks at the gray value closest to under it, and then one next to, and the bigger the contrast, the "slower" it goes (by adding less to its x position)

I don't think the original Line Girl is doing that much different - just some better choices with how particles are connected, and then tweaking some values (along with better raw source material)

I was surprised at how easily it loops - a ten frame animated GIF captures it. I recorded ten frames from the middle of the animation. At first I used the EZGif site, but I could have just used ImageMagick: convert -loop 0 *png run.gif

Thursday, January 11, 2018

mac hack howto: add number captions to series of images and make PDF via p5 and preview

For a reading group I had made a series of book-excerpt screenshots.

For ease of distribution, I knew I could open all the files in Mac's "Preview", then go to File | Print then "Save as PDF" in the PDF dropdown in the lower left of the dialog.

Having done that, I realized that it would be easier to talk about the pages if they were numbered. I went to my P5 boilerplate page and then made the code that follows.

I put all the images in a directory called "rightraw/" in the same folder as the p5 html. I couldn't dig up an easy way of reading the folder contents, so I went to the image directory and did a
ls *png > ../files.txt

(To load the page I had to run a baby webserver, like it says on the boilerplate page, otherwise the script can't load the files)

So nothing is rocketscience about this hack but I was pleased I was able to get it done and redo the Preview PDF trick before having to head out for the day. Some folks might get adept with ImageMagick or Photoshop macros or whatever, but p5 is a pretty good go-to for me.


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>addcaptions</title>
<script src="p5.js"></script>
<script>
var counter = 0;    
var files;
var fileprefix = 'rightraw/';
function setup(){
    var canvas = createCanvas(500, 500);
    canvas.parent("canvasParent");
    loadStrings("files.txt",kickOff);
    
};
function draw(){
    noLoop();
}
function kickOff(s){
    files = s;
    procNextImage();
}
function procNextImage(){
    if(counter >= files.length) return;
    loadImage(fileprefix+files[counter],showPic);
    counter++;
}

function showPic(img){
    resizeCanvas(img.width,img.height);
    image(img,0,0);
    text(""+counter,20,20);
    draw();
    saveCanvas(counter+".png");
    procNextImage();
}
</script>
</head>
<body>
  <div id="canvasParent"></div>
</body>

</html>

Wednesday, January 10, 2018

npm and new cities for trojan horses

I’m harvesting credit card numbers and passwords from your site. Here’s how. is an all-too-plausible sounding way credit card stealing code could be inserted into a popular site; the tl;dr is "reasonably clever code to steal from typically named fields inserted as a npm dependency utility for a framework, with a few other masking techniques applied".

The person who posted it at work mentioned its similarity to Reflections on Trusting Trust, a seminal ACM piece by Ken Thompson - how a compiler could be warped to detect login-program-looking C code and produce a binary with a gaping security hole.

Because I find writing simple code to do simple things - even when it is code I've basically written before - often more satisfying than learning how to use someone else's code to do the same thing, I'm at bad risk for NIH (Not-Invented-Here) syndrome, where I say "Make Vs Buy? Let's Make!" as a kneejerk response. But with links like that first one, and the story where removal of an 11-line "left-padding" module broke the build for a thousand places... I have mixed feelings about my own biases being confirmed that way.

Sunday, December 31, 2017

=== update

I updated my old Triple Equals Overrated ramble with a long postscript... while I'm not suggesting changing === as default for my company, or even the received wisdom of "avoid type coercion for comparisons), the people who like double equals aren't JUST dunderheaded cavepeople...

Thursday, December 28, 2017

Monday, December 25, 2017

pretty print json from unix shell

I've been digging using little .json files on the filesystem as a kind of DIY NoSQL database, but they're not always pretty to look at. Was looking for a pretty printer for 'em, thought I might have to do something in node or python but "json_pp" is already there in my Mac Terminal. The only weird thing is it only seems to read from STDIN (not from a file) so you have to do
json_pp < SOMEFILE.json