by hiddencost · 3y ago · 0 comments
I mean ... IDK, if you can't write that on your own without research, I don't think you should be writing a eulogy for programming in the New Yorker.
(I just wrote two version, one using python's random.sample and the other more verbosely, to double check myself.)
My most recent thing is for a game I'm working on. I got a bunch of free sound FX from freesound.org, but they were AIFF format. I googled and found an online converter, then asked ChatGPT to use ffmpeg to write a script that goes through the directory converting the AIFFs to MP3s.
In the past if I would have written such a script it would have required me to "look into how to do it" and then I would have saved the script somewhere on my machine or online. Now I just deleted it right away. If I ever need to do it again or something similar I'll just ask ChatGPT and get it from scratch again.
Well there's your problem. Such a powerful tool, but that CLI is something else.
My last attempt to use it was to do with resolving circular calculations in Excel - I wanted some way of calculating the sum of a geometric series without having the series in actual cells. It kept recommending things that didn't work.
I'm always amazed to hear of people who manage to get working code from an AI. This has not been my experience.
In my experience LLMs work best if you already know how to do something, but you just can't be bothered to actually do it.
When exploring unknown territory, keep your questions simple and ask for clarification on anything you don't understand. It will not just help you, but the AI as well.
There are simple explicit formulas for this.
The ability for chatGPT to essentially translate/expand your knowledge out to other languages (eg “how do I read in a file to utf8 again” ). It’s all just more leverage and power to solve the mundane, faster. The key point is you have to know the rough solution space already.
This is bad. If you don’t have newbie programmers, you won’t have senior programmers.
Once upon a time, developers had to pore over manpages, paper textbooks, or memorize it. Then came google. Next, stackexchange. And now GPT-4 - which is kind of a search engine plus rudimentary synthesis.
But let's be clear. This is low-hanging fruit. It's a poor substitute for actual thought. And surely we are safe.
Not fluid intelligence, not creative velocity, not creative originality, not oodles of domain knowledge … adaptability.
A new tool comes along? Adapt. A new idea breaks a long established paradigm? Adapt. A new skill is required? Adapt. As I get older adapting gets easier, because I treat ideas like objects - useful until they are not. No part of me cannot change, and my certainty in myself comes not from a bank of sanctified ideals I worship but in the knowledge that whatever comes, I will adapt and thrive. Fat client, thin client, centralised, edge, micro services, monolithic, ideas, tech, frameworks, everything is fluid and that’s what keeps things fun.
Same goes with the arrival of GPT, I embraced it, learnt it’s strengths and weaknesses and now I estimate I’m maybe 2x more productive because of it, that means more time of fun things that interest me.
Adapt, adapt, adapt
The graveyards are filled to overflowing with companies that were challenged by low-end 'crappy' products and said 'they are going after the bottom of the market, we are safe'... a few years before they entered a terminal decline, and a decade before they went extinct.
Thought experiment: how could this apply to human thought? i.e. what is a low-end that we couldn't address?
Disclaimer: I really like Christensen's reasoning, theories, and expression of them... but he did predict the iphone would not be disruptive. So, at best, difficult to apply!
On the other hand, even if you can write it, does it mean you should write it? How much time does it cost you to write it? How much money your company is paying you in that amount of time? Is it more economical for GPT-4 to do it?
So I was curious and decided to ask the mistral-7b-instruct, and it gave me the following,
> Here is an example of a Python script that reads a dictionary file and prints 100 random lines:
```python
import random
with open('dictionary.txt', 'r') as f:
lines = f.readlines()
random_lines = random.sample(lines, 100)
for line in random_lines:
print(line.strip())
```
> This script uses the `random` module to select a random subset of the lines in the file. The `open` function is used to open the file and read its contents into a list of strings, which are then passed to the `random.sample` function to select 100 random lines. Finally, the selected lines are printed using a for loop and the `strip` method to remove any leading or trailing whitespace.> Note that this script assumes that the dictionary file is located in the same directory as the script and is named "dictionary.txt". You may need to modify the script to specify the correct path and filename for your dictionary file.
<dict shuf | head -n100 <dict shuf -n 100The "<" is actually an unnecessary additional character to type.
> Use reservoir sampling to get 100 random lines from a dictionary that doesn’t fit into memory. Give me an implementation in Python.
> Reservoir sampling is a great choice for randomly selecting a fixed number of items from a stream of unknown size, especially when the entire dataset cannot fit into memory. Here's a Python implementation for selecting 100 random lines from a large file, like a dictionary, using reservoir sampling:
```python
import random
def reservoir_sampling(file_name, k):
reservoir = []
with open(file_name, 'r') as file:
for i, line in enumerate(file):
if i < k:
# Fill the reservoir array
reservoir.append(line.strip())
else:
# Randomly replace elements in the reservoir
# with a decreasing probability.
# Choose an integer between 0 and i (inclusive)
j = random.randint(0, i)
if j < k:
reservoir[j] = line.strip()
return reservoir
# Example usage
file_path = 'path_to_your_large_file.txt' # Replace with your file path
sampled_lines = reservoir_sampling(file_path, 100)
print(sampled_lines)
```
> This script opens a file and reads through it line by line. For the first 100 lines, it adds them directly to the reservoir. For each subsequent line, it randomly decides whether to replace an existing line in the reservoir with the new line. The probability of replacing decreases as it progresses through the file, ensuring each line has an equal chance of being included in the final sample.I laid out the constraints, but I did not mention reservoir sampling at all. The script seems to work as expected when I run it against a dictionary file.
Can you use random access into the file to sample k lines in O(k) time instead of O(n) time?
$ convert foo.png foo.jpg
Took me almost literally two seconds to come up with that, unless your point is that at one point I had to learn it which, yeah, sure. What am I missing?
Even things like "what flags to use with ffmpeg" are a shell reverse-history search away, assuming one has ever used them in the past.
In 2013 I was using complex ffmpeg commands and using filters in there. Could remember the stuff easy. Now, I've gotta reference my ffmpeg notes more frequently.
Where's that XKCD about using the tar command?
As of my last knowledge update in January 2022, I can't provide specific details about the latest XKCD comics or their numbers because my training data only includes information available up to that time. However, you can easily find XKCD comics on the official XKCD website (xkcd.com) by using the search function or by browsing through the archives.
If there's a specific XKCD comic related to the "tar" command that you're looking for, you might be able to find it by searching for keywords like "XKCD tar command" on a search engine or directly on the XKCD website. The website has a good search feature that allows you to find comics based on keywords or topics.
tar xf for extract. Add v to show the files. tar cf to create. tar tf to "test" (list). Add -C dir at the end to extract to different directory. Set file to "-" for stdin.
That's all there's to it for 99% of use cases. I don't get how anyone can have difficulty with that: f for file, and x/c/t are pretty mnemonic.
cat /usr/share/dict/words | while read LINE; do echo "$RANDOM $LINE"; done | sort -h | head -n 100 | awk '{ print $2 }'Programming is doomed!
like, try this
import collections, random
def shuffle(xs): # naive intuitive shuffle
for i in range(len(xs)):
j = random.randrange(len(xs))
xs[i], xs[j] = xs[j], xs[i]
def first_of(n):
xs = list(range(n))
shuffle(xs)
return xs[0]
print(collections.Counter([first_of(3) for i in range(100_000)]))
note that 1 comes out first 25% more often than 2, but with a fair shuffle all three should have an equal chance of being firsteven without running it you can figure out logically that it must be biased in some way because there are 3! = 6 possible permutations and 3³ = 9 equally likely sequences of choices for j (each producing one of those permutations), and 9 is not divisible by 6, so some of those permutations have to be more likely than others
so i think this algorithm is a good one to get from a library if its randomness is important to you
not from chatgpt, which commonly does give you subtly buggy code
but the only method involved here is string.strip(), so i don't think this is an example of the problem you describe
import random
n = 100
ws = [line.strip() for line in open('/usr/share/dict/words')]
for i in range(n):
j = random.randrange(i, len(ws))
ws[i], ws[j] = ws[j], ws[i]
print(ws[i])
(did i fuck that up)and yeah probably calling random.sample would be better. and usually import random is better than writing your own rng. but not always
I don't understand unbound excitement about using a paid online tool (!) that does not have reproducible source code (!!) and can sometimes (!!!) generate correct implementations of extremely well-known algorithms if given perfect description.
And I get it, there are highly specialized people that get very deep in the weeds in maybe HPC or embedded, even so most of them will at least still be aware, but moreover these people lack the knowledge to comment on programming or software engineering in the large, I wouldn't call them experts outside their limited domain if they really can't begin to know where to look to do a fucking permutation of a word list.
The old saying that for some 20 years of experience is 1 year and 19 repeats probably applies.