Blog
1 2 3 4 5 6  Next»

Fun with Pointers (or maybe Fun with Engineering Students) – September 20, 2016

I was a teaching assistant for 18-349, Introduction to Embedded Engineering for three semesters in college and I really enjoyed it.  One semester, the professor asked each of the TAs to create a test problem, and I had quite a lot of fun with that, though my students didn't.  Only two students out of 100+ got it entirely correct, though maybe 30% got most of the problem correct.  Students always have trouble with pointers, and understanding how their are addressed, de-referenced, etc.

Here is the problem (note that you are at a disadvantage compared to the students because they should have known what size integers and integer pointers are):

Playing with pointers with ARM 7

Given: 

int str[10] = {0,1,2,3,4,5,6,7,8,9};

int i, j, tmp;

int *K, *L;

 

For the code examples of A, B, C, and D below, mark which samples correctly reverse the order of "str".  If not correct, explain why for each such sample.  Assume 32-bit words.

A. for (i=0, j=9; i<5; i++, j--){

tmp = str[i];

str[i] = str[j];

str[j] = tmp;

}

 

B. for (i=str,L=i+36; i<L; i=(int*)i+1; L--){

tmp = *(int*)i;

*(int*)i = *L;

*L = tmp;

}

 

C. for (K=&str[1]; L = &str[10]; L-K+1 != str[9]; K++, L--){

tmp = *(K-1);

*(K-1) = *(L-1);

*(L-1) = tmp;

}

 

D. for (K=&str[0], L=K+9; K<L; K++,L--){

tmp = *K;

*K = **(&L);

*L = tmp;

}

 

The reason for the test problem is that I saw students writing things like *&var and if it didn't compile, add another * or & until it did, but without any understanding of what those symbols actually meant.  Though almost everyone got it wrong, some students did take the time afterwards to go through the code and actually understand what was happening.  It is my belief that if you can understand these code samples, you understand pointers completely.

 

Some students objected to the answer on moral or philosophical grounds, and I think the professor didn't end up weighting this question all that much when he scaled the grades.

One student went to office hours with the professor and managed to convince the professor that I was wrong, but I met with the student and we typed it into a compiler and ran it so he could see how it worked.

Note that I'm not saying this is the right way to write code.  Also, note that despite this test problem, students always rated me really high on the evaluations...

Planet Memory Review – March 17, 2014 (read more)

I have a server that is apparently considered "old", as in, the RAM in it is old enough that manufacturers aren't making much of it any more, and so the prices are starting to go up.

I had purchased the machine only half full of processors and RAM with the idea that it would be a cheap upgrade later once I needed it.  I'm getting to the point of "needing" the upgrade, and so went out looking for the parts.

The processors were easy enough to come by, but the RAM was not, and the brand new price of the RAM sticks (4GB, ECC, Buffered, DDR2, 800Mhz) was up around $50-$100 a stick, but I found them on Ebay from PlanetMemory for much cheaper - $16!

How is Lime Daley Like a Trappist Monk? – January 19, 2014

While the headline sounds like it might be the beginning of a bad joke, the Trappist Monks from Moncks Corner, SC were mentioned in a sermon this morning, and so I thought I would look up the article referenced, as it sounded pretty good: The Business Secrets of the Trappist Monks.

The article might be long for some of you, so I'll quote the highlights (though you should at least go read the seven bullet point "secrets").

I can think of no business mission more lofty, soft and abstract than serving God, and monasteries manage to successfully infuse this lofty mission into a panoply of niche products and mundane tasks with the kind of preternatural focus that leads to almost supernatural results.

The third element of service and selflessness is a commitment to excellence: At Mepkin Abbey every single egg is packed with a “prayerful attitude.”

This next one has happened to me.  I do wonder if people can feel good about themselves when they know they are gouging their customers.

One day I was making deliveries with Father Stan when I heard one of his buyers offer to sell Mepkin’s eggs at a premium price. Stan thanked him for his kindness but said that an “egg is an egg,” and the brothers couldn’t in good conscience sell their eggs for more than the prevailing price.

I love this next one, and I really like being able to bill hourly, rather than per-project, which is more standard in my business.  It takes so much time to quote the project, and then I have to estimate high for unexpected things, and so hourly is cheaper for the customer, and results in less boring work for me (quoting a project has to be the worst kind of work there is, though the sewer management guy at Star Island probably wins that contest).

Trust is the most powerful form of capital there is, and nothing makes a business run more smoothly than trust.

And lastly, in case this is getting too philosophical for you:

Every time I think I’m making progress I catch myself shoving some old monk out of the way so I can get that last dish of ice cream.

 

Hack the Hackers – December 20, 2013 (read more)

I have a customer who installed a machine with the administrator/root password very weak, and left it open to the internet.  Someone guessed the password, logged in, and then helpfully ran 'screen', so I could watch what he did (presumably - he might have been smart enough to do other things, and we will format the drive, but it was neat to see all of his commands, including typos, and guessing at some commands, because he must not have been familiar with CentOS).

He had a script that he ran to check out other machines around the world, simply doing a port scan, and then using ssh to try out accounts and passwords off of a statically generated list, so if you were bad enough to have the password "root" or "toor", etc. on your root account, then you get recorded.

His script generates a text file of hacked machines, so I emailed the administrators of those machines (living in Hungary, United Arab Emirates and Germany), and let them know that they have insecured machines on their network.  But, the cool part is still to come...

"What's the Worst Thing That Could Happen?" – May 30, 2013

