News for hackers. Stuff that matters.

ArchieMaclean

Re:Clean Code vs. A Philosophy Of Software Design on Tuesday February 25, 2025 @07:03AM (#43170844)
My take on the prime example:

    import itertools
    
    def generate_n_primes(n):
        """
        Generate n prime numbers using a modified Sieve of Eratosthenes.
    
        The algorithm keeps track of a list of primes found so far,
        and a corresponding list of 'multiples', where multiples[i] is a multiple of primes[i],
        (multiples[i] is initially set to be primes[i]**2, see the optimisations section below).
    
        The main loop iterates over every integer k until enough primes have been found,
        with the following steps:
        - For each prime found so far
        - While the corresponding multiple is smaller than k, increase it by steps of the prime
        - If the multiple is now the same as k, then k is divisible by the prime -
            hence k is composite, ignore it.
        - If, for EVERY prime, the multiple is greater than k, then k isn't divisible by any
        of the primes found so far. Hence we can add it to the prime list and multiple list!
    
        There are a few optimisations that can be done:
        - We can insert 2 into primes at the start, and only iterate over every odd k from there on
        - When we're increasing the multiple, we can now increase by 2*prime instead of 1*prime,
        so that we skip over even numbers, since we are now only considering odd k
        - When we find a prime p, we add it to the prime and multiple list. However, we can instead add
        its square to the multiple list, since for any number between p and p**2, if it's
        divisible by p then it must be divisible by another prime k < p
        (i.e. it will be caught by an earlier prime in the list)
        """
    
        # Insert 2 into primes/multiples
        primes = [2]
        multiples = [4]
    
        # Iterate over odd numbers starting at 3
        for k in itertools.count(3, 2):
            # If we've found enough primes, return!
            if len(primes) >= n:
                return primes
    
            # For each prime found so far
            for i in range(len(primes)):
                # Increase its corresponding multiple in steps of 2*prime until it's >= k
                while multiples[i] < k:
                    multiples[i] += 2 * primes[i]
    
                # If its corresponding multiple == k then k is divisible by the prime
                if multiples[i] == k:
                    break
            else:
                # If k wasn't divisible by any prime, add it to the primes/multiples list
                primes.append(k)
                multiples.append(k ** 2)
    
        return primes

Some might find the docstring as well as comments too much - I find the comments help relate the code to the docstring. Open to suggestions!
Re:The game theory of seduction and marriage with Jane Austen on Saturday February 17, 2024 @01:51PM (#39412234)
I'd be willing to bet that the majority of results you find in that search will be men talking about how much women care about money... of course some women do, but far far from all of them
Re:Racket: The Lisp for the Modern Day on Thursday June 29, 2023 @09:48AM (#36520348)
Beneath the large obvious green 'Subscribe' button there is some low-contrast grey text ('Continue reading') that, when clicked, hides the box. This is on Substack's side, not the author of the article.
Re:Your keyboard layout is broken on Saturday June 24, 2023 @11:56AM (#36459750)
No worries, worth a try!
Re:Your keyboard layout is broken on Saturday June 24, 2023 @11:16AM (#36459395)
I did this initially, but I believe it didn't work for all applications - some were still registering it as Caps Lock (e.g. VS Code IIRC).
Re:Your keyboard layout is broken on Saturday June 24, 2023 @08:40AM (#36458212)
Workman [0] was designed to be used on an ortho keyboard, though it is also usable on a normal keyboard. I suppose it's tricky to design for many modern features as they are not yet standardised between keyboards.

[0] https://workmanlayout.org/

Re:Your keyboard layout is broken on Saturday June 24, 2023 @08:34AM (#36458164)
I use Colemak-DH (modified version of Colemak that has less lateral hand motion - found I was getting slight wrist strain with normal Colemak). I find it more comfortable than Qwerty. I have not had any issue with keyboard shortcuts - Ctrl-Z/X/C are in exactly the same spot and Ctrl-V is shifted over by one key. Most shortcuts are placed to be memorable (e.g. Ctrl-F for Find), not to be ergonomic, so the keyboard layout doesn't really matter. The only place I've really had to customise is Vim, where I've remapped the motion keys back to where they are in Qwerty (actually shifted over by one to j/k/l/;).

On Gnome, switching keyboard layout is very quick and easy - there's an icon in the top bar by default - so I can use that when other people want to use my computer. When I use others' computers, I have to look at the keyboard but it is not too much hassle for me as I don't do this very often.

Re:An Elm Fork on Saturday June 10, 2023 @07:05PM (#36276212)
Ah I see. So non-kernel packages do not have access to native modules at all? I believe in Elm native modules were still possible, just not publishing them to the package database. But in this case I guess you wouldn't be able to put a native module in a GitHub repository and then pull this in as a dependency, which is equally rubbish.

Edit: EdwardDiego's answer clarified this for me

Re:An Elm Fork on Saturday June 10, 2023 @06:45PM (#36276016)
Correct me if I'm wrong, but that code seemingly only applies to kernel packages, i.e. packages which are made by the gren team [1]

Seems more like a check to make sure the version of the JS is compatible with the version of gren than anything else.

[1] https://github.com/gren-lang/compiler/blob/e665e521367eeedec...

Presumably it came from Latin 'puppis' (aft, stern, poop deck) before the passing through French to English.
The strong force is much stronger than the Coulomb (charge) force.
Re:Learn Vim (2021) on Friday February 24, 2023 @07:42PM (#34932413)
- Fuzzy file search - I can't find a way to do this in nano? Where you can search a whole directory by name for the file you want to open. This is very useful in larger projects when you need to jump about a lot.

- LSP and all its uses - jump to definition is a big one.

- Window management - while you can use a multiplexer, using one session allows copy/paste to work, saves your file/search/command history, etc.

- While often overstated, it is undeniably more efficient... once you've learnt it.

However, if you are not doing programming, but are just editing e.g. Linux config files, then I would probably stick to nano (in fact, I usually use nano for these jobs, since getting my neovim config to work when running as sudo failed).

Re:Numen: Voice Control for Handsfree Computing on Saturday February 18, 2023 @08:05AM (#34846623)
I like this a lot. This is built upon Vosk [0], open source voice recognition. I must try it for some of my own projects!

[0] https://alphacephei.com/vosk/

Re:Numen: Voice Control for Handsfree Computing on Saturday February 18, 2023 @07:53AM (#34846542)
It looks like they have a word (or multiple) for each letter of the alphabet. So CD is "change drum", git clone is " guest ice traps space cap look [Ctrl right - autocomplete]", where you can read the commands from the first letters of each word.

Edit: the default 'phrases' are here: https://git.sr.ht/~geb/numen/tree/master/item/phrases

Looks pretty. I can't scroll on the gallery page on mobile, and tapping anywhere on the page (including the top example) just brings up the navigation menu. Switching to desktop mode works.
Re:TIPP10 – Free Touch Typing Tutor on Tuesday January 24, 2023 @07:32AM (#34502783)
I use Colemak DH, and have done for a few years. I could never touch type very well on QWERTY anyway so using QWERTY I am no slower than I was originally (in fact, I'm probably faster, since I now use my fingers properly). As long as it isn't very frequent, using hunt-and-peck on any QWERTY keyboards you come across is fine, and touch typing a different layout won't affect it.

Show HN: PipeScore – FOSS Bagpipe Notation Software

https://pipescore.web.app/

I've been working on some version of this since May 2019. It is a web app that allows writing out music for the Highland bagpipe.While it uses the same notation as normal music, bagpipe music tends to have a greater focus on gracenotes (embellishments). Most music software does not deal with this very well (e.g. MuseScore just displays a list of every single possible embellishment, of which...

( Read More... | no comments | 2 points | on HN )
Re:Ideas for a JavaScript Stricter Mode on Sunday January 08, 2023 @08:49AM (#34299071)
For the last point, you can wrap the object in parens:

let generatePerson = name => ({ name, id: generateId() })

Re:Volvo is using Rust for its in-vehicle software on Saturday September 24, 2022 @07:09AM (#32961440)
/([^a-z]|^)rust([^a-z]|$)/i
Re:Betterbird: a fine-tuned version of Mozilla Thunderbird on Wednesday September 21, 2022 @03:22AM (#32921770)
Brendan Eich - wasn't banned per se, but resigned as CEO of Mozilla after it came to light he'd donated to a cause supporting the ban of same-sex marriage. This is all on Wikipedia.
Re:Slackware 15.0 on Thursday February 03, 2022 @06:49PM (#30200743)
> in spite of the dire predictions of YouTube pundits

This is in reference to DistroTube's Linux 2022 predictions which included "no Slackware release"

https://youtube.com/watch?v=YJMm4BXNdX4

Re:Chess.com vs. Lichess on Wednesday December 15, 2021 @06:27PM (#29572870)
Lichess has a 'fishnet' of donated servers [0] that allow you to analyse using Stockfish on proper hardware. You can have up to 20 deep analyses a day.

The web client uses Stockfish compiled to WASM which is decently fast.

If you're not an IM/GM, it's "good enough"

[0] https://github.com/niklasf/fishnet

Re:Weird English on Thursday November 18, 2021 @06:26AM (#29264279)
I wouldn't really call Orcish / Dwarvish 'full languages' - they aren't developed that much. However, the two major Elvish languages (Quenya and Sindarin) are both a lot fuller.
Re:Toki Pona: A Language with a Hundred Words (2015) on Friday October 29, 2021 @08:24AM (#29037611)
Related to [1] - since Toki Pona has such a limited set of sounds, it seems like it would be a great fit for stenography...

[1] https://news.ycombinator.com/item?id=29035644

Re:Open Steno Project – Freeing stenography on Friday October 29, 2021 @07:35AM (#29037328)
CamelCase is built in to Plover! [1] symbols work too - they might have less intuitive memorisation, but you don't use that many anyway (unless you're in APL...but that doesn't work with normal keyboards either).

You can set up Vim-like navigation e.t.c. too (e.g. [2]), for moving about in code. I haven't tried it.

I think however that the benefits of coding with Plover aren't really great enough to justify the huge struggle it would be to get proficient with it.

[1] https://github.com/openstenoproject/plover/wiki/Dictionary-F...

[2] http://www.openstenoproject.org/stenodict/dictionaries/vim_d...

Re:Open Steno Project – Freeing stenography on Friday October 29, 2021 @07:26AM (#29037278)
I haven't tried it, but there is a list of available dictionaries in Plover format [1] including French, Spanish and Italian.

As to switching on the fly, I can't see anything in the docs about it - this extension might work? [2]

[1] https://github.com/openstenoproject/plover/wiki/List-of-Avai...

[2] https://github.com/nsmarkop/plover_system_switcher

Re:Habits I've developed for fast and efficient programming on Sunday October 24, 2021 @09:28AM (#28977696)
VSCode, I think?
Re:Habits I've developed for fast and efficient programming on Sunday October 24, 2021 @07:07AM (#28976768)
Now that I think about it, I'm not sure I can come up with any non-contrived example (maybe this [1]). I guess what's good is that it fits right into the rest of Vim very nicely, so I can just edit like normal, instead of fiddling with regexes.

[1] https://youtube.com/watch?v=FXCitlsA7eQ

Older »