Thursday, May 14, 2020

Handy way to skeleton code a needed function in C#, so you can build without errors.

So I developed this technique years ago whilst Java was my primary coding language.  It's a great way to put a place holder method in while you're still writing code in another class or method.  I'm going to use C# today as that is primarily what I am coding with these days, and when I start talking about Asp .Net Core development that will be the language we will be using.

So if I need to place a call to a method that I haven't written yet, what I will do is quickly code a skeleton first like this.

public int myMethod()
{
    int returnValue = 0;



    return returnValue;
}

This way I can keep coding my main section as I want without Visual Studio, or Visual Studio Code complaining about a non-existent method call. Also, it will enable any test builds. This is especially useful for Asp .Net Core projects that involve Entity Framework as you need to be able to build to perform migrations or database updates.


Take care, my nerds!!!

Monday, May 11, 2020

Handy mkdir tip!

Greetings fellow nerds!!!

I thought I would make a short post with a quick tip for you.  I recently discovered this while building Linux From Scratch.  I noticed this syntax being used with the mkdir command, and have found it extremely useful for one line set up of directories for development.

You can create multiple directories from one mkdir command.  I strongly suggest using the -v switch for verbose output so you can see the results of all the directory makes to make sure everything work properly.  So the trick is to use the curly braces {} and you can list comma-separated directories.

So for instance when I've initially created a directory for a dotnet project, here's what I do for making all my required subdirectories.

mkdir -v {Controllers,Models,Views,Views/{Home,Shared},wwwroot,wwwroot/{css,js}}

Notice you can nest the curly braces.  So this creates 4 folders under the current directory: Controllers, Models, Views, and wwwroot.  It also creates 3 subdirectories under Views: Home and Shared, and finally 2 subdirectories under wwwroot; css and js.

Bonus Tip: There is a way to continue a command in bash. You leave a space and then the \ character followed by a new line.  If you are writing this in a shell script it can make things easier to read.

So in this example:

mkdir -v {Controllers, \
          Models, \
          Views, \
          Views/{Home, \
                 Shared},
          wwwroot, \
          wwwroot/{css, \
                   js}}

Very powerful, and time-saving approach to your Gnu/Linux use!!!

Ciao for now!!!

Nerdtek

Thursday, May 7, 2020

Gnu/Linux Installs

So during my Linux From Scratch tangent, I installed several Gnu/Linux distributions to see which one would suit my purposes out of the box.  I found that two distros were the easiest to work with.  Although for one my definition of easy, and a new user to Gnu/Linux's would differ.  ;-)

I settled on two distros to use.  The first one I tried that is perfect for someone who doesn't want to have to configure too much to get the build environment going was OpenSuse.  I remember trying this distribution 15 years ago or so and loved it.  Yum is a great package manager, and really easy to use and customize your system with.  In fact, package management is one of the things that set the two distros apart.  The other distribution I settled on and will be using for my tutorials is Arch Linux.  I love how hands-on it is, and I was able to customize my environment with ease.

I learned some tricks to install Arch and since it's more hands-on than OpenSuse I figured I would share some tricks with you.  Big ups go to Abhishek Prakash for his post at the excellent It's FOSS blog, and Mohd Sohail and his post on linuxandubuntu.com.  I am going to put together my two takeaways from their walkthroughs in this one.  Abhishek's suggestion of optimizing the mirrors using reflector, and Mohd Sohail's excellent description of using cfdisk, or cgdisk to set up the partitions.  These tools are way easier to use than fdisk or parted.

*** edit ***
I forgot to mention the first source you should check.  The Arch Linux Installation Wiki.  The two additions to the instructions that I have added, aren't mentioned in the installation instructions. The partitioning information is just guidelines so you can customize it the way you like, and the reflector usage is just to optimize your mirror choice for quicker package downloads.  No matter what though always check with Arch's installation guide first to make sure my instructions regarding the other steps are still relevant.

So first things first, we need to obtain the latest iso of Arch.  We simply need to go to the Downloads section of Arch's website.  There are a plethora of choices to download.  I chose a direct download from a mirror that is consistently fast for me.  I downloaded my Gentoo stuff from the same mirror when I was installing Gentoo.   Once you have downloaded the iso file you can verify its correctness by  entering the following:

$ gpg --keyserver-options auto-key-retrieve --verify archlinux-version-x86_64.iso.sig

There is a windows port of gpg, but I'm not going to get into how to use this on Windows.  Google is your friend.  ;-)

