Comments (6)
I think that using LC_ALL=C
is faster than inserting a uuencode
, but there are other aspects of efficiency.
You tested speed. It makes sense to me that adding another step in the pipeline (i.e. uuencode) would slow it down. However, making this particular line faster (by 2 milliseconds) is a micro-optimization and probably a premature optimization. This line is not in a loop in the program. I doubt that this whole program will be run in a tight loop. The time that this program spends on network communication (curl) probably dominates the CPU time anyway. There are probably some articles or blog posts about premature and micro optimization on the WWW if you want to learn more.
Another aspect of efficiency is memory use. The same ideas about micro and premature optimization apply to memory also.
Another aspect of efficiency is efficient use of programmer time and effort, so code that is more clear, more brief, more simple, and more easy to understand is better (all other things being equal).
All of these different aspects of efficiency need to be balanced against one another, with the developer deciding, based on context and the issue in question, how important they are.
from tmpmail.
@GReagle
What about this?
USERNAME=$(head /dev/urandom | LC_ALL=C tr -dc "[:alnum:]" | cut -c1-11 | tr "[:upper:]" "[:lower:]")
It's pretty much the same command as earlier, but I added LC_ALL=C
before the tr
command.
We could of course maybe replace cut -c1-11
with head -c 10
but other than that, I think that this command seems reasonable as it fixes the issue without having to make the line too long.
from tmpmail.
This web page addresses the problem and suggests some solutions: https://unix.stackexchange.com/questions/45404/why-cant-tr-read-from-dev-urandom-on-osx.
The problem with the solution proposed of using date +%s
is that on my computer it only puts out numerals, and it is not POSIX compatible. Maybe it's not random enough?
from tmpmail.
I propose:
# get 8 random bytes | encode as text | omit header| omit non-alphanum | get 10 chars|change upper to lower
USERNAME=$(head -c 8 /dev/urandom | uuencode -m /dev/stdout | tail -n +2 | tr -dc "[:alnum:]" | head -c 10 | tr "[:upper:]" "[:lower:]")
from tmpmail.
That (using LC_ALL=C tr) might fix this error with tr. I can neither confirm nor deny based on my own experience because this bug doesn't affect my system, but the web page to which I referred does seem to conclude that it works.
FYI, this command generates thousands of bytes to throw all but 10 of them. I don't think that really matters, but it does bother my OCD a little bit. Putting the binary output through uuencode uses much less data from /dev/urandom.
from tmpmail.
FYI, this command generates thousands of bytes to throw all but 10 of them. I don't think that really matters, but it does bother my OCD a little bit. Putting the binary output through uuencode uses much less data from /dev/urandom.
I do understand what you mean but, I did run both of our command 100 times and timed it to see which one is was more efficient.
Here are the results:
- your method took 0.76s
- my method took 0.52s
So from these results we can say that using LC_ALL=C
might the be the best option in terms of efficiency.
What are you thoughts on this?
from tmpmail.
Related Issues (20)
- allow passing username to generate function HOT 4
- Checking on the command syntax before changing the options/arguments code. HOT 2
- Add support to GuerrillaMail HOT 7
- Hi, can it receive email with attachment? HOT 4
- shuf is not POSIX-compliant HOT 3
- New line HOT 2
- Generate address and paste it into clipboard? HOT 2
- 1secmail API does not support the following usernames: HOT 1
- tmpmail on Homebrew! HOT 6
- tag releases HOT 2
- Version number discrepancy HOT 1
- Error message HOT 1
- Error: Could not find 'w3m', is it installed? on macOS HOT 1
- Request for Pacstall Support HOT 1
- An option to copy email address to clipboard HOT 2
- Unknown release commit HOT 2
- integer expression expected HOT 1
- Cannnot open emails.
- Is it possible to use another API with doing no change on script? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tmpmail.