HNHacker News
TopNewBestAskShowJobs

mg

7,565 karma · joined August 19, 2011

I like to build web projects and to meet like-minded people.

www.gibney.org

submissionscomments
mg··on VanillaJSX.com
Why wouldn't one be able to tell syntax highlighters and code checkers that the string that goes into the html.something() functions is html?
mg··on VanillaJSX.com
What is the benefit of mixing js and html?

    el = <button>Click me</button> as HTMLButtonElement;
What would be the downside of

    el = html.button('<button>Click me</button>');
?

That way no compilation step would be needed and debugging would be easier as the code executed in the browser is the same code the developer writes.

mg··on PyScript: An open source platform for Python in the browser
Probably. It is part of Pyodide, not something this PyScript project adds:

https://pyodide.org/en/stable/usage/quickstart.html#accessin...

mg··on PyScript: An open source platform for Python in the browser
The homepage left me confused, and also after reading the documentation, I'm not sure what this is.

I tinkered a bit to try it myself.

Turns out you can throw this into your website and it will display "Hello World":

    <script type="module" src="https://pyscript.net/releases/2024.8.2/core.js"></script>
    <script type="py">
        import js
        js.document.querySelector("body").innerText = "Hello World"
    </script>
So it seems to be a script that looks for scripts of type "py" and transpiles them from Python to JavaScript via Pyodide?

On the other hand, the demo on the homepage is a repl. And the title says "platform". So I'm still confused.

mg··on Building a highly-available web service without a database
When I start a new project, the data structure usually is a "list of items with attributes". For example right now, I am writing a fitness app. The data consists of a list of exercises and each exercise has a title, a description, a video url and some other attributes.

I usually start by putting those items into YAML files in a "data" directory. Actually a custom YAML dialect without the quirks of the original. Each value is a string. No magic type conversions. Creating a new item is just "vim crunches.yaml" and putting the data in. Editing, deleting etc all is just wonderfully easy with this data structure.

Then when the project grows, I usually create a DB schema and move the items into MariaDB or SQLite.

This time, I think I will move the items (exercises) into a JSON column of an SQLite DB. All attributes of an item will be stored in a single JSON field. And then write a little DB explorer which lets me edit JSON fields as YAML. So I keep the convenience of editing human readable data.

Writing the DB explorer should be rather straight forward. A bit of ncurses to browse through tables, select one, browse through rows, insert and delete rows. And for editing a field, it will fire up Vim. And if the field is a JSON field, it converts it to YAML before it sends it to Vim and back to JSON when the user quits Vim.

mg··on Recent Performance Improvements in Function Calls in CPython
That's what I meant. It tries to access a global variable 'y' and fails because there is none.

See also:

https://x.com/marekgibney/status/1817495719520940236

and

https://x.com/marekgibney/status/1817495721974583569

mg··on Recent Performance Improvements in Function Calls in CPython
Interesting. As I understand it, it will not affect my example:

    def f():
        exec('y = 7') # will still create a local variable
        print(locals()['y']) # will still print this local variable
        print(y) # will still try to access a global variable 'y'
mg··on Recent Performance Improvements in Function Calls in CPython
Yes, I stumbled across this quite recently:

https://x.com/marekgibney/status/1817495719520940236

I was surprised that you cannot access dynamically created local variables even though they exist.

Looks like the local dictionary still exists. Just that whether accessing a local variable looks it up in the local or global dictionary is determined at compile time.

mg··on Recent Performance Improvements in Function Calls in CPython
I think you still need to do the templating in PHP, because you usually want to escape html chars. And because you want to seperate code and layout. Having "Hello <?=$name?>" in the template is usually not what you want. It is also harder to read than "Hello {NAME}".

Let's test templating in Python and PHP!

template.py:

    def main():
        t = 'Number {NR} is cool'
        i = 10_000_000
        r = 0

        while i>0:
            x = t.replace('{NR}', str(i))
            r += len(x)
            i = i - 1

        print(r)

    main()
template.php:

    <?php

    $t = 'Number {NR} is cool';
    $i = 10_000_000;
    $r = 0;

    while ($i>0) {
        $x = str_replace('{NR}', $i, $t);
        $r += strlen($x);
        $i = $i - 1;
    }

    print($r);
Results:

    time python3 template.py 
    218888897
    real    0m2.854s

    time php template.php 
    218888897
    real    0m0.994s

    time pypy3 template.py 
    218888897
    real    0m0.795s
So for this use case, PHP is 3x faster than CPython and PyPy is 20% faster than PHP.
mg··on Recent Performance Improvements in Function Calls in CPython
Interesting! Same here.

Also with pypy3, putting it in a function about doubles the speed:

    time pypy3 min_in_function.py 
    4999874750
    real    0m0.045s
