7,565 karma · joined August 19, 2011
www.gibney.org
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.
https://pyodide.org/en/stable/usage/quickstart.html#accessin...
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.
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.
See also:
https://x.com/marekgibney/status/1817495719520940236
and
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'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.
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.Also with pypy3, putting it in a function about doubles the speed:
time pypy3 min_in_function.py
4999874750
real 0m0.045sWhen 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).
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
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.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.
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. 
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: [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.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.
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.
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.
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.
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?
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.
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.
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.
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.
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.
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"?
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.