Logo suggestions

As I mentioned earlier, I was asked to come up with a few logo design suggestions for a real estate project my employer had.

These are a few of the suggestions I came up with:

 

Affinity Designer is Fontastic!

A few weeks ago, I was asked by my employer to come up with a few logo ideas.
While designing one logo I thought I’d design the characters myself.

I liked how the letters came out and thought I’d continue working on these to make a font, so I used it as an opportunity to get familiar with the FontForge program.

Using this I made a simple sans-serif Font by exporting individual SVG files per glyph and importing them into FontForge.

The True Type Font can be downloaded here: http://www.tcarisland.com/fonts/Montebello.ttf

 

At the moment I have yet to begin kerning the letters and make any special characters and punctuation. I haven’t inserted the “bold” version of the font either, but it’s a start.

MontebelloFont

Write in C

The last couple of months has been all about Calculus, Agorithms and Datastructures, Data modelling with Object Role Modelling and SQL.

After finally getting familiar with the basics of PostgreSQL I found myself curious about using the MySQL databases supplied by my web hosting service, and today I got around to making a program to insert .csv files (with whitespace as delimiter) into my own tables.

As an added challenge I thought I’d use C rather than Java, which means I had to use sscanf instead of split to collect individual integers from an input file separated by whitespace.

This bit of code reads an input file, calculates the size of the file, the number of rows and columns and then proceeds to read the entire file. It then uses sscanf to collect each integer now that we know the number of rows and columns and then creates an sql script based on that information.

There’s probably an easier way of doing this, but in my experience, always looking for shortcuts takes time, so I might as well just use what I know already to get the job done:

 


#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#define max(a, b) ((a) > (b) ? (a) : (b))
#define pline printf("\n")

void tsize(char filename[], int ans[]);

