#garfield Logs

Jun 01 2025

#garfield Calendar

12:19 AM rue_mohr: Rue: Fridge
12:37 AM rue_mohr: Rue: Len
12:37 AM rue_mohr: Rue: driveway bell
03:35 PM aandrew: rue_mohr: http://www.mixdown.ca/dump/resistor-finder/index.html
03:35 PM aandrew: also http://www.mixdown.ca/dump/resistor-finder.zip
03:40 PM rue_shop2: er, I needed it as a C libary
03:40 PM rue_shop2: got it tho
03:41 PM rue_shop2: https://paste.debian.net/1377687/
03:42 PM rue_shop2: hehe, mines faster...
03:43 PM rue_shop2: funny thing, the code chatgpt gave me was almost identicle
03:44 PM rue_shop2: a) if the values are sorted, you dont have to search the whole array
03:44 PM rue_shop2: b) if you give it 999.9 it will come back with 820.0 not 1000,
03:45 PM rue_shop2: c) eek loops in loops!
03:45 PM aandrew: mine does it right :-)
03:45 PM aandrew: 999.9 E24 returns 1k
03:45 PM rue_shop2: huh, but it only searches the decade....
03:46 PM rue_shop2: did you have an ai help you or did chatgpt pull your code off the internet somewhere?
03:47 PM rue_shop2: cause that findclosest is almost EXACTLY what it gave me in C
03:47 PM rue_shop2: oh, I think I see the difference, you build out an array of every value
03:48 PM rue_shop2: hmm
03:53 PM aandrew: well I don't, perplexity did
03:54 PM aandrew: but you should perhaps check if the desired value is larger or smaller than the largest/smallest value in the series and repeat for the next-series to see if it's closer
03:54 PM aandrew: e.g. 999.9 > 820 so check 0k999 as well
04:00 PM aandrew: https://pastebin.com/354fRqEE is the C version it came up with
04:02 PM aandrew: it's a little dumb, like you said if the tables are sorted it doesn't have to search everything) and it's also going through ALL the decades instead of just the ones it needs (if needed)
04:02 PM aandrew: but it hardly matters, you're not exactly going to be running this for gajillions of resistors
04:05 PM rue_mohr: when I'm making a library for low level like that I prefer it to be fast just incase it ends up in a warhunt loop
04:05 PM rue_mohr: (outside the library)
04:05 PM rue_mohr: my SIprint library needs some work tho, 1.000mF
04:05 PM rue_mohr: ...
04:06 PM rue_mohr: suppose I could have it trim some zeros
04:09 PM rue_mohr: ooo %g
04:09 PM rue_mohr: oo yea
04:18 PM aandrew: I believe that's called early optimization. We all fall victim to it at times
04:19 PM rue_mohr: so
04:19 PM rue_mohr: in the formulas in the book
04:19 PM rue_mohr: there was something called "load current"
04:19 PM aandrew: I keep meaning to reimplement the TI resistor divider calculator https://www.ti.com/download/kbase/volt/volt_div3.htm to be command line and then add simple series and parallel calculator too
04:19 PM rue_mohr: which... is not calculating as the collector resistor
04:20 PM rue_mohr: I have written those in C
04:20 PM rue_mohr: I do sort of wish I'd done it all in js
04:20 PM rue_mohr: have a web page bank
04:20 PM aandrew: I don't know much about analog oscillators, but I undertand you're well versed in them iwth your various circuits over the years
04:20 PM rue_mohr: I got these formulas from a book
04:21 PM aandrew: yeah js is fine especially since you can just run them from the command line anyway
04:21 PM rue_mohr: but I'm highly amused about my little C program generating a full on svg schematic
04:21 PM rue_mohr: it took some work to figure out how to do the token replacments in C
04:24 PM aandrew: yeah that is slick
04:25 PM rue_mohr: void replaceToken(char ** buffer, char * token, char * value ){
04:25 PM rue_mohr: char * tokpos;
04:25 PM rue_mohr: tokpos = strstr(*buffer, token);
04:25 PM rue_mohr: if (tokpos) {
04:25 PM rue_mohr: memmove(tokpos, tokpos+(strlen(token)), strlen(tokpos+strlen(token))+1 ); // delete token
04:25 PM rue_mohr: astrinss(buffer, value, tokpos-(*buffer)); // insert value
04:25 PM rue_mohr: }
04:25 PM rue_mohr: }
04:25 PM aandrew: I felt the same way when I managed to get a program to properly create cue points in wav files that ocenaudio could understand
04:25 PM rue_mohr: ^^ that will probably get added to my custom generic library as a search-replace (maybe clean it up a bit)
04:26 PM aandrew: doesn't that assume that token is always smaller than avlue?
04:26 PM rue_mohr: oh, a str ins s is one of my functions
04:26 PM rue_mohr: it finds, collapses, then inserts
04:26 PM rue_mohr: astrinss uses asprintf
04:28 PM rue_mohr: int astrinss(char ** dst, const char * ins, unsigned long pos) {
04:28 PM rue_mohr: char * temp;
04:28 PM rue_mohr: int rv;
04:28 PM rue_mohr:
04:28 PM rue_mohr: if (pos > strlen(*dst)) return -1;
04:28 PM rue_mohr:
04:28 PM aandrew: ok, I see the memmove is basically moving the rest of the string from B to A: [ string string string A ]...stuff...[ B rest of string string string ]
04:28 PM rue_mohr: if ( (rv = asprintf(&temp, "%.*s%s%s", pos, *dst, ins, *dst+pos)) != -1) {
04:28 PM rue_mohr: free(*dst);
04:28 PM rue_mohr: *dst = temp;
04:28 PM rue_mohr: return rv;
04:28 PM rue_mohr: }
04:28 PM rue_mohr: return -1;
04:28 PM rue_mohr: }
04:29 PM aandrew: ah yeah I see now. memmove gets rid of a bit, astrinss allocates and adds a bit at a given position, returning the new buffer
04:29 PM rue_mohr: yup
04:29 PM rue_mohr: it was quicker than ideal :]
04:32 PM aandrew: it feels so dirty but I completely understand
04:33 PM rue_mohr: asprintf is amazing :]
04:33 PM rue_mohr: I also need to mod that token replace to keep going and replace them all
04:33 PM rue_mohr: later
07:34 PM rue_shop2: bugger, I bumped the reset button on my main machine
07:35 PM rue_shop2: gonna take ages to put it all back
07:44 PM Tom_L: shoulda hit save first
07:48 PM rue_shop2: I wont have lost anything important, but its annoying to lose the uptime and the shells I was using to remind me of projects to finish
07:48 PM rue_shop2: I keep some junk in /tmp, but nothing important