Sunday, April 2, 2023

rsync using old ssh protocol

So, after I upgraded my Mac, I lost the ability to easily ssh into my old server, which I guess only supports ssh-rsa and ssh-dss (The server is overdue for an update but is still getting security patches so my admins recommend putting off the inevitably painful upgrade)

ssh -oHostKeyAlgorithms=+ssh-rsa

works as a replacement for my ssh command as does its equivalent for sftp, but I guess rsync is more something that piggybacks on ssh? So the equivalent command (well the alias I'm using for it) is

alias rsyncfix="rsync -e 'ssh -oHostKeyAlgorithms=+ssh-rsa'"

Sigh. I really am old school with so much. I just like folders of folders with my files that I can backup manually, and that goes for my personal data as well as what I have going on my server. I just like seeing bits and bytes on hardware that I control, not somewhere out there in cloudspace though I know there are advantages...

And while we're talking old unix command, here's my old favorite disk-usage du command:

du -hs * | sort -hr

Just shows you the summary of each top level folder (or file), with human readable labels (ie. M, G etc not just bytes) and sorted biggest to least.

Thursday, March 30, 2023

programming via ChatGPT

I was laughing at the javascript  code I made in 2005 to show you what day of the week a date fell on for a series of years. That was before jQuery, but I'm not sure I was following best practices then...

I thought I'd rewrite with a better visual display, giving a sense of how the day of the week changes. And I thought I would see if ChatGPT was up for the challenge.

At first I thought I'd just recreate the old UI:

please give me the html and js with a select for month, and a selector for day of month, and an input for starting year and an input for ending year, and a button the selectors are prepopulated with today's date the starting year is 50 years ago and the ending year is 50 years in the future. when you click the button a div is populated with that date for each year in the range and what day of the week the day is for that year

And frankly, ChatGPT pretty much nailed it - I immediately had a better version of my 2005 code. 

But for some reason the inputs were hardcoded in based on right now, when the page is written, so I asked

great work! could you make it so that the starting and ending year fields are populated with 50 years before and 50 years after the date when the page is loaded?

And that was an easy enough fix. So I programmed via describing what I envisioned for the new version:

great work again! could you change it so that "date-container" is actually a table. The top row should be a row of header elements. The firsts header column should say "Year". There should be 7 more columns, each with the three letter version of the day of the week. Then each row beneath, the left column should be the year, and the corresponding column for what day of the week that date is on should be marked with the first initial of that day of the week and the background color should be green
I am truly impressed with the output of that. There were some quirks; the script part got cut off so I had to ask for it to finish (not sure if that's just a quirk of the free version or what), not sure why it went with 100% width for the table or made the "Year" header element left aligned, etc.

I asked for a few more changes, but was getting the "cut off" problem a bit more (despite it electing to start putting the script into a separate file) and decided to make the finishing touches on my own, including highlighting the current year, and automatically filling the table on load...

I even asked it for some aesthetic help when "cyan" wasn't quite what I wanted for the current year highlight:
for the css color "green", what would be the hex code for softer shade of blue that would complement it well?

A softer shade of blue that would complement green could be a pastel or muted blue color, such as a light or medium shade of sky blue. One possible hex code for this color is #87CEEB, which is a pale blue color that could work well with green. However, color choice is subjective and dependent on the specific design and context, so you may want to experiment with different shades of blue to find the one that best complements your specific shade of green.
Yup!

Stephen Wolfram has a pretty good explanation about how ChatGPT works. And it's amazing to think that this is just hyperfancy "markov chains" thinking of what the a likely next word to say might be.  I feel there is true intelligence in embodying those conceptual connections that must be there for it to be making the minor changes requested - like most often it's not ripping off any one other program. 

On the other hand, sometimes the fact that it's not doing proper full mental modeling of things will come up... but, wow. Impressive and alarming! Both in terms of what it can do and what that means for people who have made their living programming, and where it will have some surprising limitations, like how it started hardcoding the start and end years.

Wednesday, March 29, 2023

pure CSS recreating a focus box (that doesn't touch the content)

Sigh. One of those times when maybe if my googling mojo had been better I could have saved myself some time. Here's the codepen I made to learn about the following...

We are messing around with divs including some that might be able to have focus, and I got to wondering what options were for making a focus box, or something similar for hover.

One option is to make a border:
.card.border:hover {
  border:  8px solid blue;
}

the trouble is that might mess up your alignment, cause some shifting, unless it has a border in its non-active mode as well, ala
.card.border {
  border:  8px solid blue;
}

But that might distort things anyway. So it might be safer to use a boxshadow, possibly making sure the fuzz ratio is 0 (or not, if you want a less harsh look)

.card.boxshadow:hover {
 box-shadow: 0 0 0 8px red;
}

 But what if you don't a frame, rather than a border per se? Like one that isn't touching the content, yet doesn't require changes to the content in the layout, or risk moving things around?

I came up with this to give a nice such frame on hover:

.card.before {
  position:relative;
}
.card.before:hover::before {
  border:  4px solid red;
  content:"";
  position: absolute;
  top:-20%;
  bottom:-20%;
  left:-20%;
  right:-20%;
}

Position:relative was a little awkard...

But there is of course a simpler solution - I had missed the simple "outline" property, which when combined with "outline-offset" gave me just the look I was thinking of:

.card.outline:hover{
  outline: 4px solid blue;
  outline-offset:8px;
}

(outline-offset supported in most things but IE)



Monday, March 27, 2023

timezone madness

I live in Boston, MA - I have one coworker in Houston, and then others in Amsterdam and Belgium (same timezone) Recently I've been enjoying Steve Foster's Menu World Time, which can place 2 economical clocks (along with daylight icons) a polite distance from my personal time:

So for the last 2 weeks, USA went to DST but Europe hadn't, so the daily morning standup was a blesséd hour later.

It got me thinking how Menu World Time had to track that kind of shift, and by coincidence a Slack community I'm on John C wrote:

things i've started seeing now that i'm deeper into the horror of open source distro world:
the absolute chaos that is the `tzdata` package during the twice yearly time transitions. For instance, Lebanon appears to have reinstated Daylight Saving Time after transitioning

Lebanon's government reinstates daylight saving time effective midnight on Wednesday-Thursday


What a mess! A lot of assumptions a programmer might make - like "a day has 24 hours" - definitely will be challenged at some point or another. (Shades of the old Y2K problem...)

Wednesday, March 22, 2023

the software engineer is dead! (?) long live the software developer!

On a Slack community I frequent, someone linked The Death of Software Engineering. Here was my response:

  1. I'm trying to think about where my struggle with learning and finding a new deployment paradigm for web apps fits in. Like my flow hasn't changed much since the late 90s, a quarter century - make interactive website/apps by writing scripts that run under apache on a server I pay someone else to admin. Its gone from Perl CGI to PHP, the server is now a private VPS, and the front ends might have more JS flavoring but the core is the same. I do feel there's a small legion of folks more fluent in deployment... though at some point (and this might be what keeps me stuck) it's a business thing. I have fixed costs with my setup in a way I might not if I experimented with more modern approaches
  2. The way that article conflates "OOP" and "Reusable Code" is weird. Maybe I'm channeling the old Object-Oriented Programming Oversold guy - but I don't see why the two conflated. At least in the UI world, the more interesting form of reusable code is the tendency to say "there's an npm module for that!" and taking on lots and lots of libraries even when in some of the cases it might be more expedient to roll a bit more of your own functionality...


Friday, March 17, 2023

typescript, plus and minuses

 I'm trying to make more peace with TypeScript, since that where things seem to be moving. Learning and Using TypeScript as an App Dev and a Library Maintainer was a good piece. Definitely pro-TS, but admitting some of the challenges, and not worth true fanaticism.

From that page:

  • Pros 👍:
    • Documentation: static types tell devs what variables look like quickly - especially valuable when working with unfamiliar code
    • Compile-time errors: common issues like typos or undefined values can be caught immediately, rather than at runtime; compiler prevents passing invalid values
    • Intellisense: type declarations allow IDEs to provide proper autocompletion and type information when writing code
    • Refactoring: can confidently rename / delete / extract code, rather than searching and "hope I found all the uses"
    • Long-term maintainability: better codebase information for future developers who may rotate on and off the project
    • Code Quality: doesn't replace unit tests, but can help minimize errors
    • Library Support: most common 3rd-party libs either ship typings, or community has created their own
  • Cons 👎:
    • Learning Curve: additional syntax and concepts take time to understand, on top of knowing plain JS by itself
    • Time to Write Code: literally more code to write out than just plain JS
    • Difficulties Typing Dynamic JS: can be difficult to come up with good static types for highly dynamic JS behavior
    • Inconsistent/Missing Library Types: not all libs have typings, and quality can vary
    • Compilation Time: TS usage can slow down build times
    • Over-Emphasis on Type Coverage: some TS users spend too much time trying to achieve "100% perfect static type coverage" of an entire codebase, leading to bizarrely complex types

Wednesday, March 15, 2023

safely walking down a tree structure via reduce

 At work we have theme files, so you might have a button or something that will look for its color, say in something like this: 

theme["button"]["large"]["primary"]["backgroundColor"]; 

so if you codify that as 

theme[componentName][size][type].backgroundColor 

it might blow up if part is missing... so you can defensively code it like 

theme?.[componentName]?.[size]?.[type]?.backgroundColor

But I wanted to print out more diagnostic information, not just safely null out... here's the content of the  codepen I came up with, which lets you call something like

getRootNode(theme,componentName,size,type,backgroundColor);

Here's the codepen code:

const getRootNode = (theme,...keys) => {
    const foundNode = keys.reduce(
      (node, key)=>{
        return node ? node[key] : null;
      }, theme);
    if(! foundNode) {
      console.log(`Could not find rootNode for ${keys}`);
      console.log(theme);
    }
    return foundNode;
}

const tree = {
  apple:{
    red:{},
    green:
      { taste: 'tart'}
  },
  banana:{
  },
  pear:{
    
  }
};
console.log('got');
console.log(getRootNode(tree,'apple','green', 'taste'));

It walks down the theme tree, but if there's no content anywhere along the line it calmly complains and returns null.

FOLLOWUP: I'm having some trouble selling my coworkers on this, they like the elegance/transparency of the chain syntax vs an arbitrary helper function. They also questioned the efficiency, so I wrote up a stopwatch function:

console.time();
for (let i = 0; i < 100000; i++) {
  const foo = getNodeInTheme(props.theme,"Badge",props.variant,props.size,props.color);
}
console.timeEnd();
console.time();
for (let i = 0; i < 100000; i++) {
  const bar = props.theme.Badge![props.variant!][props.size!][props.color!]
}
console.timeEnd();

Results: 

default: 18.383056640625 ms default: 1.559814453125 ms

And yeah, technically it's like 10 times slower, but 10,000 calls is still only 20 milliseconds, which is 0.02 seconds.  And that's for a LOT of calls.

Heh. Reminds me of BASIC that lacked a "SLEEP" command so you'd write "do-nothing" FOR...NEXT loops. And they weren't superfast!