Friday, November 16, 2012

OpenOffice / LibreOffice Base timestamp quickie

The built-in database for these is hsqldb.

To setup an automatic timestamp when you enter data.. it cannot be done from the table design view. It must be done from within the "Execute SQL Statement" window. Go to Tools, SQL to get there. Then enter this command:
ALTER TABLE "TableName" ALTER COLUMN "ColumnName" SET DEFAULT CURRENT_TIMESTAMP

Replace "TableName" with the name of your table and "ColumnName" with the name of your column. The type of your column should be Date/Time [ TIMESTAMP ].

I find that the case of the SQL commands isn't really that important but it is very particular that you have the correct case for your table name and column name. If you have a table named Contacts, then you must enter "Contacts". It will give you an error if you enter "contacts" instead.

This will cause that column, or field, to be filled with the time & date that the row was inserted to the table. It's possible to set it to insert the time & date on an update as well but I don't need to use that as of yet.

Wednesday, September 26, 2012

Toolbox: Notepad++

Notepad++ is a program I've used a lot lately, both at home on personal projects as well as in professional work. Major features include tabs for all of your files that persist between sessions, a session manager that saves your tabs so you can switch between projects easily, syntax highlighting for quite a large number of languages, a macro system, an extensive plugin capability and much more.

I have two plugins that I use constantly. One is the compare plugin which will compare two files and show you differences between them. It can also compare a file to the last saved version of itself. This is very handy for seeing what changes have been made and can be used to normalize multiple revisions of a file.

The other plugin that I've started using fairly recently is the NppFTP plugin. It allows you to connect to sites that use ftp, ftpes, ftps, or sftp and read/save text files directly from within Notepad++. I've used this in my recent website work to edit the files directly on the webserver and then preview in my browser without having to do anything about copying files back and forth. One of the nice things is that with a very minimal configuration I can work remotely on my netbook just as well as on my main desktop. I currently have it configured to use sftp via ssh on my website development box which is an old Dell desktop running Ubuntu Server 10.04.

If you were to setup your router to let you access ssh and www externally then it would be possible to develop on the road.

The downside of NppFTP is that it is only good for editing files with Notepad++, you can't actually use it to transfer files like PDF, WAV, etc with it. At least, unless you use uuencode and somehow uudecode it on the remote end. I use coreftp to transfer files but you could use Filezilla or another client that supports the method you want to use such as sftp.

Tuesday, September 25, 2012

portfolio website Part 2

Portfolio project is going very well. I'm highly expecting to be able to launch it before the end of next week and perhaps as early as this week. Most of the content is entered into the database and I'm putting some finishing touches on the PHP code for some features I'd like to have. Some of my information is in PDF files which are as of now displayed in an iframe. There's a link above it for devices and systems that can't support showing PDF files like that. I also have a little PDF icon setup next to the link so you can see what the file type is before downloading it.

Created a simple breadcrumb functionality as well using a session variable.

Sunday, September 9, 2012

portfolio website

I'm currently working on a rewrite of my portfolio website. Started working on it Friday, September 7 and worked through the weekend. Originally, the website was written in pure HTML with CSS for styling and a little bit of Javascript. The Javascript isn't really an integral part of the website, I had a couple of samples of code running. I ought to add to that, since I've done more since then. The new website I am working in is written in PHP backed by a MySQL database. I'm excited to deploy it and I'm expecting I will before the end of the month.

My current site uses frames to separate the header and links from the content, my new one will not use frames at all. Links will be generated from a database table and the header is built into the php file I'm writing. Content from all of my pages will be transposed to the database and then the PHP file will read it and generate the page live. I know I could do this with a CMS like Drupal or Joomla, but I do like to learn new things.

The generated pages, and link to the content was very easy to do. I'm currently working on the code to pull link data from the database and generate a list of links. I've run into a couple of roadblocks and may actually redesign my table, but what I've done so far is fairly neat if I can say so.

