Showing posts with label Computer. Show all posts
Showing posts with label Computer. Show all posts

Saturday, April 5, 2025

Hamurabi.bas

 Hamurabi.bas was a game we use to play in High School on the PDP-10 in the computer lab. The original code is available all over the internet. As a thought experiment, I decided to update it to a more modern format. I took out the line numbers, used meaningful variable names and replaced the GOTO's and GOSUB's with functions.


'hamurabi.bas
' Original code by Creative Computing, Morristown, New Jersey
' Updated code by Chris Stoddard

Randomize

Dim As Integer year, people, grain, harvest, rats, land, yield, immigrants
Dim As Integer starved, totalStarved, totalPercentStarved
Dim As Integer landPrice, acresToBuy, acresToSell, grainToFeed, acresToPlant
Dim As Integer plagueChance, peopleFed, babies, inputValid
Dim As Double percentStarved

year = 0: people = 95: grain = 2800: harvest = 0: rats = 0
land = 3000: yield = 3: landPrice = 17: immigrants = 5
starved = 0: totalStarved = 0: totalPercentStarved = 0

Sub ThinkAgainGrain(grain As Integer)
    Print "HAMURABI: THINK AGAIN. YOU HAVE ONLY "; grain; " BUSHELS OF GRAIN. NOW THEN,"
End Sub

Sub ThinkAgainLand(land As Integer)
    Print "HAMURABI: THINK AGAIN. YOU OWN ONLY "; land; " ACRES. NOW THEN,"
End Sub

Sub ImpossibleRequest()
    Print : Print "HAMURABI: I CANNOT DO WHAT YOU WISH."
    Print "GET YOURSELF ANOTHER STEWARD!!!!!"
    End
End Sub

Sub Bell()
    For i As Integer = 1 To 10
        Print Chr(7);
    Next
End Sub

For year = 1 To 10
    Print : Print : Print "HAMURABI: I BEG TO REPORT TO YOU,"
    If year > 1 Then
        Print "IN YEAR "; year - 1; ", "; starved; " PEOPLE STARVED, "; immigrants; " CAME TO THE CITY,"
    End If
    people = people + immigrants
    If plagueChance = 0 Then
        people = people \ 2
        Print "A HORRIBLE PLAGUE STRUCK! HALF THE PEOPLE DIED."
    End If
    Print "POPULATION IS NOW "; people
    Print "THE CITY NOW OWNS "; land; " ACRES."
    Print "YOU HARVESTED "; yield; " BUSHELS PER ACRE."
    Print "THE RATS ATE "; rats; " BUSHELS."
    Print "YOU NOW HAVE "; grain; " BUSHELS IN STORE."

    landPrice = Int(Rnd * 10) + 17
    Print "LAND IS TRADING AT "; landPrice; " BUSHELS PER ACRE."

    Do
        inputValid = 1
        Print "HOW MANY ACRES DO YOU WISH TO BUY? ";
        Input "", acresToBuy
        If acresToBuy < 0 Then ImpossibleRequest
        If acresToBuy * landPrice > grain Then
            ThinkAgainGrain(grain)
            inputValid = 0
        End If
    Loop Until inputValid = 1

    If acresToBuy > 0 Then
        land += acresToBuy
        grain -= acresToBuy * landPrice
    Else
        Do
            inputValid = 1
            Print "HOW MANY ACRES DO YOU WISH TO SELL? ";
            Input "", acresToSell
            If acresToSell < 0 Then ImpossibleRequest
            If acresToSell > land Then
                ThinkAgainLand(land)
                inputValid = 0
            End If
        Loop Until inputValid = 1
        land = land - acresToSell
        grain = grain + acresToSell * landPrice
    End If

    Do
        inputValid = 1
        Print "HOW MANY BUSHELS DO YOU WISH TO FEED YOUR PEOPLE? ";
        Input "", grainToFeed
        If grainToFeed < 0 Then ImpossibleRequest
        If grainToFeed > grain Then
            ThinkAgainGrain(grain)
            inputValid = 0
        End If
    Loop Until inputValid = 1
    grain = grain - grainToFeed

    Do
        inputValid = 1
        Print "HOW MANY ACRES DO YOU WISH TO PLANT WITH SEED? ";
        Input "", acresToPlant
        If acresToPlant < 0 Then ImpossibleRequest
        If acresToPlant > land Then
            ThinkAgainLand(land)
            inputValid = 0
        ElseIf acresToPlant \ 2 > grain Then
            ThinkAgainGrain(grain)
            inputValid = 0
        ElseIf acresToPlant > people * 10 Then
            Print "BUT YOU HAVE ONLY "; people; " PEOPLE TO TEND THE FIELDS! NOW THEN,"
            inputValid = 0
        End If
    Loop Until inputValid = 1
    grain = grain - acresToPlant \ 2

    yield = Int(Rnd * 5) + 1
    harvest = acresToPlant * yield
    rats = 0
    If Int(Rnd * 2) = 0 Then
        rats = Int(grain / yield)
    End If
    grain = grain + harvest - rats

    babies = Int(yield * (20 * land + grain) / people / 100 + 1)
    immigrants = babies
    peopleFed = grainToFeed \ 20

    plagueChance = Int(10 * (2 * Rnd - 0.3))

    If peopleFed < people Then
        starved = people - peopleFed
        percentStarved = (100.0 * starved) / people
        If percentStarved > 45 Then
            Print : Print "YOU STARVED "; starved; " PEOPLE IN ONE YEAR!!!"
            Print "DUE TO THIS EXTREME MISMANAGEMENT YOU HAVE NOT ONLY"
            Print "BEEN IMPEACHED AND THROWN OUT OF OFFICE BUT YOU HAVE"
            Print "ALSO BEEN DECLARED NATIONAL FINK!!!!"
            End
        End If
    Else
        starved = 0
    End If

    totalStarved += starved
    totalPercentStarved += percentStarved
    people = people - starved