mg··on Recent Performance Improvements in Function Calls in CPython
I wouldn't say you are a stickler. But the most productive addition to the discussion would be to do the benchmark as you see fit and then show us the results.
mg··on Recent Performance Improvements in Function Calls in CPython
Yes, it is CPython. Added data on the PyPy performance to this comment now:

https://news.ycombinator.com/item?id=41199431

mg··on Recent Performance Improvements in Function Calls in CPython
You might be right about the min() call being the major penalty.

When I avoid the min() call like this ...

min2.py:

    i = 10_000_000
    r = 0

    while i>0:
        i = i-1
        if i<500: r += i
        else    : r += 500

    print(r)
I get a speedup of about 50%:

    time python3 min2.py
    4999874750
    real    0m1.338s
Still 4x slower than PHP though.

With PyPy I get an amazing speedup of 96%:

    time pypy3 min.py
    4999874750
    real    0m0.088s
4 times faster than the PHP version!

I'm not sure what the state of things is regarding PyPy and running a web application. Doing a bit of googling, it seems that calling C functions from PyPy is slow, so one would have to check if the application uses those (for example to connect to the database).

mg··on Recent Performance Improvements in Function Calls in CPython
Reading this, I was interested to see how big the speed difference between Python and PHP is these days, so I tried it like this:

min.py:

    i = 10_000_000
    r = 0

    while i>0:
        i = i-1
        r += min(i,500)

    print(r)
min.php:

    <?php

    $i = 10_000_000;
    $r = 0;

    while ($i>0) {
        $i = $i-1;
        $r += min($i,500);
    }

    print($r);
The results:

    time python3 min.py
    4999874750
    real    0m2.523s

    time php min.php
    4999874750
    real    0m0.333s
Looks like Python is still 8x slower than PHP. Pretty significant.

I ran it with Python 3.11.2 and PHP 8.2.18

mg··on Raspberry Pi Pico 2, our new $5 microcontroller board, on sale now
Which Raspberry Pi would one need to run Vim and Firefox? And is it possible to have it use a tablet as a monitor and draw power from it?

That would be everything I need to develop web applications. I wonder if I could use a 3-piece setup to do so:

    A keyboard connected to the Pi
    The Pi connected to a tablet which acts as a monitor
Not sure how much the Pi weights, probably less than 100g? The Apple Magic Keyboard for example is 230g. And the Lenovo Tab P12 for example is 570g. So together less than 1kg. For a Linux development machine with external keyboard, that would be quite nice.
mg··on Computers are amazing. So why is software so terrible?
A friend of mine has an expensive 15-inch Dell laptop. He does not know much about tech specs, but since much of his work life revolves around his laptop, he simply bought the maxed out version. In the hope it makes his life easier.

In the hope that every tool he installs makes his life easier too, he installed so much stuff on it, that the battery in this newish laptop lasts less than an hour.

So he lugs around this beast of a laptop, with a beast of a charger. And even when he just uses a browser, after 30 minutes, he gets nervous: "I need a power outlet!".

Every time I watch this drama in confusion, I ask him why he doesn't look up what software drains his battery, and what he can do about it.

That makes him very uncomfortable, and he proclaims: "No, it's Dell's fault! And I can use the laptop with a power outlet! No problem!".

Somehow, analyzing what software does seems to make some people so uncomfortable that they never look into it and therefore never blame bad software for its behavior.

mg··on "We ran out of columns"
That is why people these days tend to use a single JSON blob instead of multiple columns. And because it is so popular, SQLITE and other DBs are building better and better JSON support into the DB.

I wonder if better support of EAV tables would solve this issue better.

If one could do "SELECT price,color,year FROM cars! WHERE status='sold'" and the "!" would indicate that cars is an EAV table ...

    entity attribute value
    1      price     20750
    1      color     red
    1      year      2010
    1      status    sold
... and the result of the query would be ...

    20750 red 2010
That would solve most of the use cases where I have seen people use JSON instead.
mg··on I prefer rST to Markdown
Markdown:

    ![alttext](example.jpg)
RST:

    .. image:: example.jpg
      :alt: alttext
The author prefers RST because:

    ... you can extend Sphinx with new text objects!
    Say you that instead of an <image>, you want
    a <figure> with a <figcaption> ...
What I would do:

        ![alttext](example.jpg)[caption]
And write a renderer which supports this syntax to create a figure with a figcaption. A markdown renderer is simple enough to write your own or extend an existing one.
mg··on In the Beginning Was the Command Line (1999)
The analogy I would make is that living in the command line is like using a CAD program while living in IDEs is like using CorelDraw to design houses.

CorelDraw feels more efficient because one quickly has what looks like a beautiful, colorful house on the screen. And then one does not understand why the doors don't work correctly.

