frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Show HN: Moon Phase Algorithms for C, Lua, Awk, JavaScript, etc.

https://github.com/oliverkwebb/moonphase
66•oliverkwebb•1d ago

Comments

ericpruitt•1d ago
I adapted the same moonphase logic for the status line program I use with dwm. Did you run into any discrepancies with using January 0 vs December 31st? Some of the translations of Walker's as noted in my comment at https://github.com/ericpruitt/emus/blob/ea059239845ee6d57614... seem to produce differing results.
oliverkwebb•1d ago
This discrepancy with time is explained in the book the algorithm is based on (Practical Astronomy with Your Calculator, which also does a good job explaining a ton of other ideas and models in astronomical calculation).

January 0th makes sense because a year starts on January 1st. You count days of the year from 1 instead of from 0. So if we are going by the day of the year, day 1 of the year should be Jan1, the consequence of this being that Jan0 exists and is Dec31 of the prev year.

I originally got into this because of my status bar on i3, hacking together C code from moontool into https://github.com/oliverkwebb/moontool about a year back.

rybosome•1d ago
Fun! From the repo[0]:

> Your function must be self-contained, such that someone could copy-paste it into their code and not get an error. It also must not effect the environment outside it if at all possible (no #define or mutating globals). It must be as "pure" and self-contained as the language will allow.

This is an interesting restriction, actually, with respect to style. The “natural” way I would program such an algorithm certainly doesn’t adhere to this requirement.

Producing functions that are still correct, idiomatic and legible while producing minimal changes to environment or state requires a non-beginners understanding of the runtime nature of the language.

[0]: https://github.com/oliverkwebb/moonphase?tab=readme-ov-file#...

danparsonson•1d ago
Could you elaborate on this? Maybe an example of what you mean?
oliverkwebb•1d ago
This is also interesting for speed, The algorithms ran by all the impls are identical, but sacrificing speed for cleanliness and adherence to spirit is done regularly.

Without having actually measured, the rust impl probably runs faster than the C impl, but that's not because rust is "faster" than C. That's because I used a closure with one call to floor() for modulus in rust, whilst in C I did 2 fmod()'s to get it because the alternative would've been to make the code unreadable or add a second function/macro (although thinking about it now, undef does exist...)

blululu•1d ago
This is really nice. My initial thought was "why just divide the time interval since the Unix Epoch by the synodic period of the moon". Turns out the moon's phase is a bit more complicated than that. https://en.wikipedia.org/wiki/Lunar_phase#Calculating_phase
madcaptenor•1d ago
That said, this is basically what the Hebrew calendar does (although of course they use a much earlier epoch)
o11c•1d ago
`pom(6)` from `bsdgames` might already be installed on your system to do this. Source comments indicate it was originally based on prior versions of the same book but updated to the Third Edition in 1998.

For "implement simple task in many languages" you should probably think of Rosetta Code, now at https://rosettacode.miraheze.org/wiki/Rosetta_Code

lifthrasiir•1d ago
This code consistently converts angles to the [0, 360) range, which is IMO overkill. A better approach is to normalize everything to [0, 2) range so that you can simply multiply or divide by pi to get the radians. If your math library has `sinpi` or `cospi` it will be even more accurate, as it no longer has to divide by 2pi to do the actual calculation.
librasteve•1d ago
made a PR for raku, hope it gets accepted

some cool things stood out:

  sub fixangle($a) { $a mod 360 }    # raku has built-in support for Euclidean modulo
  pi                                 # raku has pi
  
  # Solve equation of Kepler
  my $e = $M; 
  my $delta;

  repeat {                           # raku's repeat loop allows initialisation of delta to be folded in
    $delta = $e - $eccent * sin($e) - $M; 
    $e -= $delta / (1 - $eccent * cos($e));
  } while abs($delta) > 1e-6;
eddyg•1d ago
Thanks! (I'm a big fan of Raku; it doesn't get nearly the respect it deserves!)
oliverkwebb•1d ago
Thank you! I accepted it
librasteve•1d ago
yay - it has made it to raku module status https://raku.land/zef:librasteve/Moonphase
anthk•1d ago
AWK can be far more than a DSL.
kbr2000•1d ago
LCAL[0]: The Moon Phase Calendar Program

A PostScript program to visualize a calendar of moon phases (skip down to "LCAL PostScript Calendar Examples" for just that). Did some nice PS prints recently for the next 10 years, adapted to fit in a frame I had laying around.

[0] https://pcal.sourceforge.net/

Show HN: AirAP AirPlay server - AirPlay to an iOS Device

https://github.com/neon443/AirAP
63•neon443•46m ago•4 comments

Show HN: An Alfred workflow to open GCP services and browse resources within

https://github.com/dineshgowda24/alfred-gcp-workflow
17•dineshgowda24•1h ago•2 comments

Show HN: Controlling 3D models with voice and hand gestures

https://github.com/collidingScopes/3d-model-playground
68•getToTheChopin•6h ago•13 comments

Show HN: Localize React apps without rewriting code

https://github.com/lingodotdev/lingo.dev
38•maxpr•3h ago•31 comments

Show HN: I wrote a Java decompiler in pure C language

https://github.com/neocanable/garlic
127•neocanable•8h ago•57 comments

Show HN: PinSend – Share text between devices using a PIN(P2P, no login)

https://pinsend.app
44•avovsya•6h ago•20 comments

Show HN: .NET Threading Mystery Classes

https://github.com/fbie/threading-mysteries
4•superF•1h ago•1 comments

Show HN: Use Just Your Voice To Author Flow Charts

https://www.loom.com/share/bf336caddabc4e8b84032aa95a7ff303?sid=5c24a0b3-8b28-4dbe-91ce-5077dce2ddaf
4•voice_prompt•1h ago•0 comments

Show HN: Asciilator.com

https://www.asciilator.com/
13•4m1rk•5h ago•7 comments

Show HN: Mosaique.info – Global news in context (solo dev, no ads, no tracking)

https://www.mosaique.info
5•msqinfo•3h ago•0 comments

Show HN: SQLxport – Export SQL Query Results to Parquet, CSV, and S3

https://github.com/vahid110/sqlxport
5•wahid110•2h ago•0 comments

Show HN: I'm Building Ahrefs for AI Search Results

https://linrush.com/
5•devarifhossain•2h ago•1 comments

Show HN: pgarrow – A SQLAlchemy PostgreSQL dialect for ADBC

https://github.com/michalc/pgarrow
3•michalc•2h ago•0 comments

Show HN: I made a scripting language run in the browser with no HTML

https://github.com/sinisterMage/WPlusPlusPlayground
4•sinisterMage•2h ago•0 comments

Show HN: Ultra-lightweight chunker library with emoji support

https://github.com/ushakov-igor/chonkify
16•Beardier•4h ago•4 comments

Show HN: Psuedocode Expander

https://github.com/Explosion-Scratch/psuedocode-expander
3•explosion-s•3h ago•0 comments

Show HN: I build one absurd web project every month

https://absurd.website
263•absurdwebsite•1d ago•63 comments

Show HN: Slurm-web – open-source lightweight web UI for Slurm HPC/AI clusters

https://slurm-web.com/
6•rezib•6h ago•0 comments

Show HN: Kan.bn – An open-source alterative to Trello

https://github.com/kanbn/kan
471•henryball•1d ago•210 comments

Show HN: Rethinknig Serverless – Services, Observers, and Actors Now Available

3•genovalente•4h ago•0 comments

Show HN: Legal Eyes – Turn casual text into legalese with one click

https://www.legaleyes.uk/
4•ForgedLabsJames•5h ago•3 comments

Show HN: A toy version of Wireshark (student project)

https://github.com/lixiasky/vanta
253•lixiasky•1d ago•70 comments

Show HN: Cmd-K for the Terminal

https://github.com/mieubrisse/cmdk
5•mieubrisse•6h ago•1 comments

Show HN: Compliant LLM toolkit for ensuring compliance & security of AI systems

https://github.com/fiddlecube/compliant-llm
6•kaushik92•6h ago•0 comments

Show HN: Winhider – Hide windows from screenshare and Taskbar/Taskswitcher

https://github.com/aamitn/winhider
3•bigwiz•6h ago•0 comments

Show HN: Onlook – Open-source, visual-first Cursor for designers

https://github.com/onlook-dev/onlook
400•hoakiet98•5d ago•80 comments

Show HN: I built an open source clone of Grok's DeepSearch

https://github.com/mendableai/firesearch
2•ericciarla•6h ago•0 comments

Show HN: Penny-1.7B Irish Penny Journal style transfer

https://huggingface.co/dleemiller/Penny-1.7B
145•deepsquirrelnet•1d ago•72 comments

Show HN: Text to 3D simulation on a map (does history pretty well) with gmaps++

https://worldlens.co/map/
4•lukehollis•8h ago•0 comments

Show HN: I made an AI that turn live lecture into structured notes,mind-maps,PDF

https://www.notorium.app
26•pranav_harshan•1d ago•14 comments