I hope to put this knowledge to work on a couple of private projects in the future. One of the major ones I'm thinking about is a medication tracking system that I can operate from my phone's browser. Probably to track headaches. (Actual headaches, not IT headaches... I don't get those) I expect that I will learn a bit about how to write a mobile capable site and how to use forms in PHP. The other idea I had was a gas tracking system for my car. Of course, both of these will probably be behind a login screen on a private server.

Wednesday, August 29, 2012

MSP430 Morse Code in Energia

I'm cross-posting this from my Ham Radio blog: n9xlc.blogspot.com It may be of interest to anyone viewing this, my professional blog.


 Just a small project I worked on this past weekend 8/24-8/25. I have several of these cheap MSP430 Launchpad dev kits from TI. What a deal they are too, $4.30 each. I intended on configuring it to further my Kenwood TM241a project, but got sidetracked and made a program to send my callsign in Morse Code. I ended up using Energia, which is a port of the Arduino IDE but this one makes MSP430 programs. It seems most of the same commands are supported, but not all.

I really need to get setup to program in C or even try my hand at ASM. I tried ASM on the PIC microcontrollers a couple of years ago but gave up on it fairly quick. Maybe I'd do better now? I'm not sure the Wiring language would produce code fast enough to bit bang 1200 baud serial with a clock.

Code for my project is below. It would be fairly easy to modify this to make a beacon, or foxhunting cpu, or even an ID for a repeater or standalone rig. If you do something with it, I'd appreciate a link back to my radio blog, n9xlc.blogspot.com and maybe drop me a line to let me know. I'd probably write an entry about it and link to your site.

It's not technically hard to add other characters and I think it's fairly self-explanatory. I'm not 100% happy with using the IF statements to cycle through the letters. I'd be happier with an array and a For loop with an index number but this works. I tried to set up a constant type like an UIntTable to store the characters, but I only received error messages when I tried to use that. It may not be fully supported in Energia yet, or probably I didn't fully understand it.

I know I'm not the first person to do this by a long shot, but it was a fun challenge and it did help me familiarize myself somewhat in Energia, maybe next time I'll rewrite this in C? I see there are videos of others who have written Morse Code projects for the MSP430 on Youtube with a little more pizzazz than mine, such as audio out and a serial terminal for input.
/*
James Hall - N9XLC
Small program to push out my callsign via the red LED on a MSP430 board.
Developed 8/24/2012-8/25/2012

Started off modifying, then totally replacing the code in the 'Blink' example project.
This could probably be wrapped up in a function to send out arbitrary sentences.
Only enough morse code is implemented to get my callsign out, but it would be trivial to add the rest.
Could be used to blink out current temp or maybe short status info in morse code in other projects.

 http://www.arduino.cc/en/Tutorial/BitMask
 http://wiring.org.co/reference/bitwiseAND.html
 http://wiring.org.co/reference/bitwisebitshiftleft.html
 */
 #define output 2 // pin 2 has the red led on a msp430 board, pin 14 is the green led.
 
unsigned int mask = 1;
int dot = 1;
int dash = 3; //dash is equal to 3 dots
int lspace = 1; //spacing in same letter is 1 dot
int llspace = 3; //spacing between two letters in same word is 3 dots
int wspace = 7; //spacing between two words is 7 dots.

int didot = 2;
int didash = 3;
int spacems = 100; //100ms is a little slower than 20wpm (60ms) so maybe 13-15wpm?
// 10 dot, 11 dash, 00 end
// unsigned int is 16 bits
unsigned int cwN = 11; //0000 0000 0000 1011 <-read right-to-left
unsigned int cw9 = 767; //0000 0010 1111 1111
unsigned int cwX = 235; //0000 0000 1110 1011
unsigned int cwL = 174; //0000 0000 1010 1110
unsigned int cwC = 187; //0000 0000 1011 1011
byte testbyte;
  
void setup() {                
  // initialize the digital pin as an output.
  // Pin 14 has an LED connected on most Arduino boards:
  pinMode(output, OUTPUT);     
  pinMode(14, OUTPUT);
 // pinMode(5, INPUT);
}

void loop() {
  digitalWrite(14, LOW);
  digitalWrite(output, LOW);
  unsigned int cwout;
  unsigned int mask = 3;
  int callsign = 1;
  
while(callsign) {
 if (callsign == 1) {cwout = cwN;}
 if (callsign == 2) {cwout = cw9;}
 if (callsign == 3) {cwout = cwX;}
 if (callsign == 4) {cwout = cwL;}
 if (callsign == 5) {cwout = cwC; callsign = 0;}
 callsign++;

    while (cwout) {
     testbyte = cwout & mask;
       if (testbyte == 2 ) {
          digitalWrite(output, HIGH);
          delay(dot * spacems);
          digitalWrite(output, LOW);
         } 
           if (testbyte == 3 ) {
            digitalWrite(output, HIGH);
            delay(dash * spacems);
            digitalWrite(output, LOW);
           }
       delay(spacems * dot); //inner letter spacing 
    
     cwout >>= 2; 
    }
 delay (spacems * dash); //outer letter spacing

}

delay (spacems * wspace); //word spacing
}

Saturday, June 16, 2012

XCP on Ubuntu

This has been an odyssey so far. I've learned a few things too, mostly different commands related to using LVMs, and a few commands related to managing Xen/XCP via xe.

If anyone else gets into a state where XCP is stuck in maintenance mode, and the only thing it will do when you try to take it out is to tell you that the host is disabled until reboot..
Delete /var/lib/xcp/local.db
Then do: sudo service xcp-xapi restart

Bingo! (at least for me)

If you lost your guest templates, the list will be empty in XenCenter and if you do "xe template-list" nothing will appear.. do this:
run /usr/lib/xcp/lib/create_templates

If your Storage Repository won't let you create it, check to see if one exists in the LVM already and then use that one. (I may update this later with more details, this part is fuzzy now I'll have to recreate it)

