Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Thursday, December 19, 2013

How I use Virtual Machines

So sometimes it's nice to have custom environments to play with "new" toys. For example I decided the other day I wanted to install Ruby and play with it. Of course I can download the installer (if i'm using windows) or sudo apt-get install, however what happens when I forget about it and don't want to play with it anymore, do i want to deal with the hassle of uninstalling? Do I want to leave it and let it bog down my PC? of course not. So this is where virtual machines come in. Virtual machines can be costly in terms of space though, so today I'm going to teach you about linked clones.

Here is what I did.

I bought a Sandisk Cruzer Extreme (these things rock).

1. Download the ubuntu Server instance (this will keep memory low)
2. Install VirtualBox.
3. Create that virtual machine and install (pointing to your usb drive, or if you already have an SSD then that I suppose).
4. Basically we want a very minimal install, so don't put any of the LAMP stuff in, basically if it says "Hey should I install this extra wiz bang thing?". Say no
5. Install samba (sudo apt-get install samba)
6. Setup a configuration similar to the following:
    6a. Create a folder (whatever you want to name it) in your home folder.
    6b. chmod the shared folder to this:  sudo chmod 777 folder
    6c. Update samba configuration (from /etc/samba/smb.conf) replacing path with the folder you created in 6a.
 
7. Once that was all setup, I start making linked clones for various tasks, I.E. Ruby Machine, NodeJS Machine, etc (be sure that network is set to NAT, in this case I have a HTTP Proxy that is a hassle, so this is my workaround, you may have a better way and I'd love to hear it.)
  7a. So select your Ubuntu Server, right click clone,
  7b. Give it a good descriptive name when it asks,
  7c. When prompted select LINKED clone, this gives you a standard setup, but clean environment!
8. Logging in I see that occasionally my network takes FOREVER to come up, so that's because of some oddball thing so remove this file and it should resolve it, you're welcome to google around but you'll probably find that deleting this file is the solution:
sudo rm /etc/udev/rules.d/70-persistent-net.rules
9. after installing everything you need. halt the machine, shut down, and change the network adapter to Bridged, boot your VM up again, your local machine should be able to see the samba drives at \\\shared_folder (or whatever you called it in the smb.conf file).

Now whenever you want to work, you can startup the Linked Clone and start playing (and reference the folder you setup so you can work from your local machine with all your custom setups, just to play).


Thursday, November 5, 2009

Design and Programming..a Love affair

Let's take a look at design.

If you design your project well, looking at all possibilities up front without coding a single thing you can catch some problems up front that you may run into. One of those may cause messy or unneeded code! That's again the beauty of the artist they can choose whether they want to keep repainting the exact same thing or really go out there and paint something new!

What all can be designed?
For Microprocessors where you have a limited number of register's to use, defining a personal/project standard allows greater code re-use, as well as less code and easier to understand code.

If you define a register as the UART pointer from the beginning and make sure not to change it, you won't have to constantly be re-writing the code to setup a pointer. How many times does that have to happen? Well if everytime you have to drop into your interrupt service routine and determine whether it was a RX or TX bit that sent you running, that's 2 times for every "interrupt". I know it doesn't sound like alot of time, but when you run into a situation where your time is critical, 2 instructions can make that difference.

The short time that it takes to design your project, can multiply the rewards exponentially.

Deciding how you want to setup each module is part of design, would you rather setup the entire initialization in your main routine for each module, and let that handle everything OR modularize everything and put ALL uart related items in the UART section.

This brings up the good point of .include files, by putting all your setup into a .include file, you can now start using that file in new projects and rather then constantly having to re-write a subroutine you just write it once, and any improvements you make are better for all programs, (provided they are in fact better). Writing this I already see a flaw in the design of the program we made in our latest lab!

Guess what? Looking back on it, I realize we have a file called variables that contains the ".set" items that point to the UART and all other associated names, this means that every file that I try to .include the UART routine into has to have the entire variables file included, Guess what we did that with a "register setup file too!!!".

How can this be improved?

I can put all registers that the UART EXPECTS to use in it's .include file as part of the initialization, and make sure that any time I use that file those particular register's are in that state before the subroutine is used, this can occur by pushing the register settings to the stack before any updates to them, then reverting them back, will allow the subroutine to keep using them as expected.

If there is one thing I'll stress, Try to make your code as uncomplicated and easy to understand for yourself and others, Implementing a design can aide in that.

Let me know how you design!!

Tuesday, July 28, 2009

Learning Ada

I'm getting the opportunity to do some work in ada so I'll note some things I've learned as I go along, they may be common knowledge to some people, but they're new to me as I am learning.

Yesterday I learned how to declare a record and how to assign values to the items in the record, there are 2 ways (that I currently know of).

Pertaining to a record that contains the items animal and fish:

1. Assign individually:
     Albuquerque.animal := ("cow");
     Albuquerque.fish := ("trout");

2. Assign them as a group:
      Albuquerque := (animal => "cow", fish => "trout");

Tuesday, May 5, 2009

Command Prompt

I frequently find myself needing access to the command prompt when I'm inside a folder, one of the ways I do that is:
1. Click start
2. Click Run (or alternately to get to this Windows Key +R)
3. Type cmd
4. Then Type cd
5. Then drag the folder of the location I want into this window
6. Hit enter (ok so not literally, I didn't hit it)
Today, I'm going to introduce how to use the right click menu to make life easier for those (in windows) to be able to jump to command line pretty easily,

1. Open an explorer window, this can be accomplished by either pressing "Windows key + E" or just opening a folder.
2. Select Tools Folder Options,
3. Click the Tab File Types
4. Select Folder
5. Select Advanced
6. Select New
7. For Action name, Just name it something you'll remember like "command prompt"
8. For the application used to perform this action enter cmd.exe /K cd %1
9. Select Ok's to exit.
10. Try it out, now go to a folder and right click on it and select whatever you named your action.

Time to explain what I had you put in the application used to perform.
cmd.exe opens your command prompt, /K means "run the following" and the following is cd %1, cd means change directory, and %1 means what was passed to the command in this case the folder location (I.E. c:\New Folder).

I hope this helps some people out there, let me know how it works for those of you who try it!!!

Thank you for reading my first "real" post.