Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 25 Mar 2003
Offline Last Active Mar 11 2013 12:21 AM

Topics I've Started

[How] do you maintain a daily routine?

19 January 2010 - 05:39 PM

I usually waste a lot of my time on things that don't matter and as I'm getting older it's becoming a bigger priority for me to spend my time wisely. This year I resolved to get this part of my life under control. I think the best way to do it is to have a daily routine. When I tried to force a routine on myself, I realized there are three problems I need to solve: - Sometimes I just don't want to do things in the scheduled order - Sometimes other things take priority so I can't stick to schedule - I cannot force myself to have a regular sleep schedule I solved the first two problems in the following way. I divide the day into four hour chunks. The rule is, I can rearrange the tasks within a chunk any way I want, but they must be done within the designated chunk. If something prevents me from doing a task, when I get back on schedule I can drop any of the items within the chunk I'm currently in, but not in any other chunks. This way I have enough flexibility to do the things I want (or can), but enough structure that I don't lose track of things. But I can't solve the third problem. My natural sleep schedule is very irregular. If I go to sleep at a given time, I can't fall asleep, and can't wake up in the morning. If I sleep when I want, my schedule becomes very irregular (I end up going to sleep on different times every day, usually my sleep time shifting later and later into the night until I flip over). Every time I was forced to keep a sleeping schedule (for a full-time job), I have been very unproductive and miserable. This has been the biggest stumbling block to implementing a daily routine. Does anyone have a similar problem? How do you solve it? All the standard remedies (exercise, etc.) don't help me go to sleep at a regular time, and I don't want to force myself to sleep via OTC medication. Perhaps I can work around it? Or force a schedule somehow? How do you do it?

C++ template metaprogramming question

27 November 2009 - 12:44 AM

Suppose I have the following piece of code:
class foo_t
    template<typename T> void bar()
        // ...

What I would like to do is to have every instance of the bar function to have its own member variable within foo_t (or something similar, like an indexed array). It seems that at compile time I can know how many different bar() functions were instantiated, so I should be able to have a member array in foo_t, and for every bar() function I could index into that array. Unforunately I don't know how to accomplish this - I'm new to C++ template trickery. An easy way I can think of is to place a static variable within bar, but I need this to be stored per runtime instance of foo_t. Is there a good way to do this?

Scalable network/disk IO server - Linux best practices

23 October 2009 - 09:59 PM

I'm writing a highly scalable network server that needs to do a lot of disk IO. On Windows, the best way to do it is well understood - just use IO completion ports. On Linux, there seem to be a plethora of polling mechanisms, event mechanisms, etc. From what I understand the best accepted practice is to use epoll in combination with aio. Is this correct? If this is so, I plan to design the server in the following way. I'll create a thread pool of workers (equal to the number of CPUs on the machine), and a single thread to listen/accept a socket connection and transfer it to one of the workers from the pool (probably in round-robin fashion). Each worker will then have an epoll_pwait loop so that it wakes up when there is a network IO ready, or an AIO ready from disk. If there is a network IO, the thread will process it by issuing an AIO request with an appropriate signal mask. When the AIO request completes, the thread can then wake up, handle the AIO, and reply to the client. Is there something I'm missing? Is this an acceptable "best practice" to build this sort of server?

Thirty representative French films

05 December 2008 - 10:06 AM

I once heard an anecdote that Igor Sikorsky, the Russian-American inventor of helicopters, learned English solely by going to movie theaters and seeing the same movie over and over and over again, switching to a new movie after a while. According to the anecdote, one day something in his mind clicked, and he instantaniously gained an understanding of a significant part of the English language. I am not very interested in the authenticity of this anecdote, but it does appeal to me in some way, so I'd like to try it out on French. I decided to pick thirty French movies and watch a new movie every day for one month. After thirty days, I will return to the first movie and start watching them over again. In six months I hope to report my findings. I found a list of French films on wikipedia: http://en.wikipedia.org/wiki/List_of_French_language_films but they are not rated in any way. I know that French Cinema is very rich and has many waves and movements. I'd like to find some list of top French films of all time, so that I could pick thirty representative films to watch. Does anyone know of such a list, or could you simply recommend classic French films from different cinematic movements? Ideally, the films would be popular enough so that I could easily obtain them, because I wouldn't know where to begin finding rare French films in America.

Scalability of Unit Tests

28 January 2008 - 09:22 AM

I am trying to understand how to properly do test driven development. I know I'm doing it wrong, but I can't figure out how to do it right. Here's a simple example that illustrates my problem. Suppose I wrote a function, sqrt, that estimates a square root of a number with Newton's method. I also wrote a test for it, sqrt_test, that tests it for some input. Now, suppose I wrote a solve_quadritic function that takes cooficients for a quadratic equation and solves it using a well known formula, utilizing my sqrt function above. I also wrote a test for it, solve_quadratic_test, that tests it for some input. So far so good. Now, there is an obscure bug in my sqrt function. I have to fix the bug. Now I've broken two unit tests - the one for sqrt function, and the one for solve_quadratic, even though I only changed the code in sqrt. You could make a number of arguments about this example (that both tests are supposed to fail because my change in sqrt affects other parts of the program, that my tests aren't actually unit tests but some other kind of tests, etc.) but the fact of the matter is that this type of testing does not scale. If a small change in the lower layer propagates all throughout my software and almost every minor change requires me to change tests that are responsible for other layers, very soon I'll spend most of my time dealing with fixing tests rather than adding features. It seems that the fundamental problem here is that solve_quadratic_test doesn't just test the algorithm in solve_quadratic, but also its dependencies. I can think of a few ways to get around this problem (pass a function pointer to sqrt to solve_quadratic so that during the test I can pass a mockup, start abstracting away unit tests, etc.) but all of these aren't really workable. So, how am I supposed to go about solving this problem?