The VNC session in XenCenter might not work when you use the keyboard. Don't know why, but if you close XenCenter and open a VNC session with another viewer, it seems to work. I opened one remotely from my X session and it worked fine. Although the viewer I used kept closing when the OS I was installing kept messing with the display settings.

Ubuntu 12.04 and XDMCP

XDMCP is a really neat protocol. You can use an X server to remotely connect to a linux system running it and then you can use it as if you are sitting at the system. I use it on a couple of my Linux server computers and it is incredibly easy to setup on Ubuntu 12.04.

The recent versions of Ubuntu use LightDM for the display manager. You can run a bare X windows session, but there's no easy way to start programs. That's why Window Managers like Gnome, KDE, icewm and others exist. Then you have Display Managers like xdm, gdm, lightdm and others that will give you a graphic login and the ability to switch which Window Manager you are using with a GUI.

Edit /etc/lightdm/lightdm.conf
add
[XDMCPServer]
enabled=true
That's it!

You can log in using X on another linux system, or using an X server on Windows such as Xming. I highly recommend Xming when on Windows.

Want to run the system headless? That's where you remotely access the GUI without having a local copy running.

http://lists.freedesktop.org/archives/lightdm/2012-February/000233.html

Edit /etc/lightdm/lightdm.conf
then add
[LightDM]
start-default-seat=false
Then sudo restart lightdm to load the new settings.
You'll have to login again if you were using the GUI but you will see that the server side GUI didn't start up, while you can still log in over the network. 

Thursday, April 26, 2012

BASH and PHP problem solving

I had a problem where I was trying to get a BASH script to run a backup extension on a Joomla site the other day. It was hosted on a shared server on HostGator with my only access being cpanel. For some reason my cron job wasn't firing when I thought it should. It would only work when I scheduled a recurring job every few minutes. I had to look up the PHP code but I wrote something like <?PHP echo date(r); ?> into a time.php file and uploaded it, then navigating to that location with my browser gave me the local time on the server. The server's time was 1 hour in the past which is why my cron jobs set to specific time weren't firing. I set my job to an hour in the past, and it worked that time and since.

The backup extension is Akeeba Backup. One of the features in it is a frontend triggered backup. You can set up a secret word, so just not anyone can trigger it and use something like wget to make it run. There is an integrated backup if you want to pay money for the Pro version. This way you can do scheduled backups with the free version. It's also relatively easy in BASH to delete older files. I haven't had to do anything fancy like keep certain day backups, or only keep x number of backups no matter when they were made.

Monday, April 9, 2012

A word about backups

There are a few different levels of backups:
Full - Just as it sounds, a full backup is a backup of everything. It depends on what you configure for the backup, but it doesn't exclude files from the backup set.
Incremental - An incremental backup only backs up files that are new or modified since the last backup, whatever kind of backup that was.
Differential - A differential backup will backup all files that are new or modified since the last full backup.

The major takeaway from this is that if you do a full backup, and then just an incremental for the next 2 weeks and then the system fails it's a pain to restore. Because to restore you must first restore the full backup, then each incremental in turn until you get caught up. On the other hand, consider if you do a full backup then differential backups each day for 2 weeks then the system fails. All you have to restore is the full backup, then the most recent differential. Both methods have their downsides. While incremental backups require you to restore each individual one since the last full backup, they do potentially take up less space. Differentials will continually increase in size from the point of the last full backup as new data is added and existing data is changed.

An actual backup plan would probably have a mix of backup modes with a full happening much more often. Something like doing a full backup on a Sunday, then incremental backups the rest of the week. Or possibly a differential on Wednesday. This wouldn't always be true however, if you use Amanda backup then it will schedule full and incremental backups to try to always use the same amount of space. It is very much geared toward doing tape backups, but it can also work with a disk based backup system.

Sunday, January 29, 2012

Tech blog

Welcome to my new blog. I intend to use this space to talk about various techie things. Computer hardware and software that I have installed and configured over time. Also some of my programming projects that I've done.