Next

Dim As Integer acresPerPerson = land \ people
Dim As Integer avgStarved = totalPercentStarved \ 10

Print : Print "IN YOUR 10-YEAR TERM OF OFFICE, "; avgStarved; "% OF THE"
Print "POPULATION STARVED PER YEAR ON THE AVERAGE."
Print "A TOTAL OF "; totalStarved; " PEOPLE DIED!!"
Print "YOU STARTED WITH 10 ACRES PER PERSON AND ENDED WITH"
Print acresPerPerson; " ACRES PER PERSON."

If avgStarved > 33 Or acresPerPerson < 7 Then
    Print "YOU STARVED TOO MANY AND LOST TOO MUCH LAND!"
    Print "YOU HAVE BEEN DECLARED A DISASTER!"
ElseIf avgStarved <= 10 And acresPerPerson >= 9 Then
    Print "A FANTASTIC PERFORMANCE!!! CHARLEMAGNE, DISRAELI, AND"
    Print "JEFFERSON COMBINED COULD NOT HAVE DONE BETTER!"
ElseIf avgStarved > 3 Or acresPerPerson < 10 Then
    Print "YOUR PERFORMANCE COULD HAVE BEEN SOMEWHAT BETTER."
    Print Int(people * 0.8 * Rnd); " PEOPLE WOULD DEARLY LIKE TO SEE YOU ASSASSINATED."
Else
    Print "YOUR HEAVY-HANDED PERFORMANCE SMACKS OF NERO AND IVAN IV."
    Print "THE PEOPLE (REMAINING) FIND YOU AN UNPLEASANT RULER AND,"
    Print "FRANKLY, HATE YOUR GUTS!!"
End If

Bell()
Print : Print "SO LONG FOR NOW."
End

Sunday, June 12, 2022

r/selfhosted

 Yeah, it has been a good long time since the last time I posted anything here. It is a wonder I even still bother to maintain this site. The fact of the matter is, I really just want to retain the domain name, so I pretend to blog every now and again to justify the $12 a year it costs me to keep it. To make even weirder, I have been offered money for this domain name, $2000 to be exact, but I turned it down. The exact reason I turned it down is a bit vague, but I am sure subconsciously I have a good reason.

I have been working on this blog post now for at least a month. I originally was just going to talk about setting up an ESXi virtual machine server, but since then the project has grown to the point where I am self hosting a small pile of services. Below is a screen shot of Homer, one of the services I setup. Homer's only job is to serve up a nice webpage with links to things I use. It is really just an overly complex landing page, but it works well and makes things look pretty. I am not going to get into the links or the streaming services, these are just external links to websites I go to reasonable often. The Applications and Servers is where the more interesting stuff is happening.



Meh!, between taking a screen cap and uploading the above image, I changed my mind, I am not all that interested in talking about setting up my own cloud services. While I enjoyed learning how to use Ubuntu Snaps and Docker Containers, it is honestly not a particularly interesting subject and there are tons of websites and Youtube videos on how to set this stuff up. While I set this up on a machine with 16 GB of RAM and 5 TB of storage, you could easily do the same thing on a Raspberry Pi, minus the ESXi server of course. If you really are interested in what I did, I got started with this Youtube Playlist.

pi-hosted on the Novaspirit Tech channel

The process he is following will work perfectly fine on any old Intel/AMD based system you have laying around that was built in the last 10 years. I think you could get by pretty well with 4 GB of RAM, I have seven Docker Containers running and it is consuming less than 1.6 GB of RAM. The amount of storage you need depends entirely on how much room you need for NextCloud and Emby.

Sunday, December 19, 2021

Crypto Currency

 Over the last couple of days I have entered into Crypto mining. No I have not bought a $12,000 Bitcoin miner, I am not that crazy. No, I joined a Monero mining pool, which allows me to put low powered machines to work mining the Monero crypto coin and still some small amount based on how much work these otherwise idle machines do, everyone who contributes CPU cycles gets a cut. I put 2 Raspberry Pi 4's to work along with 2 Optiplex 3050 mini's to work on this project. The 2 Pi's are averaging about 90 hash's per second, the two Optiplex's are averaging around 600 hash's per second. Over the last couple of days as I put my mini farm to work I have acquired 0.0003 Monero or about $0.05. Yeah, I know, its not much, but hey, if I eventually get 1 complete Monero, at its current price of $190, That will pay for every penny of what I have sunk into this equipment over the last 2 or 3 years, then of course I can start paying off the power this sucks down.

