I decided recently that it'd be valuable to keep a running list of things that I've learned in the web dev world (or software engineering more broadly). I took inspiration from Meagan Dunham who posts an update to a thread about something they've learned every time they figure something new out. It's great, so I figured I'd emulate a bit by making this a featured post that I update periodically.


1. File Reading & type width in C

I was working through CS50's problem set related to recovering JPEG data from a borked .raw file. I was looking through the blocks like this:

FILE *file = fopen("filename", "r");

// allocate a block of length 512 (one jpg unit/thing)
int block[512];
fread(&block, 512, 1, *file);

printf("I expect a value here that is one byte: %i", block[0]);	
// actually yielded 0xffd8ffe0

Wait a second, I asked for 1 byte and you gave me 4. The problem here is that an int is actually 32 bits (4 bytes). Check out this C Reference for deets.

The 32-bit int data type can hold integer values in the range of -2,147,483,648 to 2,147,483,647.  You may also refer to this data type as signed int or signed.  

Solution was to use something smaller like unsigned char. voila.


1. Reverse DNS

Recently I was tasked with learning Scala in order to work on some of our back-end work at McGraw-Hill. Someone mentioned "Reverse-DNS" in reference to why the module we were working on was nested 30 bajillion folders deep. I was only used to hearing DNS referred to in the web, so hearing it as a naming convention was odd to me. So essentially it looks like this:

├── main
│   ├── resources
│   │   └── datafiles
│   │       └── lookups
│   │           └── v1
│   ├── scala
│   │   └── com
│   │       └── mhe
│   │           └── measures
│   │               └── delivery
│   │                   ├── avalon
│   │                   │   ├── dataservice
│   │                   │   ├── db
│   │                   │   └── schema
│   │                   ├── dataservice
│   │                   │   ├── habitat
│   │                   │   └── lookups

Damn that's long and confusing, but I understand the value of avoiding naming collisions, so I guess we're even?

2. Getting a Postgres version using a query

SELECT version();

Returns the detailed version from whatever host you're connected to :).