For those of you who know me, you know I find it useful to ask the question, "What's the worst that can happen?" when thinking about whether to do something or not - particularly when it comes to a matter of walking by faith in a particular situation.  I find that the answer to that question is usually, "I could get embarrassed", or "I might lose some money", or other such things that don't matter all that much.  Every once in a while the worst thing that could happen is a bigger deal, but I find it seldom is.

I was amused to see the question asked in the Dilbert comic strip the other day.

Dilbert 5/28/2013

Archive Page for Wordpress Blogs – May 13, 2013 (read more)

A customer wanted a "site index" page for their Wordpress site, which in blog terms means an "archive" page.  You can use the wp_get_archives() function, but that doesn't give you much in the way of customization.  I thought about using the "format=custom" parameter, and try to parse the information afterwards, but that seemed like a pain, so I threw away that function call, in favor of calling get_posts, and then doing all of the setup myself.

Here is what I ended up with (note, I'm skipping the template specific stuff, you'll want to include a header, and an appropriate div, and your sidebar(s), etc. There are many sites on the internet that will show you how to create a generic archives.php template)

Changing Paths While Migrating Subversion Repositories – March 13, 2012

Note: This is extremely hacky, and you had better make sure you have a backup, as it is quite easy to wreck the repository.

Scenario:

I was moving a subversion repository from one server to another, and in the process, I also wanted to update the paths, since the first repository had been a general purpose repository, and the second was only for one particular customer, and so didn't need the extra path info at the beginning.

I started with these instructions: http://svnbook.red-bean.com/en/1.5/svn.reposadmin.maint.html#svn.reposadmin.maint.filtering and they got me almost all of the way there.  However, I had problems with one revision that contained some merge information in it.

The error I got was: pathname not terminated by :

The problem was that I had replaced:

Node-path: SAMS/framework/mine
Node-kind: dir
Node-action: change
Prop-content-length: 90
Content-length: 90

K 13
svn:mergeinfo
V 55
/SAMS/framework/current:4-9
/SAMS/framework/tags/3.6:10
PROPS-END

with:

Node-path: framework/mine
Node-kind: dir
Node-action: change
Prop-content-length: 90
Content-length: 90

K 13
svn:mergeinfo
V 55
/framework/current:4-9
/framework/tags/3.6:10
PROPS-END

And that isn't quite right.  The key is realizing what the "V 55" part means and that is counting the number of characters that is in the next section, and since I removed 10 characters (I removed "/SAMS" twice in the same block).  Replacing "V 55" with "V 45" and tada, it works.

I suppose that the Content-length field should be updated as well, but subversion seems to be able to tolerate text changes without updating that field.

Groan: New International System of Units – April 19, 2011

A little humor for your day, courtesy of Jack Gannsle.

  1. Ratio of an igloo's circumference to its diameter = Eskimo Pi
  2. 2000 pounds of Chinese soup = Won ton
  3. 1 millionth of a mouthwash = 1 microscope
  4. Time between slipping on a peel and smacking the pavement = 1 bananosecond
  5. Weight an evangelist carries with God = 1 billigram
  6. Time it takes to sail 220 yards at 1 nautical mile per hour = Knotfurlong
  7. 16.5 feet in the Twilight Zone = 1 Rod Serling
  8. Half of a large intestine = 1 semicolon
  9. 1,000,000 aches = 1 megahurtz
  10. Basic unit of laryngitis = 1 hoarsepower
  11. Shortest distance between two jokes = A straight line
  12. 453.6 graham crackers = 1 pound cake
  13. 1 million-million microphones = 1 megaphone
  14. 2 million bicycles = 2 megacycles
  15. 365.25 days = 1 unicycle
  16. 2000 mockingbirds = 2 kilomockingbirds
  17. 52 cards = 1 decacards
  18. 1 kilogram of falling figs = 1 FigNewton
  19. 1000 milliliters of wet socks = 1 literhosen
  20. 1 millionth of a fish = 1 microfiche
  21. 1 trillion pins = 1 terrapin
  22. 1 rations = 1 decoration
  23. 100 rations = 1 C-ration
  24. 2 monograms = 1 diagram
  25. 4 nickels = 2 paradigms
  26. 2.4 statute miles of intravenous surgical tubing at Yale University Hospital = 1 IV League
  27. 100 Senators = Not 1 decision

 

Procmail Recipe to Filter Addresses in the From Field – April 12, 2011

I've noticed a common spam method lately, which I'm not quite sure what the idea is since it is so obviously spam, and trivially filterable that it doesn't seem like it will last very long, but a couple have ended up in my inbox, and since I really don't like emails in my inbox I decided I would write a filter to keep this type out.

:0:
* ^From:[^@]+@[^@]+@
spam/mail

Pretty simple - just look for multiple @ signs in the From address - I can't think of a reason why someone would do that on purpose.  Though maybe some people have "joe@example.com" <joe@example.com> as their from address - I'll have to see if it results in any false positives.

Simple TinyMCE Integration Into Moodle 1.9.x – June 24, 2010 (read more)

There are a handful of solutions out there to integrate TinyMCE and Moodle, but some of them are obsolete, and some contain all sorts of things other than the TinyMCE files.

So, I started by reading this entire page, and then figuring out which versions no longer worked, and finally settled on John Stabinger's version (link to stabinger.us was removed, since it appears the site was bought by SEO spammers), which was pretty good, though it contained a lot of extra stuff.

I've tried to keep my version pretty simple, and hopefully you'll save some time by using it.  I downloaded John's version that was built using 1.9.8 from 05/12/2010.  It merged cleanly into my 1.9.9 2010-06-09.

1 2 3 4 5 6  Next»