int main(int argc, char *argv[]) {
if(argc < 4) {
   printf("too few arguments");
   return -1;
}
char *typename = argv[3];
int tablesize[4];
bzero(tablesize, sizeof(int) * 4);
tsize(argv[1], tablesize);
int row, col, i, q, inp, siz, pos, totalpos;
row = col = i = q = inp = siz = pos = totalpos = 0;
col = tablesize[0];
row = tablesize[1];
siz = tablesize[2];
int table[row][col];
FILE *in = fopen(argv[1], "r");
char *text = malloc(sizeof(char) * siz);
bzero(text, sizeof(char) * siz);
while((inp = fgetc(in)) != EOF) {
   text[i++] = inp;
}
fclose(in);
for(i = 0; i < row; i++) {
   for(q = 0; q < col; q++) {
      int val = 0;
      sscanf(text + totalpos, "%d%n", &val, &pos);
      totalpos += pos;
      table[i][q] = val;
}
}
FILE *out = fopen(argv[2], "w");
fprintf(out, "CREATE TABLE rammepris (\n");
fprintf(out, "meterpris INT NOT NULL,\n");
fprintf(out, "halvmaal INT NOT NULL,\n");
fprintf(out, "utpris INT NOT NULL,\n");
fprintf(out, "rammetype VARCHAR NOT NULL UNIQUE,\n");
fprintf(out, "PRIMARY KEY(meterpris, halvmaal)\n");
fprintf(out, ");\n");
for(i = 1; i < row; i++) {
   for(q = 1; q < col; q++) {
      int meterpris = table[i][0];
      int halvmaal = table[0][q];
      fprintf(out, "INSERT INTO rammepris(meterpris, halvmaal, utpris, rammetype) \   
      values(%d, %d, %d, %s);\n", meterpris, halvmaal, table[i][q], typename);
   }
}
fclose(out);
}

void tsize(char filename[], int ans[]) {
FILE *in = fopen(filename, "r");
int col, inp, siz;
col = inp = siz = 0;
while((inp = fgetc(in)) != EOF) {
   ans[2]++;
   if(inp == ' ' || inp == '\n')
      col++;
   if(inp == '\n') {
      ans[0] = max(col, ans[0]);
      col = 0;
      (ans[1])++;
   }
}
fclose(in);
}

Read More …

Piping to stdout and file simultaneously

Just another note to self here:

./[program] [arguments] | tee [filename.txt]

Run program with arguments, use pipe “|” and the program named “tee” to output do both stdout and a particular file. Great for logging terminal programs.

Flags:

  • -a Appends the output to the end of File instead of writing over it.
  • -i Ignores interrupts.

Since it’s a GNU-core utility, “man tee” gives a manual of the program.

 

Ljusterö

I just recently spent a few days at the island of Ljusterö just outside of Stockholm.

Since I’m still waiting for my DSLR-charger I chose not to bring it, and as luck would have it, I had to take these shots using my cell phone camera.

Still I find myself pleased with the results, so here goes…

More Barcodes

I’ve been working more with my barcode application and am finally close to a working solution.

Adding start and stop characters is more or less dependent on which charset you want to use, unless you’re going to use special characters or some other special functionality, you’ll be using Code128 B – which supports most normal alphanumeric characters and punctuation characters in the ASCII table. The rest is just basic String concatenation, which you can do in LibreOffice Calc or through programming.

The first stretch was developing the checksum method in Java, which was pretty easy thanks to the information provided by wikipedia here.

What I did was simply to make an array with the characters listed for Code 128 B, disregarding special characters since I won’t be using them anyway. The array looks a little something like this…

private String code128B_table[] = {
" ","!","\"","#","$"," %","&","'","(",")","*","+",",","-",".","/",
"0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?",
"@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P",
"Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_","`",
"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p",
"q","r","s","t","u","v","w","x","y","z","{","|","}","~","DEL","FNC3",
"FNC2","ShiftA","CodeC","FNC4","CodeA","FNC1","StartCodeA","StartCodeB","StartCodeC"
};
private String code128_table[] = code128B_table;

With the Array in place, all I needed to do to calculate the checksum was write this method:

/**
* Calculates the checksum
* @param input String input for calculating checksum
* @return the checksum in integer form
*/
public int checksumInt(String input) {
int checksum = STARTCODE;
for(int i = 0; i < input.length(); i++) {
int value = charNumber(input.charAt(i));
if(value < 0)
return value;
int position = i+1;
checksum += (value * position);
}
return checksum % 103;
}

/**
* Helper function for checksumInt
* Finds the number of the particular character using the Code128B table
* @param c
* @return
*/
public int charNumber(char c) {
for(int i = 0; i < code128_table.length; i++) {
if(code128_table[i].charAt(0) == c)
return i;
}
System.out.println("Could not find " + c);
return -1;
}

But wait, there’s more. The checksum itself isn’t enough, it needs to be in the form of a character, but since we already have the table for Code128B in array form, we just convert the integer to character for printing.

/**
* Converts calculated checksum into character
* @param i calculated checksum
* @return character for printing checksum
*/
public char checksumChar(int i) {
if(i < 95)
return (char) (i + 32);
else
return (char) (i+ 100);
}

Since the computers come with Norwegian keyboards and the barcode scanner will read barcodes as if receiving keyboard input, I had to do a few cheap hacks to remap the characters according to Norwegian keyboards, this isn’t a problem with alphanumeric data, but characters like { [ ] and } will read on a computer set with  a Norwegian keyboard layout as receiving the letters Æ Ø and Å or some other character because of this, I made a function with way too many if/else tests rather than using a HashMap or other key-value pair since it just seemed simpler to write at the time.

The class file is available on github here.

Beginning Barcodes

About a year ago, I made a bit of an impulse buy on eBay and purchased a barcode scanner for a little less than a dollar (little did I know that shipping and handling would cost me 9 dollars more, but 10 bucks isn’t really anything to worry about).

BarcodeScanner

Why you ask?

Because for some reason I thought it might be a good idea to have a barcode scanner available so I could learn a bit about programming applications using barcodes.

What have I learned so far?

Well there’s a lot of talk on how you need permission to use certain barcodes. Especially EAN and UPC seem to be regulated if you want to distribute your product, but EAN is only the tip of the iceberg.

Some of the simplest barcodes to work with today can be installed as fonts and these include Code 39, Code 93 and Code 128.

But you can’t just download a font and think it’ll work like that – barcodes usually need some way of knowing where to start and stop reading, so the name “Studio Black” would have to be written “ÌStudioÂBlack{Δ to work in Code 128.

Luckily, several websites, like this one, can help translate for you.

So how does this work?

Barcodes are actually an incredibly simple and efficient input method and isn’t really all that different from a computer keyboard. Think of it as a mix between a keyboard and a scanner. When it reads any barcode it supports, your computer will pretty much only act as if it received keyboard input in the form of a string or number.

Some barcodes support alphanumeric data (like Code 39 and Code 128), which means it can contain both text and numbers, while others are simply numeric (like EAN and UPC).

Because of this, programming an application that reads barcodes require next to nothing extra and you can probably just use the same old text fields and forms as always. The USB barcode scanner I have is pretty simple to use and drivers were as easy and automatic as when connecting a keyboard or mouse – just plug and play.

In the long run, the biggest hassle is probably getting familiar with the legal issues of it all.

You can find the fonts for the different barcode systems:

Here: Code 39

Here: Code 93 and

Here: Code 128

As of yet I’ve had the best luck using Code 128, with the type of barcode scanner you can find for about 10 bucks off eBay. My model is called X-9100 and works like a charm.

By the way, make sure to never use bold or italic with barcode fonts, they mess up everything.

Mounting shared folder

mkdir ~/Documents/VBShared


#!/bin/sh

mount -t vboxsf VBShared /home/$USER/Documents/VBShared

Save this as a file, such as “mount.sh”

$ chmod +x mount.sh

$ sudo ./mount.sh

I’m writing this as a reference for every time I make a new Virtualbox guest linux machine

Install guest additions.

Make sure settings have a shared folder set with automount enabled.

Run script at startup.

 

For systems without an X-Server:

Make sure sufficient packages are installed. Build essential is useful.

Click on “insert guest additions CD image”

sudo mount /dev/cdrom /mnt
sudo /mnt/VBoxLinuxAdditions.run

Sudoku

Finished the Sudoku-puzzle solver about two weeks ago, I might publish part of the solution later on when the course is finished, but at the moment here’s a few snapshots of how it looked like.