Showing posts with label Terminal. Show all posts
Showing posts with label Terminal. Show all posts

Friday, January 10, 2020

Stupid Hobby Collision D&D+Linux

I like Linux and D&D. Rarely do these hobbies collide, but sometimes I can force it. Not that I am a great Linux user. I like Linux. I like Ubuntu with XFCE. It's a great environment for my purposes. I am newbie when it comes to terminal skills. This post assumes you have zero skill.

I wanted a simple way to generate 6 D&D Character Abilities scores using Linux. There are the classic methods of using a spreadsheet, but what if I don't want numbers in a spreadsheet? What if I merely need them displayed on the screen or in a text file?

Well... terminal can do that with the shuf command. Open a terminal and try this command:

shuf -i 3-18 -n6 | paste - -s -d ' '


Breaking it down, shuf will select a seemingly random number. -i is the input of an expected range, in this case 3 to 18 or 3-18. The headcount or the number of numbers generated in this fashion is -n6. Everything after the pipe | is formating. Basically, this part will turn the typical column of numbers into a row of numbers. 

If you play D&D like me, you let players re-roll ones. In this case, your command would need to cover a range of 6 to 18. Two times three dice is 6. Try this line: 

shuf -i 6-18 -n6 | paste - -s -d ' '


Ok. That's great. You get six numbers in a row on your screen. What if you want that in a text file? For sanity, use the cd command to move from wherever you are to the Documents folder. (I lose lots of files and time by NOT doing this...)

cd Documents


Now that you are in a safe place, let's add some information to that line of commands:

shuf -i 3-18 -n6 | paste - -s -d ' ' > Stats.txt


The instruction > Stats.txt at the end will create a file called "Stats.txt" in your current directory.

Go open that file:


Great. That is one character's worth of stats. Let's make more: 

shuf -i 3-18 -n6 | paste - -s -d ' ' >> Stats.txt


Note the double >> symbols. All that does is tell terminal to append the current information to the file described. Note: I clipped my screen to show gedit and terminal in one screen shot for the next step.

Repeat the last command with a small modification, change -i 3-18 to -i 6-18. Since you didn't close gedit, you will get a new button which refreshes the file. Before you do, repeat the shuf command again. This is easily done by pressing the up arrow and then return. Do this twice.


Ok, now hit that refresh command. You have 4 sets of stats, where the first two have a range of 3 and 18 and the second is 6 and 18.


Shuf is not exactly a random number generator, but it's good enough for government work* and character stats. I THINK it is using it's the process id time and doing a computation based on that value. That means if you run a bunch of these commands in rapid succession and that interval is less than a second, then the seemingly random numbers will all be the same or very close to it. This is why I didn't make it generate 6 character at a time. You probably can't hit up arrow + return in less than half a second so the effect is not as noticeable.

Lastly, you could always run info shuf to see the full documentation of this command or to read at your convenience, try info shuf > Infoonshuf.txt

*This is joke. DON'T use this to generate random numbers for government work.

Sunday, December 20, 2015

The Strange Chromebook XFCE Glitch

This morning, I had some trouble with my version of XFCE on my Chromebook. Tab-Alt stopped working, the menu bar had vanished, the programs opened would not keep focus and the cursor was either X or invisible.

How I hate messing with a perfectly good distro. The solution is rather easy. Delete your ~/.cache/sessions directory and the functions come back after logoff/reboot. How simple.


Of course, I forgot you can't rm directories and needed to try three times before I remembered the rm -r modifier. So the actual command is above.

Whew! Thank god for Ubuntu and XFCE's easy of use. If this was Windows, I'd be screwed.

Sunday, May 31, 2015

Incantato, il mio vecchio amico Alsamixer!

If you use Duolingo on a chromebook, you may have microphone problems. I tinkered around with the settings and chromebooks do not allow websites to access your microphone and camera by default. Change that by going into settings and Privacy.
Now for the surprise. This didn’t completely fix my problem. I did a little more searching and found that Alsamixer is the key. Press crtl+alt+t to pop open a new crosh tab. Type shell and enter.

Bamb! Alsamixer almost like linux. That shouldn’t be a surprise. One issue I did encounter was the function keys wouldn’t work even when I used the function key. Not all is lost. For some reason the search key needs to be pressed to invoke the function keys.
No problem. Press it with your desired function key. Escape to exit. 
I like Duoling to keep up on my Spanish, but it occurs to me that it is also useful for my horrible Italian. Duolingo lets you select multiple languages at the same time. I have no idea if there is a limit to the number, but I thought that I would stick to the two I know pretty well. 