Now you need to make your installation media bootable.  We do that with the command dd.  

The if= argument takes the location of the iso file you downloaded.  So for example: 

if=/home/nerdtek/Downloads/archlinux.iso

The of= argument takes the drive, not the partition.  So for the first drive, it would be of=/dev/sda as opposed to of=/dev/sda1
The bs= argument refers to the bitrate of this operation.  So the example is suggesting 4 MB/s.

# dd bs=4M if=path/to/archlinux.iso of=/dev/sdx status=progress oflag=sync

So next you need to insert your media and reboot your system.  Some systems may require you to access the boot menu via f12 or similar button during boot post.  Shortly you should see the installation media boot screen:

Arch Install Boot Screen


You will get a plain terminal and a prompt:
root@archiso ~ #


The first thing we need to do is partition the drive.
So we either need to use cfdisk for a system that does not UEFI enabled, or cgdisk for a system with UEFI enabled.

I will first show the non-UEFI system.  Click here for the UEFI enabled system.

First, we need to see what the system sees the drive we want to install Arch on is called.  
So we run  fdisk -l


So in this instance, we can see our drive is /dev/sda.  More than likely this will be the case in your case as well.  So now we will need to figure out what partitions we would like to make.  
  1. /dev/sda1 This will be the /boot partition that will hold our kernel images and grub.cfg.  We will make this 200 MB in size.
  2. /dev/sda2 This will be the swap partition and we will make this of memory up to a max of 2 GB.
  3. /dev/sda3 This will be our / root partition
Some people like to separate the / root partition and make a separate /home partition.  This makes moving your /home folders to a new system easy.  The drive I am installing on is smaller than 30 GB so I am not going to bother.

So we start up cfdisk with cfdisk /dev/sda remember to change the sda if your drive has a different designation.


Choose dos as the label type.  'gpt' is for UEFI enabled systems.  On the next screen select New.


Next, change the default size by typing 200M.


Select Primary on the next screen.


Selected bootable in the next screen, and you will notice that there is an asterisk under the boot column for /dev/sda1.


Move down to the Free space and select new.


We will make the next partition the swap partition so that it will be half of RAM up to a maximum of 2 GB.  So in my case, I set my swap to 2 GB.



Next,

we need to change the partition type to 82 Linux swap / Solaris.


Next select write from the main menu and type yes


Now quit.  We need to create our file system, and then we will be ready to move on to the next step.

If you don't need the UEFI enabled system instructions then skip to the Creating filesystems section.

For UEFI enabled systems we run cgdisk instead of cfdisk.

# cgdisk /dev/sda (or whatever drive you are installing to)

A warning pops up, it is safe to ignore this.  Just continue to the next screen.



So the difference when creating these partitions is the bios partition has a type of ef02.  Unlike with cfdisk, it will prompt you for the type when creating a new partition.
So the procedure is:

  1. Choose +1M as the second sector selector, the type will be ef02, and the name will be 'bios'
  2.  Choose +200M as the second sector selector, the type will be 8300 (default), and the name will be 'boot'
  3. Choose +{half of ram up to 2G max} with the appropriate M or G after the amount, the type will be 8200 for Linux swap, and the name will be 'swap'
  4. Choose the defaults for sectors, the type will be 8300 (default), and the name will be 'root'

Select write and then type 'yes', then quit

Creating Filesystems


We need to create an ext2 filesystem on /dev/sda1, a swap filesystem on /dev/sda2, and an ext4 filesystem on /dev/sda3.  (remember to substitute the appropriate drive designation if you are not installing to /dev/sda)

The drives will be slightly different for the UEFI enabled system.  /dev/sda2 for /boot    /dev/sda3 for swap    and     /dev/sda4 for /   root.


We will come back to the drive.  Now we need to optimize our set up of pacman the package system that will install the operating system and any tools we might need along the way.

The first command we will run will synchronize the repository information that is stored, which will be as of the date on the install iso.  Usually the first of the current month.  

Type pacman -Syy to accomplish this.

Next, we need to install reflector.  Type pacman -S reflector
Next, we run reflector with

reflector -c "CA" -f 12 -l 10 -n 12 --save /etc/pacman.d/mirrorlist   substituting your country code for the "CA".

Now we are ready to continue with our newly formatted drive.

The first thing we need to do is mount the root partition and the boot partition.

Type: mount -v -t ext4 /dev/sda3 /mnt

