rails date/time formatting string cheat sheet

(click for .pdf version)

project euler - problem 1 solution [c++]

#include <iostream>

using std::cout;

int main()
{
int number = 0, sum = 0, i = 0;

for ( i; i < 1000; i++ )
{
if ( ( number % 3 == 0 ) || ( number % 5 == 0 ) )
sum += number;
number++;
}

cout << sum;

return 0;
}

Good news, everyone!

mbp+boxI’ve got some projects that I want to work on and I felt that my current setup (OS X 10.4 on a mac mini + ok-but-not-great monitor) was holding me back.  It was time to do something about it, so I went down to the Apple store and bought a new macbook pro.  It’s fancy, it’s fast, and I love it.  Now i have no excuses keeping me from starting the many projects that i’ve been whining about not being able to start because of “equipment problems”.

a new hope…

a note...okay.  i get it.  i’ve been hearing the same thing from several distinct sources, and they’ve all been telling me that writing on a (semi-) regular basis is important.  apparently, it’s the only way to be both a better writer and a better programmer (more on that later).  so now, as part of starting the new year in the right direction, i’m going to fill in some of the blanks since last posting in may.

if you’ve been reading my dispatches for a while now, or if you take a minute to browse through the archived offerings, you’ll notice a pattern.  lately, the posts have increasingly focused on geekery.  this is a reflection of the changes in my circumstances as well as a change in my fixations.

i spent the last few years working off-and-on while taking some math and science courses part-time.  most of the jobs i had tended to be either boring, monotonous, or unfulfilling.  after years of procrastination, distraction, and indecision, i decided to apply for admission into the computer engineering program at concordia university.  last july i received my offer of admission while finishing the last prerequisite course.

the program is a mix of math, programming, and electronics: subjects i’ve found fascinating although not always my strongest.  my classes are interesting and challenging- the exact opposite of my previous school and work experiences- and exactly what i need.  after getting through a rough introductory semester, i can say that this is one of the better decisions i’ve made.

since i’m already preoccupied with programming and nerdy computer stuff, and there are tons of projects that i intend to start (and hopefully finish), this blog is increasingly going to reflect that.  i’m going to share what i’m working on- i hope mostly non-school projects- and what i am getting into.  later this week i’ll be attending a conference about software engineering, CUSEC, so expect a report of my experience there or at least a brief rundown of my impressions as a start to this new year of consistent posting.

procrastination as inspiration

i’ve been working on some more objc stuff lately. i followed along with become an xcoder which finally, at least for me, made the connection between interface builder- and things like IBOutlet, IBAction, and custom classes that seem to be missing or glossed over in other books that i’ve read- and xcode. as a follow up to my last post , i just wanted to mention that i’ve finished two mini objective-C/cocoa apps. these aren’t terribly complicated, and were just a smidge more challenging than a command-line tool, but fun and instructive anyway.

first one was a test to see if i could write something from the ground up that actually worked. surprisingly, i could and it did. so the second one was made a bit more useful- it calculates squares and roots of a given number. if the number does not have an integer root, it will display the closest integer root, as well as the square of that calculated number. sounds more confusing to describe than it was to write. if anyone wants to give it a go, here it is:

solo

(obviously it will only run on OS X- just drop it in your applications folder.)

this just brought me a huge step closer to finishing that homework machine i dreamt up a few months back.

rails/mysql makeup post

remember a few days ago when i was complaining about my difficulties getting rails set up and running?  well, here’s how it all turned out.

the error i was getting (”Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock”) was caused by two things:

  1. i forgot to start the mysql server before trying rake, and
  2. i didn’t edit .bash_profile correctly.

the first thing to fix was pretty obvious- start the mysql server from within system preferences.

after doing that, i got the inspiring “rake aborted!  Unknown database ‘demo_development’” error.  as i was going step by step through one of my many sets of installation instructions (this time browsing through Beginning Rails), i realized i didn’t have a .bash_profile file and that i may not have actually created a database.  i thought i remember adding it when first setting up this project, but it wasn’t there.  this was fixed by creating the file and adding the line “export PATH=”/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH” ” and then creating a database with “mysqladmin -uroot create demo_development”.

crossed my fingers, gave rake one last go, and all is now well.

ps.  yes, this post is partially a reference for if when i screw this up again.

rails hates me

As this blog seems to be turning into a ‘time capsule’ of sorts, this post seems appropriate.

I’ve been having some difficulties lately.  While trying to get ruby on rails set up on this computer (running OS X 10.4.11) I’ve hit a few snags.  but first, some background.