New chromebooks are much better than the one I have. I'm going to start shopping for a new one soon. 

Friday, April 24, 2015

Why use Terminal? (GIMP Install)

Linux has come a long way over the years. Nearly every variant has a software manager, a graphical interface for adding software. Why bother with the Terminal any more?
First, the terminal will display everything it does. Second, there are many versions of Linux and all of them have Terminal as an option. No matter what version of Linux, Terminal experience will server you well.
Here is a quick example of how to install GIMP using the Terminal.
Install GIMP:
sudo apt-get update && sudo apt-get install gimp
The && combos two commands, update and install. The first checks your repositories to make sure they are up to date and the second installs GIMP.
You can follow this with autoclean and clean:
sudo apt-get autoclean && sudo apt-get clean
These commands remove .deb files not used by your system. Autoclean removes the cache information. This is good for systems with low disk space, however the penalty is you will need to download these again if you need to update or install software.

Thursday, April 23, 2015

Eye on the Pi

I have my eye on the Raspberry Pi. This little machine has a vibrant community and help is available all around the web.
This morning, I found The Errant Scientist blog; Matthew takes a walk through the set up process and installation of software via the LXTerminal.

Thursday, April 9, 2015

Next → Stupid Saucy and XFCE Minecraft Trick

Installing Minecraft on a Chromebook is simple. Get Crouton, install Saucy and XFCE then get stuck. Why stuck?
You need to change the permissions of the Minecraft.jar to be an executable.
On many versions of Ubuntu, it is a simple matter of right clicking and checking the “make executable” check box. Using the standard Thunar XFCE file manager, that isn’t an option.
You have a couple of choices here. Installing a new file manager is a possibility, but if you are running XFCE or other light version of Linux, maybe you simply don’t want to do that.
This is a great chance to use the terminal to do what you want. The command needed is “sudo chmod +x”.


As you can see from the screenshot, I am using XFCE on a Chromebook, so my directory line is a little different.


Sunday, February 15, 2015

Terminal Refresh - Chromebook Users and Terminal

Years ago, I wrote a terminal cheat sheet over on pretendertothepower.com I think it is time for an update.
One command that I misunderstood from the beginning was sudo. This concept troubled me as there is a root account, which is sort of analogous to being an admin on Windows. Windows is bad news, because the admin account is so handy, or worse, required to do many standard things. This is not the case in all the various forms of Linux. xPud is a notable exception as you are always logged in as root.
By way of example, in Windows, the Admin account will not allow you to delete critical files from your system. At least, not without a lot of effort. Linux will happily allow the root user to delete ANYTHING!
Linux Rule One: If you don't know what outcome you need, root is NOT the tool for you.
On the other hand, you can gain temporary access to elevated privileges with the sudo command. This is actually the correct method for gaining privileges. Let's say you want to install some software, and you intend for all users to access it. The sudo command allows a user to gain privileges using their own password, not the root account password. The process creates a log of what is done in /var/log/auth.log; if mistakes are made, you can easily figure out what and when it was done.
In this example of sudo, we are going to install gedit. But we need to get ready for it.
sudo apt-get update
This command will tell your system to go and check what versions you have against what versions are available on the servers. It installs nothing. This is very important, because your linux computer has a local list of software available and it could be out of date. Update, update, Update!
The command for installing is:
sudo apt-get install gedit
Linux is made up of packages of software, in discrete chunks to make it more useable. The command apt-get install will put these packages on your system and make them useable.
You can go ahead and try to run both commands without the sudo. It will throw a nasty looking error.
Ok. Now we have gedit installed. We can open gedit without the sudo command. Type
gedit
As you can see, gedit is a very basic editor. We are going to use our elevated privileges and use gedit to do something a normal user cannot do. I am using a Chromebook with Crouton and I would like my Linux system to default to the $HOME/Downloads directory.
Let's fix this. Type sudo gedit .config/user-dirs.dirs to open the protected .config file.
What is not shown is all the activity in the terminal. At this point, since terminal opened gedit with elevated privileges, you should not close the terminal window.
Go ahead and change the text $Home/Desktop to $Home/Downloads.
I changed them all, but obviously you don't need to do that. Click save. You should see some activities in the terminal window.
Tomorrow we will look at using sudo for other purposes.