Next, we need to create the boot directory on our newly mounted partition.

mkdir -v /mnt/boot

Now, mount the boot partition at /dev/sda1

mount -v -t ext2 /dev/sda1 /mnt/boot

Now, it is time to bootstrap our system onto the drive. This is accomplished with the command pacstrap


# pacstrap /mnt base linux linux-firmware vim nano links dhcpcd

This tells the bootstrapping program to load the base system, plus firmware and some needed utilities.  'vim' and 'nano' are text editors (you only need to install one), links is a terminal-based web browser, and dhcpcd is so we have internet once we reboot.  This command will take quite some time to complete.  After it completes, it's time to generate the fstab and chroot into our new system.  Setup the fstab file, locale, timezone, and networking information.

So the first command we type is: # genfstab -U /mnt >> /mnt/etc/fstab

Next, we need to chroot into /mnt:  
# arch-chroot /mnt

Timezone


We need to set up a symlink to the appropriate timezone info at /etc/localtime.  To figure out what your Region and City specifiers are you can run # tzselect so in my case, my Region is America and my City is Toronto.

# ln -sf /usr/share/zoneinfo/Region/City /etc/localtime

Next, we need to synchronize the clock by creating the /etc/adjtime file.

Run # hwclock --systohc

Localization

Edit the /etc/locale.gen file and remove the # for the locales you wish to enable plus en_US.UTF-8

Next run # locale-gen to create the locales, and create the /etc/locale.conf file with

# echo 'LANG=en_CA.UTF-8' > /etc/locale.conf

Network Configuration

Create the hostname file

# echo {your desired hostname} > /etc/hostname

Edit the /etc/hosts file
127.0.01   localhost
::1        localhost
127.0.1.1  {your desired hostname}{fqdn} {your desired hostname}

The fully qualified domain name doesn't have to be registered, it's just that some software will not work correctly if this is not set.  I use nerdtek.example.com myself.

So my last line would be 

127.0.1.1 nerdtek.example.com nerdtek

Root Password


# passwd


Grub

Install grub:

pacman -S grub

# grub-install /dev/sda

# grub-mkconfig -o /boot/grub/grub.cfg

Gnome

Install the Xorg server, selecting the default choices.

# pacman -S xorg xorg-server

Install Gnome, once again selecting the default choices.

# pacman -S gnome

Now enable the network manager service.

# systemctl enable NetworkManager.service

Leave the chroot environment

# exit

Shutdown the system.

# shutdown -h now

Once the system is shut down remove the install cd/USB key.

Startup the system again booting into your newly installed operating system.

Create a new user.

# useradd -m {desired username} -s /bin/bash (or if you prefer the default of /bin/zsh)

Set a password for your new user with: passwd {desired username}

Turn on the Gnu Display Manager service.

# systemctl enable gdm.service

Reboot your system into your graphical login and desktop environment.
# shutdown -r now



Once into the Gnome desktop go to settings/displays, and update your screen resolution.





Enjoy your new Arch installation!!!

Until next time...be cool my fellow nerds!!!!

Thursday, April 16, 2020

Squirrel!!!!

So I have been sidetracked somewhat.  Not to worry though the Asp .Net Core 3.1 development walkthrough is coming.  I have a nice setup on my system now and I think it's working as well as can be expected.  The only annoying part is there's no automated way to make a dev cert on Linux machines as the dotnet command-line interface is missing this command.

I have begun working through Linux From Scratch. Although I have bootstrapped a Gentoo system before, the thought of doing everything from scratch is really appealing and I want to give a try. I will let you all know how it goes in the upcoming weeks.

Sunday, March 22, 2020

I'm back!!!!

So it's been a while...almost 7 years actually.  Life got busy in the past 7 years.  I was separated, got a new position at work, and of course, I have been a happy little code monkey as well.  I definitely got a great grasp on C# and ASP .Net Core.  So much so that my Java skills which used to be more forté are not even remotely up to date.  I have found that Microsoft's .Net has matured to the point now where it doesn't make sense to ignore it anymore.  I find that PHP is too hard to work with, although it is a fairly robust platform (Wordpress for eg).  Ruby on Rails is another popular framework but it is rather slow.  JSP is definitely still a very robust platform but the hosting options are not as ubiquitous as the other options. 