I started into rails because I knew it was the next step i had to take.  from clarisworks (remember that?) way back when to html tables to xhtml and css, now i need to add a new layer.  i have a few things that i want to build that go beyond the interactivity that javascript can offer (college students, check back here in early september,) and rails seemed like the quickest way to get that done.

maybe i just don’t know what i’m doing, but after trying several times, i get stuck at “rake db:migrate”.  i tried reinstalling mysql and using a different server and still nothing.  all i see is the same error “Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock”.  sounds simple enough, right?  it probably is, but i still can’t figure out how to make this shit work.  once i get past this, i’m going to look back and feel pretty dumb.

any suggestions?

update: problem fixed.  details here.

10 minutes

this is going to be a ten minute post- hopefully it will be a meaningful 10 minutes.

up until last night i had a problem. i’m working on a project. it’s a website that plays video. the page is simple- it only has the title banner across the top, the main div where the video goes, and a few navigation links under that. what i needed was a way to switch between videos without reloading the page, just the div. flash is out of the question- i work only with xhtml, css, javascript, and php.

after some googling, i came across this. for some reason, i knew as soon as i saw this that it was exactly what i needed. after a little more inspection, these two lines confirmed it:

xmlhttp.open(”GET”,url,true);
and
onload=”loadXMLDoc(’test_xmlhttp.txt’)”

i noticed that the source for the text swapped into the div was a text file. up until this example, all the “div content swap” solutions i found used text that was in a preloaded div with display:none; to keep it hidden until whatever action called it. it didn’t seem to be a far stretch to change that path to that text file to the path to the videos i was using.

the fact that the second argument passed to the xmlhttp.open() function is actually called “url” confirmed it. i just needed to provide it with the url i wanted.
this is where the functions that i had previously written came in handy. instead of calling the loadXMLDoc function right away, clicking on the previous or next function calls would generate the correct path. instead of loading the contents of “test_xmlhttp.txt”, the
function would load the correct path. ie “http://…1.html” or whatever. it was just a matter of changing the last line of the script to pass the correct url to the function.

here’s the rest of my javascript.

var videoNumber = 1;

// initialize first video
// to http://…whatever…/1.html

var path = “http://…whatever…/videos/”;
var extension = “.html”;

function nextVideo(){
if (videoNumber < 3)
updateNumber(videoNumber += 1);

// increment current video's number,
// pass value to updateVideo()

else updateNumber(videoNumber = 1);
}

function previousVideo(){
if (videoNumber > 1)
updateNumber(videoNumber -= 1);

// decrement current video’s number,
// pass value to updateVideo()

else updateNumber(videoNumber = 3);
}

function updateNumber(currentVideoNumber){
var newVideoAddress = path + currentVideoNumber + extension;

// create new video’s address
loadXMLDoc(newVideoAddress);

// pass address to reloading function
}

weird how those two scripts seem like they were written to work together. comments and critiques are always welcome.

ps- i removed the actual path for now. it wasn’t the final one anyway. i’ll be sure to mention once this is good and ready.

pps- this took me 17 minutes to write.

thunderstruck

i don’t know what to do.  i think it may have something to do with the thunderstorm.  at least that’s what the physicist guy from my work tells me.  but he’s kind of weird.

i probably should have posted this a week ago, but i’m that lazy.  i plugged my external hard drive into my computer and, horror of horrors, i got nothing.  no icon on the desktop.  the little power light was on, i could hear it spinning, and i doubt there’s anything wrong with both of the firewire ports on my computer, so i’m not really sure what to say.  i just really can’t have that drive die on me.  i got it four years ago, so it has a ton of old stuff-  recordings of me playing guitar, old pictures of me and my shitty old band, a few websites i had built, old receipts and financial records (still haven’t done my taxes this year), ALL of my music, and worst of all- my secret project.  i had been working on some stuff and a redesign of this dated monstrosity.

now what?  try to take it somewhere to get fixed?  it almost seems like that would be admitting defeat and the possibility that i may never get my shit back.  so instead i’m going to give him a beer and hope he comes around.

finally.

i just had to post these links. now if only someone would get started on experimenting with adding tails. i would love to be able to have a tail ‘grafted’ on. a monkey tail of course, so it could be like an extra hand or i could even help me balance when i’m drunk.

pushing the limits of what can be done with eyeballs is cool and all, but what i’m really looking for are retinal implants. i know the basics can be done now, but i want infra-red, heat and night vision, and superhuman zoom.

ps- i have no idea what’s up with the formatting in the previous post and i’m too lazy to fix it.