Live data from Hacker News

Show HN: I made a web-based notepad with a built in unit calculator

numpad.io

171–180 of 246 posts

Re: Show HN: I made a web-based notepad with a built in unit calculator

#172

Earlier quoted context omitted.

And `mpg`/`l/100k` please!

I've avoided adding mpg because the UK and US disagree on what a gallon is and mpUKg/mpUSg is not very nice to look at. You can write "miles per gallon" or "miles per US gallon" because per is the same as the "/" operator, and you can sort of do "L/100km" but you can't convert to it. I'll have to think some more about this one.

I think I see where you’re going. I’d be comfortable with “litres per hundred kilometres” if that’s possible and especially if there was a “did you mean” suggestion prompt

Re: Show HN: I made a web-based notepad with a built in unit calculator

#173
post #149
post #21

Nice - I'll give it props for: > 1 metre + 8 chain = 161.9344 m > 1 tonne + 1 short ton = 1.90718474 t > 1 tonne + 1 long ton = 2.0160469 t and give it a pass for not supporting pre 1963 UK | US historic weights and measures .. that's getting into a pretty specific use case where Standards nerds like to have a clear display of what conversion factors are in play and what provenance those factors have. Time Zone suppo…

Didn't tell me how much 8 gills[1] would be in liters (about 1) [1] https://en.wikipedia.org/wiki/Gill_(unit)

I was disappointed it couldn't convert "1 furlong / 1 fortnight in mph", but this was successful:

> 14 furlongs / 2 weeks in mph [0.0052083333 mph]

Re: Show HN: I made a web-based notepad with a built in unit calculator

#174

I like how you are using a Gist for the exchange rates ( https://gist.github.com/tonyonodi/e154f529180b1f0f475966d333... ), do you have a GitHub action setup to automatically update that?

Impressed you found that. I don't have anything set up to automatically update it currently, but I do have an intention to have something set up to automatically update it.

Btw the conversions don't seem to work for me:

> 100 eur to usd $-100.63 > 100 usd to eur Incompatible units

Re: Show HN: I made a web-based notepad with a built in unit calculator

#176

Earlier quoted context omitted.

Yeah, honestly this has been annoying me too, I just haven't got around to fixing it. It's using CodeMirror 6 as the editor, the author said he deliberately made this version not "break" the default tab behaviour, which I think is understandable as a library author, but that makes it my job to fix!

I thought CM had some example code on how to override the tab behaviour. Might be worth checking out as I agree it sucks to not have tab = indent 4 spaces

2 spaces!

(ducks) (but srsly)

Re: Show HN: I made a web-based notepad with a built in unit calculator

#177

Super cool. I wish this was open source so I could see how you did some things, but I understand you've decided to keep it closed. Just to satisfy my curiosity, would you mind sharing how you did parsing at a high level? Did you use some publicly available parser/lexer or did you just implement pattern matching yourself with something like regex or other token splitting measures?

I'm very glad you asked. I wrote my own parser combinator library in TypeScript partly based on eulalie[0], so it doesn't have a separate lexer and parser and doesn't rely heavily on regexes (though it does use them to do things like match a single alphanumeric character). I plan on open sourcing this library one day once I can tidy up the API because I think it would be useful to other people.

But to give you an idea of what that all looks like this is the code for the parser that parses the "as a % of" operator:

  append(
    string("as"),
    oneOrMore(space),
    optional(append(string("a"), oneOrMore(space))),
    percentSymbol,
    oneOrMore(space),
    string("of")
  )
[0] https://github.com/bodil/eulalie

Re: Show HN: I made a web-based notepad with a built in unit calculator

#179
post #164

Super cool. I wish this was open source so I could see how you did some things, but I understand you've decided to keep it closed. Just to satisfy my curiosity, would you mind sharing how you did parsing at a high level? Did you use some publicly available parser/lexer or did you just implement pattern matching yourself with something like regex or other token splitting measures?

I've found that a super simple way to parse basic expressions is a recursive descent parser. It is very simple to implement. No need to to break into tokenizer/parser, no need to generate an AST, just evaluate the expression while parsing.

Do you have an example of a simple parser like that?
Post reply on HN