I am not a big believer in the whole crypto currency thing. Frankly to me it is like gold in World of Warcraft or maybe even Monopoly Money. It have no real value except what people attribute to it and eventually all those big mining operations and hedge fund managers who are hoarding all this crap are going to cash out and it is all going to come crashing down. There is no way I would ever spend $190 of actual cash on buying a Monero or god forbid $47,000 for a Bitcoin.

So why then am I putting effort into mining it? Well for one thing it is an interesting technical challenge setting up the hardware, compiling the code, getting everything working. Second, though eventually this is all going to come crashing down, until then there are some uses for crypto currency, especially Monero, which has some extra security features on it that make tracking it much more difficult. While I have no intention of doing anything illegal, you just never know when you will need a stash of untraceable money at your disposal.

Anyone interested in getting started should watch this video, it is a great starting place.



Thursday, July 8, 2021

$20 Dollar Computers

 I picked up three Optiplex 3050 mini computers for $20 each. They came sight unseen, untested and without power supplies. I would have offered more, had the systems come with power supplies and I could have tested them. I purchased a single power supply so I could test the three system. All three are working and took a Debian install, so now I need to buy two more power supplies, which only cost about $17 each, so I am still under $40 for each of them.


Where I am now, is what to do with them. They each have i3 processors, 4GB of RAM and a 500 GB hard drive (not SSD's) and they are less than 4 years old. I am tempted to build a Beowulf cluster, doing this would allow me to do some interesting projects, like find out just how long it would take to break a Windows password or perhaps experiment with machine learning and unleash a Twitter Chatbot on the world just for the LOLs.

Two of them would also make pretty good media servers, as you can see, the middle one in the stack is pretty beat up and probably will not clean up well, having that sit next to a TV would just be unsightly. I am also not sure if the Intel graphic would be up to 4K video playback and there is not much I can do about that.

There are other options for using these machines, but really, I think the Beowulf cluster is the most interesting of ideas. I have a laptop that I use for testing different operating systems and such, I think I will use it as the master node in the cluster. This would remove the need for any keyboard, mice or monitors, since the three nodes would be headless and the laptop would be used to manage the cluster. The laptop also has both an Ethernet connector and wireless, so the Ethernet connector can be used to communicate with the nodes, while still having access the rest of my network and the internet via wireless. I can also setup network sharing on the laptop to provide access to the nodes for updates and such.

At the moment, I am waiting on the 2 power supplies and a network switch. I expect to have those by Wednesday and after that I will begin setting up Skynet.

Sunday, May 23, 2021

Thoughts on the Raspberry Pi aftermarket

 I have owned many raspberry Pi's over the last decade. For the most part I have been pretty satisfied with them as development and project platforms. The Raspberry Pi is well thought out, well designed for its purpose and is well supported by both the manufacturer and the community that has grown around it. What I have not been satisfied with is the third party hardware market that has popped up.

Let me say upfront that not all the hardware I have ordered over the years has been terrible, some of it has worked perfectly. However, the vast majority of these things have failed in some major way making the product either barely usable or not usable at all. Case in point, I recently bought a HyperPixel 4" screen from a company called Pimoroni. This product came highly recommended and was well reviewed and the instructions for getting it working were on the surface fairly easy.

My problems with this device started very early, at first, it would flash on for just a second and then the screen would go blank for no apparent reason, the Raspberry Pi was working fine, I could plug it into the HDMI and get video fine, I could plug other devices into the GPIO and get it working perfectly fine. After 2 days of troubleshooting this, I figured out that the I2C drivers interfered with the screen working properly, when ever those drivers polled the GPIO pins the screen would blank and not come back until a hard shutdown occurred. Completely disabling I2C and SPI on the system made it slightly better, as I could then use it for several hours before the screen blanked. There was absolutely no mention of this problem in any of the documentation anywhere, nor was there any mention of the problem on the Pimoroni forums. I thought maybe I simply had a bad screen, maybe it was just sensitive to the voltage being put out by the GPIO, so I put in an RMA request and pretty quickly, I received a replacement, same exact problem. At this point, I just gave up on it.

Again, if this had been the first time I received a half ass product, I probably would not think much about it, but over and over it has happened. It is a really sad state of affairs when I can jury rig something up on a breadboard from spare parts that works better than the professionally built version. Unfortunately I do do not have any good advise on how to tell the good from the bad here, these crap devices are often well reviewed and have very few publicized problems. All I can really say is, if you can build it yourself, do it, if you can't, well, "May the buyer beware!".

As a side note, if you are looking for a 4" screen for a Raspberry Pi, Miuzei makes a pretty good Touchscreen that works as promised with very few issues, my only real issue with it, is it does use the HDMI port, but that is not a show stopper, it just adds a cable I was looking to avoid.

Sunday, May 9, 2021

Building a PC

I do not build computers very often, my daily driver is an Alienware and I am not ashamed of that. The fact is, I am generally too lazy to build out a PC to my spec, when I can generally just go buy a pre build with 99% of what I want at the time. This is not to say I have never built a PC, I have in fact build probably 50 or 60 computers over the years, I simply do not do it anymore. The last time I build one was when I needed a system to run my website on and I needed a lot of memory to run multiple virtual machines and a redundant RAID array, this was perhaps 6 or 7 years ago

A bit more than week ago, I was on vacation and having lunch with the wife where she works. I noticed an older Pentium brand processor sitting on the shelf for about $70, more out of curiosity than anything I asked what type of CPU it was, the wife said it was an Intel G4400 dual core 3.3 Ghz Processor that had been sitting in inventory for over 2 years and she would make a deal with me if I bought the MSI B250I Motherboard they had on the shelf for, that had also been sitting on the shelf for awhile. So I said, sure throw in some RAM and lets see what the bugger costs, it came to just over $200 with 8GB of Crucial 3200 RAM. Not too shabby really. I of course still needed a case and storage, so when I got home I went on Amazon and found a nice small form factor ITX case, yes, the motherboard is an ITX board. The motherboard supports an M.2 card for storage, so I decided to grab a 256 GB SSD M.2 card, with shipping and handling, it came to about $120 total.

I got the case and m.2 card on Wednesday and was ready to put it all together. Two things I already had, was a 1 TB hard drive, that I intended to use as a 2nd drive to install games and store data. The second thing is I decided to use an old AMD R 5440 I had laying around. My experience with integrated video has never been good and with the current pricing of decent video cards being nothing less than outlandish, I figured this was a better option than not. The one thing I lacked was a copy of Windows 10. Yes, I know, I am a Linux guy, but I decided I should probably have at least one system in the house that ran Windows 10. However, for the moment, I decided just to install Linux on the thing until I decided where to get a copy of Windows from.

Assembly of the system took me maybe 20 minutes, sans cable management. System posted on the first power up, and I was mildly proud of myself. The install of Linux took another 20 minutes, and dame that SSD is fast, the fucking machine literally boots in 5 seconds. The next day, I looked around for what a copy of Windows would cost me, which was somewhere in the $130-$140 range, I was not thrilled about this, since that would constitute 25% of the cost of the machine. After thinking about it, I decided to sacrifice the Windows 10 virtual machine I had, that I never really used for anything. I removed the registration key from it, deleted the VM and then used it to activate windows on the new system. 

Keep in mind, this is not supposed to be a power house machine, it is supposed to be an adequate secondary machine. I am pretty satisfied with this build, it has a low profile, it is quiet and it is reasonable fast with the M.2 card in it and even the 1TB spindle drive is not terrible.

Edit for update 12/12/2021:

Since I put this system together I have been on the hunt for a brand new in box low end video card for a reasonable price. Unfortunately that has not been easy, the only thing really available in the sub $100 range has been GT 710 Nvidia cards, which were total junk 10 years ago when they were first released. The lowest acceptable cards I could find like the GT 1030, were still going for at least a $150 and that was more than i was willing to spend for a slightly less junk video card. Best Buy had a Christmas sale and I was finally able to get a GT 1030 for $100. So I think for the time being, this system is done.

Thursday, March 11, 2021

I do stupid things sometimes

 I have been using Linux for decades. At this point I have it down pretty well, even to the point where it is easier than Windows 10 for me. Sometimes I get bored with the "It just works" shit I take on a task just because it is hard. If you have been reading this blog for any length of time, you have seen me switch Linux distributions, and even try out FreeBSD.

This wee, my project has been trying out tiling windows managers. Normally I just use Mate, which is pretty straight forward and not too different from using Windows, although it is far more configurable. A tiling window manager, to quote Wikipedia, is 

"a tiling window manager is a window manager with an organization of the screen into mutually non-overlapping frames, as opposed to the more popular approach of coordinate-based stacking of overlapping objects (windows) that tries to fully emulate the desktop metaphor."

Something like this:


In other words, instead of windows floating all over the place, the windows are nicely lined up, wasting no desktop space. The really nice feature of most of these tiling windows managers is they are light on resources. When using Mate, it is not unusual for 5GB of RAM to be in use at any given times. While using one of these, I have never seen RAM usage climb above 1 GB. Of course there is a trade off in functionality and ease of use. Of course this was not about functionality or ease of use, this was about abusing myself. I tried two of them out, DWM and 13, compared to Mate, neither were great, but one was definitely better than the other.

DWM is made by the Suckless organization, I have some really bad news for them however. DWM does not suck less. I get it, these guys want to build light weight tools, with a minimum of features. Okay, got it, but seriously, it should not be necessary to recompile from source code to change the colors of the tool bar. In fact any changes at that you might want to make, require you to change the source code and recompile. Apparently, to them, this is a feature, not a bug. In my mind, reading and writing a configuration file would not be a terrible leap in bloat. To their credit, they do provide patches for the more popular modifications people make, unfortunately, it is exactly no ones job to maintain these patches, and I found 80% of them I could not even apply the patch without jumping through hoops and when I did get the patches installed properly, many of them  failed to function properly. So after fucking with this for 2 days and getting little more than a basic install working, I decided this was a non starter.

i3 is slightly better in terms of configuration. They at least understand the utility of a configuration file to make small useful changes. Mind you it took me the better part of a day googling things to finally get a usable desktop so it was not all fun and sunshine, however once I figured out the basic syntax of the config files, it was relatively easy to add functionality. I would not consider i3 to be easy by any means, but it sucks less than DWM. The thing i3 really had over DWM, is once I got everything setup more or less the way I wanted it, it was pretty easy to save the config files and write a script to automate installing all the needed software and placing the config files where they needed to be, so duplicating my setup on another system would be trivial.

Overall, I am a bit meh! about this whole tiling windows manager thing. I like the idea of this kind of organizational structure and desktop management, but honestly there is no reason why it should take 7 hours setting up a decent working desktop with my preferred colors, properly sized and readable fonts that do not make my eyes bleed, and some useful applets like WiFi, Battery and volume control. Now that it is done, I will probably use it for a while, but if I ever decide to seriously change windows managers, I will choose one that has a setup wizard, not one that requires me to know that #012FFF is the hexadecimal value of my favorite shade of blue.

Thursday, March 4, 2021

RE: Raspberry Pi 400

 One of the things I thought I'd talk about with this machine is configuring it to do something useful. On the outside this appears to be pretty easy, the basic Rasbian boot image pretty much has everything you need to be reasonably productive. The problem is, I don't particularly like the basic setup or the choices of applications. On top of that, I prefer Ubuntu to other flavors of Linux, so I wanted to start there. The basic Ubuntu desktop never appealed to me, Gnome 3 is just not my thing and on my desktop, I use Mates. There is a Mates version I can use, but I wanted to do something a little different. The Raspberry Pi 400 is a pretty decent machine and is very capable of running Mates, but it is still somewhat constrained my modern standards and i have no desire to overclock it, so the less resources the windowing system uses, the more resources I have available for applications and multitasking.

My choice for Window Manager is Dynamic Window Manager (DWM), it is the core of the Suckless Desktop, whose design goal is simplicity in desktop design. The whole thing runs on less than than 300K of memory. It does have some limitations and irritations, but the trade offs are acceptable. DWM is very configurable, but this requires you to recompile it to even change the default color scheme and upgrading it, forces you to make all the changes again before doing so. This is a no thanks for me, the default colors are fine, all I really want to do is change the background and that is easy enough without recompiling anything. So I will simply be using apt-get to install and update it.

I will start off with the Ubuntu 20.04 Server image, I choose this because it does not have xorg or graphical applications preinstalled, it is totally command line and is a blank slate for our purposes. I am a lets script this shit kind of guy, so that is what i did, I created some basic config files to get me started and write a shell script to install the software I regularly use, so once I get Ubuntu Server installed, updated and a new user created, I simply copied all of these files, plus the image I wanted to use as my background, over to my home directory via ssh and ran the setup script.

Some notes about what I did here. I removed snap because i have found snap applications run significantly slower than the normal repository versions, so I remove it to keep from accidentally installing from the snap store. I removed gdm3, because I want the system to boot into text mode by default, I will start DWM manually when I need it. You will note that I have two fairly complete sets of applications, text mode and GUI, I would say I am in the GUI 80% of the time, but I do have a bit of a fetish for the command line and sometimes I will spend a lot of time working in text mode only, and this gives me both for when I am in one of those moods. To answer the obvious question, yes I can be fairly productive at the command line, about the only things I can't do is play videos and the internet experience is less than optimal.

Well that is it folks, I have posted all the files below, so you can use them as a template for yourself so you can customize your setup without too much fuss.

Setup script:

#!/bin/sh

# Update the system
sudo apt-get update

# Install text mode applications, tools and libraries
sudo apt-get install mc links cmus htop neofetch wordgrinder emacs-nox tmux alpine sc finch tpp net-tools i2c-tools build-essential -y

# Install GUI and applications, tools and libraries
sudo apt-get install xorg dwm suckless-tools dmenu feh rxvt-unicode firefox thunderbird gnumeric abiword pidgin pluma audacious vlc -y

# Clean up
sudo apt autoremove --purge snapd -y
sudo apt purge gdm3 -y
sudo apt-get autoremove -y
sudo apt-get clean

# Copy config files and fix some things
cp x.tmux.conf ~/.tmux.conf
cp x.xsession ~/.xsession
cp x.Xdefaults ~/.Xdefaults
mkdir ~/pictures
cp background.jpg ~/pictures
sudo cat wifi.txt >> /etc/netplan/50-cloud-init.yaml

 .tmux.conf file

# loud or quiet?
set -g visual-activity off
set -g visual-bell off
set -g visual-silence off
setw -g monitor-activity off
set -g bell-action none

#  modes
setw -g clock-mode-colour colour5
setw -g mode-style 'fg=colour1 bg=colour18 bold'

# panes
set -g pane-border-style 'fg=green bg=white'
set -g pane-active-border-style 'bg=green fg=white'

# statusbar
set -g status-position top
set -g status-justify left
set -g status-style 'bg=green fg=white'
set -g status-left ''
set -g status-right '#[fg=white,bg=black] %d/%m #[fg=white,bg=black] %H:%M:%S '
set -g status-right-length 50
set -g status-left-length 20

setw -g window-status-current-style 'fg=white bg=black bold'
setw -g window-status-current-format ' #I#[fg=white]:#[fg=white]#W#[fg=white]#F '

setw -g window-status-style 'fg=white bg=green'
setw -g window-status-format ' #I#[fg=white]:#[fg=white]#W#[fg=white]#F '

setw -g window-status-bell-style 'fg=white bg=green bold'

# messages
set -g message-style 'fg=white bg=green bold'

 .xsession file

# set background image
feh --bg-scale ~/pictures/background.jpg

# puts a clock in the upper right hand corner
(while true; do xsetroot -name "` date +"%I:%M %p %D"`"; sleep 5; done ) &

# starts DWM
exec dwm

 .Xdefaults file

URxvt*termName: rxvt
URxvt.buffered:         true
URxvt.background:       black
URxvt.foreground:       green
URxvt.cursorColor:      green
URxvt.underlineColor:   red
URxvt.scrollBar:    False
URxvt.perl-ext:         default,matcher
URxvt.urlLauncher:      /usr/bin/firefox
URxvt.matcher.button:   1
URxvt.transparent:    True
URxvt.shading:        50

 wifi.txt file to setup wireless

    wifis:
        wlan0:
            optional: true
            access-points:
                "Access Point SSID":
                    password: "Password"
            dhcp4: true

Tuesday, March 2, 2021

Raspberry Pi 400

Recently I bought a Raspberry Pi 400. This is a neat little device, basically it is a Raspberry Pi 4 (RPi) built into a nice slim white keyboard. Like the RPi, it has GPIO headers for attaching interesting devices like sensors, servos or small LCD panels. It is powered off a USB-C connector, it has 2 Mini HDMI ports so you can run 2 monitors on it and has USB3 ports. The most important thing about it is the 4 core ARM processor that runs at 1.8Ghz and it has 4 GB of memory, which mean it is fast enough to function as a proper desktop computer.

Now, would I use this as my main computer? Probably not, but as a backup machine, why not. If I were buying a computer for a kid, this would definitely top my list, coming in at $70 for just the system itself. A more complete kit with power supply, Mini HDMI cable, mouse and an SD card preinstalled with an OS is about $100. It does all the basic things a computer needs to do, surf the web, check email, basic document creation, plays MP3's and videos with very little trouble.

There are a couple of downsides as you would expect. For one the keyboard is a bit cramped, I typed this post on it, and I found it to be just a little uncomfortable. It boots of an SD card, which are notoriously slow for disk access, so if you are reading and writing large files, the system will pause for a bit. i found attaching a USB3 Hard rive to it fixes that problem pretty well. Finally, this is not a problem for me, but many other people will, it does not officially run Windows. Some clever hackers have gotten Windows installed on it, but there are missing drivers, and will be missing features like WiFi and Bluetooth support. For me this was not a big deal, I am a Linux guy, so this did not bother me even a little.

Overall, not bad, the RPi 4 was certainly the best Raspberry Pi to hit the market and this does it one better by making it an integrated easy to use computer.

Friday, July 24, 2020

Simple Encryption with MMBasic

The program presented here is a very simple encryption program, one I have written several times over the years to relearn Basic. This program takes advantage of two built in functions, RND and XOR.

RND is a pseudo random number generator, I say pseudo because it is not a true random number generator. The function needs to be seeded with a number, which it then uses to generate other numbers. If you seed the function with the same number, it will generate the same numbers. To make this appear more random, Basic programmers often seed the function with the Timer function, which seeds RND with the number of seconds past midnight. In this program, I take the password entered, convert each letter to its ASCII number and add them all together and then seed the RND function with this number. The result of this is, each time you enter the same password, the RND function will use the same set of numbers to encrypt or decrypt the message.

XOR is a simple formula that always produces the same 3 numbers. For instance, 1 XOR 2 = 3, 2 XOR 3 = 1, 3 XOR 1 = 2. In this program, I am generating a number using the RND function, then I am taking the letters from the file I want to encrypt, one at a time and converting it to its ASCII number. I am then XOR'ing the two numbers, converting that number into text and writing it to a file. For instance say the RND function generates 35 and the letter from my file a small case "a". The ASCII values of small case "a" is 97. 35 XOR 97 = 33, I then convert 33 to its ASCII text equivalent, which is "!" and I write that to the encrypted file. Re-running the program, this time using the encrypted file as the file you want to encrypt, the process reverses itself. The RND function will produce the same number, 35, and it will read the "!", convert it to its ASCII value of 33, then XOR the two numbers (35 XOR 33 = 97), to produce 97 and convert this number to its ASCII text value of small case "a" and writes that to the decrypted file.



' encrypt.bas
' Uses the RND and XOR functions to encrypt text files
Input "Password: ", Password$
Print

For Count = 1 To Len(Password$)
  MyNumber = MyNumber + Asc(Left$(Password$,Count))
Next

Randomize MyNumber
Input "Enter File to be encrypted: ", FileName$
Print
Open FileName$ For Input As #1
Input "Enter the name to save the encryted file as: ", EncryptedFile$
Print
Open EncryptedFile$ For OutPut As #2
Print "Encrypting the file, please wait..."
Print
 
For Count = 1 To Lof(#1)
  Print ".";
  RealPassword = Int(Rnd * 126) + 1
  Temp$ = Input$(1,#1)
  Encrypt = RealPassword Xor Asc(Temp$)
  If Encrypt < 1 Then Encrypt = Encrypt + 126
  If Encrypt > 126 Then Encrypt = Encrypt - 126
  Encrypt$ = Chr$(Encrypt)
  Print #2, Encrypt$;
Next Count

Close #1
Close #2
Print "Done"
Print
End

Okay, let me make this very clear, this is not a strong encryption by any means, in fact by today's standards, it is barely encryption at all. A low level NSA mook could break this on his coffee break, and even a scrub hacker could break this in an hour using his grandma's computer. The only person this will protect you from is your 12 year old sister, and I would not even bet on that.

The point of this program is simply to teach the basics of encryption, using functions readily available in the Basic programming language. The security can be increased by building your own equivalent functions to RND and XOR using more mathematically complex and security sound formulas. You could also use the RND function to find a location within a key file, say a jpeg image, and use the bit at that location to XOR with the letters needing encrypting and save the file as a binary file rather than a text file. The point of course is, this is just a starting point.

_______________________________________________________________
Edit:
The reason this is not considered secure encryption is because the possible combination of numbers is low by the standards of modern computing. We have three numbers, the psuedo random number generated by RND, the ASCII number of the letter to be encrypted and the ASCII number of the encrypted letter. In theory, this gives us 126x126x126=2,000,376 possible combinations, this is a pretty big number, but not a huge number when you consider that an old 1.8Ghz desktop computer can execute 1,800,000,000 computations per second, that means it takes about .001 seconds to go through all of them for a single letter, that is not much. Now, the reality is, we already know 1 of the three numbers, the encrypted letter, so all we have to do is find the other two, now we are only looking at 128x128=15,876 combinations, now we are talking .000009 seconds for each letter. So the file you are trying to protect would have to be gargantuan to take any significant amount of time to break.

Tuesday, July 21, 2020

Colour Maximite Thoughts

Recently at the Backshed forums, which is the primary community for the Maximite system, a user suggested a database library which could then be used to develop database applications. There was a minor discussion about it, but ultimately there was simply not enough interest in the project and the original poster ended the discussion with some snark, saying

"It doesn't look like very many people see a need for it and are interested in using it. I certainly am not going to bother writing it if nobody wants or needs it. No matter, the CMM2 will do a great job of teaching youngsters how to fire bazookas at boogymen and androids."

While I cannot fault him for the statement,  I think the real problem is the OP's fundamental misunderstanding of what the Colour Maximite series of machines are really being used for. The Maximite is not a desktop computer, it is not the type of machine you use to surf the web, check your email and create documents. Even the newest version is based on a 400Mhz ARM processor and has only a few megabytes of RAM. On top of that, MMBasic is not a true operating system, it is a programing language that serves some of the functions of an operating system.

What the Maximite is, is a development platform that falls somewhere between an Arduino and a Rasperry Pi. The end goal for these things is to provide an environment similar to that of a Commodore 64 and other computers of its era.Additionally, a set of GPIO pins have been provided so the hardware can be extended with relative ease. It is far more flexible than an Arduino, as well as easier to use. It is also far less daunting than a Raspberry Pi for small projects and does not have the overhead of a full blown Linux operating system.

If you go back and look at what people were using those Commodore 64's for, it was not writing letters, doing homework or tracking receipts, although I suspect many parents were convinced to buy them for these purposes. No, the primary use for those machines was to play games. Almost every kid who had one of these machines, also learned to do at least a little bit of coding in Basic, because you pretty much had to to use the bloody thing.

The Maximite is no different, no one is going to develop productivity applications for the Maximite, not even a simple text editor. It is not because it cannot be done, it can be. The problem is, there is no point, in this day and age, virtually everyone has a desktop computer at home. Don't give me any bullshit about some people cannot afford computers, which is true, but if you cannot afford a computer, then you sure as shit cannot afford a Maximite and you should be using that money for food and rent. But seriously, what is the point of developing a database library for the Maximite, when I have several good options available to me on my desktop computer. I don't need the Maximite for productivity applications, I already have a computer for that stuff. Those wheels have already been invented and they are running on hardware that is superior to the Maximite by several magnitudes.

The last thing I have to say about this is, if the OP wants to develop a database library for the Maximite, he should go a head and do it. However, he should do it because he has a use for it and because he wants to do it and because he will enjoy doing it. Ultimately basing his decision to do it or not on whether or not other people needed it, tells me even he did not think it was a great idea, otherwise he would have just done it.

Saturday, July 11, 2020

My Basic Programs for the Maximite


I have started placing all the basic programs I write for this website on my Google drive and made it public. This is for those of you who do not want to type them in by had. Personally, I think you should type them in by hand, especially if you are just learning to program in MMBasic. Typing in the programs is a good way to start learning and retaining computer programing. Besides that, most of these programs are fairly short. So if you have been following my tutorials and such, the programs are here;

Google Drive Link

As I progress, I will add more to the drive.

The Practical Maximite Part 3

In this tutorial we are going to learn how to take advantage of the Arduino compatibility of the Maximite. All of the Colour Maximites have the headers, but not al of them have the sockets soldered in. Mine came with the sockets, if yours did not, you will have to stop here.

When I was making the choice as to what Arduino hat I wanted for my Maximite, it was actually a pretty easy choice. An LCD hat gives you another readable output, which is good for a number of things like error capturing when debugging programs and providing secondary information. These also provide you with a set of buttons that you can use to trigger events. The hat I got can be found here; 16x2 LCD Keypad Shield 1602. These hats are made by many companies, are readily available and are cheap, since you can generally get them for under $10. Make sure if you are buying one of these from a different manufacturer, that is is built on a HD44780 LCD chip, MMBasic has built in support for this chipset.



There are a couple of caveats with these hats, first, there is a reset button, this is handy for resetting your Maximite if, like me, you do not have a power switch. The downside is, if you accidentally press it, you will loose any unsaved programs you have in memory, so be careful and save often. Second, there is a select button, this does not work, it is hooked up to the 5 volt rail, but I have no idea what Pin it is connected to. Lastly, if at first you cannot get anything to display, the contrast is probably set way too low. The contrast is controlled by a screw on top of the blue plastic thing in the upper left corner of the hat. Give the screw 10 complete turns clockwise, and that should make your text become visible and you can adjust to taste from there.

 Now, lets get on with doing useful things with this hat. I am sure the first thing you want to know is how do you get text on the screen. The first thing you must do is initialize the LCD by telling your program which pins it will be using to communicate, 99% of the time, this is d4,d5,d6,d7,d8,d9 and this is done by simply adding "LCD INIT d4,d5,d6,d7,d8,d9" to the top of the program. Next we issue the LCD command, the first number tells the Maximite which line to print the text on (1 or 2), the second number tells the Maximite what position in the line to put the text (1 - 16), this is then followed by the text you want displayed. The following program displays "Hello World" followed by the date.

'lcdtxt.bas
LCD INIT d4,d5,d6,d7,d8,d9
LCD 1,1,"Hello World"
LCD 2,1, Date$

That is the easy part. The next thing we want to do is make the buttons do something useful. All of the buttons are connected to Pin 35, when in use, Pin 35 will constantly output 3.3 volts, when one of the buttons is pressed, that voltage is reduced and the button can be determined by the voltage. Unfortunately, the voltage differs from board to board, which means you need to determine what these voltages are. The following program configures Pin 35 for Analog Input, this is so we can read the voltage being put out by the pin. The program then starts polling the pin, if no button is pressed and the voltage is 3.3, it does nothing, because no button is being pressed. If the voltage drops, meaning a button is pressed, it prints the voltage on your monitor. Press each button and make a note of the the output for each button.

'bttnvolt.bas
SetPin 35,AIN

Main:

  Volt = Pin(35)
  If Volt <> 3.3 Then Print Volt

GoTo Main

My results were Left=2.01, Right=0, Up=0.49 and Down=1.26, the numbers actually went out 5 decimal places, but don't worry about that. The Right button is easy, Voltage is 0. Left and Down are both fairly close to 2 and 1 respectively, so by using the Int() function, I can round those values down, without worrying about minor variations in the voltage. Up is a bit more complicated, for this, I need to check to see is the voltage is less than 1 and greater than 0, not tough, but something you have to pay attention to. Putting this altogether, the following program configures Pin 35, initializes the LCD, and displays "LCD Button Test" on the first line. The program then polls Pin 35 for a button press and the displays on the second line which button was pressed. The trailing "*" are there simply to make each string the same length, and no characters are left over from the last button press.

'bttntest.bas
SetPin 35,1
LCD INIT d4,d5,d6,d7,d8,d9
LCD 1,1,"LCD Button Test"

Main:
  Volt = Pin(35)
  If Volt = 0 Then LCD 2,1, "*Right"
  If Int(Volt) = 2 Then LCD 2,1, "*Left*"
  If Int(Volt) = 1 Then LCD 2,1, "*Down*"
  If Volt < 1 And Volt > 0 Then LCD 2,1, "*Up***"
GoTo Main

If you have the LED's from the previous tutorial still connected, you can use the buttons to blink the LED's.

'bblink.bas
SetPin 12, DOUT
SetPin 13, DOUT
SetPin 14, DOUT
SetPin 15, DOUT
SetPin 35, AIN
LCD INIT d4,d5,d6,d7,d8,d9
LCD 1,1,"LCD Button Test"

Main:
 Volt = Pin(35)

If Volt = 0 Then
    LCD 2,1, "*Right"
    Pin(15) = 1
      Else
        Pin(15) = 0
  EndIf

  If Int(Volt) = 2 Then
    LCD 2,1, "*Left*"
    Pin(12) = 1
      Else
        Pin(12) = 0
  EndIf

  If Int(Volt) = 1 Then
    LCD 2,1, "*Down*"
    Pin(14) = 1
      Else
        Pin(14) = 0
  EndIf

  If Volt < 1 And Volt > 0 Then
    LCD 2,1, "*Up***"
    Pin(13) = 1
      Else
        Pin(13) = 0
  EndIf

GoTo Main

________________________________________________________

Here are some useful programs for handling the LCD Hat.

'bloff.bas
' This turns the backlight off
SetPin31,DOUT
Pin(31) = 0

'blon.bas
'This turns the backlight on
SetPin31,DOUT
Pin(31) =1

'lcdcls.bas
'This clears all text from the LCD
LCD INIT d4,d5,d6,d7,d8,d9
LCD Clear

Mastodon