mg··on In the Beginning Was the Command Line (1999)
The command line is still king.

Whenever I see new coders struggle, it usually is because they:

    - Don't know the context of what they are executing

    - Don't know about the concept of input and output
On the command line, the context is obvious. You are in the context. The working dir, the environment, everything is the same for you as it is for the thing you execute via ./mything.py.

Input and output are also obvious. Input is what you type, output is what you see. Using pipes to redirect it comes naturally.

Not being natively connected to context, input and output is often at the core of problems I see even senior programmers struggle with.

mg··on Tesla Sales Drop 17% in California
I also have the feeling that there is a good chance Tesla cars built in 2024 won't become robotaxis. But that is a different question.

My guess is about the first car using Tesla software to offer commercial rides. No matter when it was build or who built it. Because the most interesting part is the software.

mg··on Tesla Sales Drop 17% in California
It seems the focus of Tesla has mostly shifted to operating robotaxis.

What is everybody's guess when they will have the first robotaxi on the road somewhere, offering rides without a safety driver? Could be interesting to look back in the future and see how close or how far off we have been with our guesses.

My feeling is that it will happen in about 2.5 years. Could be next year, could be in 5 years. So if I had to guess, I'd say in 2.5 years.

mg··on Google's shortened links will stop working next year
Every time I change a ULR (or a set of URLs), I put a test for the redirect into my end-2-end tests, which run once per day. So I know all my URLs will work forever.

I have not thought about it for years now. Just checked for my first ever Show HN from 10 years ago:

https://news.ycombinator.com/item?id=7465980

The URL has long changed, but the redirect still works. Phew :) So all seems to be good. Here's to the next 10 years!

Google should do the same. Set up a seperate server for the redirect service itself. And then I guess they have multi project end-2-end tests running somewhere in their infrastructure. Just add testing this service and thats it. Amount of work per year to keep it up should be less than an hour, right?

mg··on My daughter (7 years old) used HTML to make a website
Awesome!

That's pretty much how I make websites up to this day.

Later, if it grows, I usually add a stylesheet file to separate content and layout.

Then I sometimes add some JavaScript.

Then I sometimes add some backend storage and processing.

Then I need a certificate for https.

Then if it gets a lot of traffic, I put a CDN in front of it.

And that's it.

mg··on Self-Awareness Might Not Have Evolved to Benefit the Self After All
What exactly does it mean that we "have the language to know"? And how do you prove it? How does the cog's reply in my last comment not match your definition and proof?

In my experience, when you try to define and prove it in a way that is not fuzzy, you come up with a definition that also matches the cog.

mg··on Self-Awareness Might Not Have Evolved to Benefit the Self After All
Is there a difference between panpsychism and the idea that consciousness is just a post hoc justification?

To me they seem the same. When you say "3 stones make a trio of stones" you don't mean that a "trio" existed somewhere outside of the stones and now moved into the stones, do you? You just gave a name to this specific formation of a stone, another stone and yet another stone.

mg··on Self-Awareness Might Not Have Evolved to Benefit the Self After All
Yes, I would say every system has self-awareness.

You say "reasoning" is needed. Ok, but how is that defined? Say you "ask" the cog why it turned by rattling it. Then it will rattle the other cog and, therefore, point you towards it. And you might say "Oh, I understand. You turned because the other cog pushed you". You might say that is just a mechanical mechanism. But if you look at human behavior close enough, it's just a mechanical mechanism too.

mg··on Show HN: Product Hunt for Music
Hey, I run two somewhat popular music recommendation websites, the Music-Map and Gnoosic. I currently experiment with the ability to feature the music of artists, so I have put your music up on Gnoosic:

https://www.gnoosic.com/artist/freddie+veggie

And put you on the map next to some other didgeridoo artists:

https://www.music-map.com/freddie+veggie

I'm not yet sure when I will turn the signup into a public feature. Currently, I'm interested in feedback from artists. If you like, shoot me an email. The two sites have a pretty big audience, and I would like to find out how I can use it to help small artists.

mg··on Self-Awareness Might Not Have Evolved to Benefit the Self After All
I have the feeling that self-awareness is inherent in every system.

When a flower gets more sunlight from one side than from the other, it starts to turn to that side. Is that different from a person who walks somewhere because they like to? Most people I ask say "Well, the human can say 'I'". But a computer can also say "I". Where is the threshold to call it "self-awareness"?

mg··on Libera IRC Channels Sorted by Number of Users
#linux has 2198 users right now. That might be the largest.

What is everybody's favorite channel?

I find #python pretty good (1501 users!). Also #debian, #php, #javascript, #math and #statistics.

#startups was great in the past but is kinda empty at the moment.

← PreviousPage 12 of 34Next →