So I am going to try a little experiment which I will start talking about in my next post.  I am going to try and develop an ASP .Net Core 3.1 MVC Web Application on Linux.  I am using Ubuntu 19.10 (Eoan Ermine) on my laptop and have tested it out I was able to get a small sample app to run.  Pretty cool.

Also on more physical experimentation things, I intend on trying an experiment in a leather alternative.

Stay tuned, my intent is to start posting regularly.  Since I have some topics that will involve regular posts, there should be more content here in the future.

Until next time my fellow nerds!!!

Friday, May 24, 2013

Learning C#

So I decided to finally take the plunge.  Despite getting a sneak preview of C# way back in 2000-2001 I never really learned it.  I delved into .NET programming a bit but only from an ASP and C++ perspective.  We have need of a utility at work, and I have already built one in VBA on top of Excel 2007.  To say it's quirky is a bit of understatement.  I've decided to build it again as a stand alone app and learn C# while I'm at it.

After all the issues I had with VBA and different forms I'm going to use a MVP framework called MVC#.  This should make keeping track of authentication and any persistent data fairly easy.

The program is to manage medication administration records at work.  This way we can generate them rather than typing them up every time, and gives us a record of what a particular client had received in the past.  Since we will be dealing with sensitive client information that must remain confidential I will have to add encryption to the data.  Rather than use SQL I want this to be easy to deploy since we don't usually have administrator access at work.  I will use flat files to save all the information, and the "database" will be just the model component of the Model View Presentation framework.

So I will post more details in my next post.  Until next time.

Nerdtek out!

Sunday, December 2, 2012

Medieval Tech






So I'm part of the Society for Creative Anachronism and have a few projects on the go currently. I will be detailing my progress in this blog as I progress. Currently I've already made a maille coif. My current projects are small mead, gruit, (I love brewing!) A maille hauberk. A gambeson and a bow and arrows. The project that I'm currently working on is a batch of small mead.

So here's the modified recipe that I've used. This is based on the original medival (well Elizabethan actually but close enough)

1 kg Honey
7 1/3 l water
1/2 tsp Ale yeast
1 1/4 Tbsp Ginger
3/5 Tbsp Orange peel
14 or so resealable bottles (I used old Grolsch bottles but you can use pop bottles with twist tops too.)
Cheese cloth
Fermenting bucket (must be food grade, and not metallic. I use an ice cream bucket)

So combine the honey with the water in a stock pot. Heat the mixture up carefully watching it, as if it boils over it happens fast. Keep a rolling boil going and spoon off the scum from the top when the total volume is reduced to about 5.56 litres then it's time to add orange zest. Zest 3/5 Tbsp of orange peel carefully avoiding the white part of the peel into a few layers of cheese cloth. Tie the cheese cloth and place in the pot. Continue to boil for 15 minutes (this is the last 15 minutes of the reduction) grate the ginger and add to an additional cheese cloth. Add the ginger at the last minute of the boil. The reduction should take 2 to 3 hours depending. Don't forget to continually remove the scum from the top. It should be clear by the time the mixture has been reduced. Transfer the mixture (including the two cheese cloths) to your primary fermenter. Cover the fermenter with a clean tea towel and allow mixture to cool. Once the mixture has cooled to luke warm take a hydrometer reading. Make note of your initial reading as this will give you your approximate final alcohol content. Pitch the yeast into the fermenter and cover with the tea towel again. Check every day until the specific gravity has lowered to approximately 1.004 +- 0.0005. At this point transfer the mixture to the bottles. I usually syphon the mixture to do this most effectively although you do want some of the yeast to transfer to the bottle to carbonate your mead. After 3 or 4 days refrigerate your mead. It will be drinkable in a week, but will taste better if you age it a bit longer.

One thing to keep in mind is sterilise all your utensils and containers. I use a steriliser that I obtained from my local brew supply store.

Step 1. Add honey and water to stock pot and bring to a boil.
Step 2 - with 15 minutes to go add the orange peel wrapped in cheese cloth to the mixture.
Step 3 - zest orange peel and add to a few layers of cheese cloth and tie off the cloth.
Step 4 - at the last minute of boil add the orange peel to the pot.
Step 5 - Transfer the mixture to the fermenter (in this case an ice cream tub)
Step 6 - Once the mixture is luke warm sprinkle the yeast into the mixture.
Step 7 - After 24 hours push the cheese cloths down into the mixture to get the yeast off of them and take a specific gravity reading. In the case of this batch mine was 1.054. Make sure to note this reading some where as you will need it later.