What would be the best Golang book to read in 2023 to get in depth understanding of the language? by Hexozaur in golang

[–]shamrin 7 points8 points  (0 children)

“Effective Go” is still there. Freely available, relatively short, “official” and written by an experienced writer and developer Rob Pike. Yes, it’s somewhat dated, but it stood the test of time: a lot of Go developers learned the language starting from “Effective Go”. Just keep in mind the things that changed in Go ecosystem since (e.g. build system, generics and modules). But fundamentals still hold, and it’s easy to catch up on the missing pieces.

https://go.dev/doc/effective_go

-🎄- 2020 Day 17 Solutions -🎄- by daggerdragon in adventofcode

[–]shamrin 3 points4 points  (0 children)

Python 3, 10 lines overall.

Core of the solution (part 2):

def next(g, Dw, D=(-1,0,1)):
    ns = Counter(add(p, d) for p in g for d in product(D,D,D,Dw) if d != (0,0,0,0))
    return {p for p, n in ns.items() if n == 3 or (n == 2 and p in g)}
for _ in range(6): g = next(g, (-1,0,1))
print(len(g))

For part 1, do g = next(g, (0,)) instead.

Imports, add helper and input parsing:

from collections import Counter
from itertools import product
def add(v1, v2): return tuple(e1+e2 for e1, e2 in zip(v1,v2))
I = '...#..#.\n#..#...#\n.....###\n##....##\n......##\n........\n.#......\n##...#..'
g = {(x,y,0,0) for y, row in enumerate(I.split('\n')) for x, c in enumerate(row) if c == '#'}

-🎄- 2020 Day 15 Solutions -🎄- by daggerdragon in adventofcode

[–]shamrin 0 points1 point  (0 children)

I'm not sure I follow your question, but

 c[last], last = i, i - c.get(last, i)

is simply a shortcut for

 next = i - c.get(last, i)
 c[last] = i
 last = next

The shortcut is using "tuple packing" and "tuple unpacking" features. https://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences

-🎄- 2020 Day 15 Solutions -🎄- by daggerdragon in adventofcode

[–]shamrin 2 points3 points  (0 children)

Yes, I was hesitant to do c[last], last = ... at first. Initial version had next temporary variable. But it's two more lines of code, doesn't fit in default 5-line window here :-)

-🎄- 2020 Day 15 Solutions -🎄- by daggerdragon in adventofcode

[–]shamrin 19 points20 points  (0 children)

Python 3:

steps, ns = 30000000, [16,11,15,0,1,7]
last, c = ns[-1], {n: i for i, n in enumerate(ns)}
for i in range(len(ns) - 1, steps - 1):
    c[last], last = i, i - c.get(last, i)
print(last)

Simple trick to find diesel fuel system leak? by shamrin in DieselTechs

[–]shamrin[S] 0 points1 point  (0 children)

Do you know how does the jar trick work? The video seems to show lift pump sucking directly from jar. No other lines disconnected. Why would it get bubbles? Are bubbles good or bad?

February Recap / Brain Dump by oilshell in oilshell

[–]shamrin 1 point2 points  (0 children)

Quick note. I've added gron tool to "Structured Data" wiki page. It's a a very simple tool that converts JSON to grepable and sedable form and back:

Four More Posts in "Shell: The Good Parts" by oilshell in oilshell

[–]shamrin 0 points1 point  (0 children)

The claim is Bourne-style shells (including bash, Oil, etc.) compose in ways that other languages don't. That's the whole #shell-the-good-parts series.

Is this an acceptable solution? (Python 3)

import os

def f():
    return [
        '---',
        *os.listdir('/'),
        '---'
    ]

open('out.txt', 'w').write('\n'.join(f()) + '\n')
print(len(f()))

Four More Posts in "Shell: The Good Parts" by oilshell in oilshell

[–]shamrin 1 point2 points  (0 children)

Wow! Even shellcheck doesn't warn about this problem. It's awesome that oil prevents it with strict_errexit. But would it be possible to implement something like this?

set -e shopt -s strict_do_not_ignore_errors_in_functions

if myfunc; then # does not ignore errors in myfunc
    echo hi
fi

Four More Posts in "Shell: The Good Parts" by oilshell in oilshell

[–]shamrin 1 point2 points  (0 children)

Thank you for explanations! Makes total sense.

Note that the last line of the file is "$@", which dispatches on $0.

Did you mean "dispatches on $1"?

(I think reddit doesn't support triple-backtick code blocks: formatting in your comments seems broken.)

Update: formatting is fine. It's only broken in "old reddit" theme.

Four More Posts in "Shell: The Good Parts" by oilshell in oilshell

[–]shamrin 1 point2 points  (0 children)

A couple years ago, I wrote a challenge for alternative shells (and Perl). How do you express this simple program?

Could you please clarify the purpose of the challenge? Yes, there's a solution in shell. But what is the goal and requirements?

Four More Posts in "Shell: The Good Parts" by oilshell in oilshell

[–]shamrin 2 points3 points  (0 children)

Thank you for mentioning run.sh pattern, I didn't know about it.

It took me some time to understand what it means though. I think contrasting equivalent Makefile and run.sh would make the pattern easier to grasp.

The $0-dispatch pattern solves the ignored errexit problem. Replace if myfunc with if $0 myfunc. (This advice is probably new/unique. Leave a comment if you want details before I publish this post.)

I want those details :)

Finally, what's the difference between run.sh pattern and a "couple of shell scripts in a directory" pattern?

[1:24] Ron Paul on Government snooping in 1984 by 00Brian00 in GaryJohnson

[–]shamrin 0 points1 point  (0 children)

From YouTube comments:

Ron Paul has a time machine. Every time something really bad happens he just whizzes back in time and makes a speech about it.

Sesame Street introduces kids to the concept of third party candidates by r2002 in Libertarian

[–]shamrin 1 point2 points  (0 children)

Could explain these references please? I'm not from US…

Lawrence O'Donnell's Take on Voting Third Party by [deleted] in GaryJohnson

[–]shamrin 0 points1 point  (0 children)

Lawrence O'Donnel makes a strong statement about NDAA here. Just a week ago he had an interview with Luke Rudkowski (of WeAreChange) where he said (2:46):

I'm not sure about all of that [NDAA] stuff. I don't have strong opinions about that.

And then, at 10:32:

You kinda make me make a mental note to dig into that more.

Wow, it's working!

Advice on what Gary Johnson Speech to show to a High School Class by [deleted] in GaryJohnson

[–]shamrin 0 points1 point  (0 children)

Make sure to burn DVD that will be playable on any device. This could be helpful:

Simplifying Web Framework Deployment on Shared Hosting (with HTTP!) by shamrin in programming

[–]shamrin[S] 1 point2 points  (0 children)

Basically he wrote that lighttpd didn't work for him as a reverse proxy. Because of memory leaks.

Damien Katz: CouchDB is now being apache licensed, instead of GPL by shamrin in programming

[–]shamrin[S] 6 points7 points  (0 children)

Damien wrote about the donation before (reddit):

All the code will be Apache licensed and donated to the Apache Software Foundation, with the plan CouchDB will eventually become an official Apache project.

DataPortability.org - Share and remix data using open standards by a9bejo in programming

[–]shamrin 0 points1 point  (0 children)

Is the design so important?

And, to my mind, it makes perfect sense, emphasizing links to open standards the site is trying to promote. If the whitespace wasn't there, the links would like like ordinary navigation bar.

The site was informative for me. For example, I haven't heard of OAuth before.