Shifting My Own Bits: Part 2

TL;DR: Participating in life makes me feel like a fraud, but I need to participate in life in order to be happy.

A year-and-a-half ago I wrote Part 1 of my foray into understanding myself, at the time coming up with several explanations for my attitudes. Unfortunately, knowledge is only half the battle; understanding that my attitude doesn’t match reality doesn’t make it easy to change, to reinvent myself. It’s easy to follow advice and take a step in the right direction, to “go out and do something today!”, but the momentum doesn’t last. It’s like pouring water on sand — no matter how much water you pour on, no matter how much the water pools and aggregates, it will always drain through.

Even while out my old attitudes persist. I’m there looking for a chance to excel, to prove how superior I am, to feed off the love and admiration of others. It’s like a drug. If I can’t find that opportunity, or if I fail, I tune out. I’m no longer participating, just biding my time until I can leave. I don’t project a bubbly, happy personality, and so no one talks to me; I in turn talk to no one as I’m so afraid of that awkward moment when I have nothing to say except the thousand things I can’t, so afraid of being identified as boring and empty. I’m a puzzle piece trying to fit into the wrong puzzle.

Listening to others conversations, I realize I would have nothing to say even if I was part of them; I can’t relate to the social experiences of others because I am not social. I didn’t go to that event last week, I didn’t see that TV show, I didn’t hear that song, I didn’t have that relationship, I didn’t feel those things at all. How can I cheerfully interact with others’ happiness when I’m in a constant state of denial over my own? When I spend my Friday nights trying to understand myself, trying to alter the attitude that keeps me unhappy. How can I relate to anyone without these flaws, except on a peripheral basis?

These outings leave me broken, an overwhelming mix of feelings I can’t understand, parse, or organize. The high from having overcome anxiety and actually gone, the rush from brief positive interactions and the hope they will turn into my cure, the deep funk of failure as reality sets in. Each of these is an experience, but not a lasting one. My perspectives and attitudes remain unaltered, I make no friends and start no relationships; I’m not participating in life.

This is not to say I do nothing; I really enjoy my work and I do several sports to at least maintain my mind and body. I can also overcome anxiety in certain circumstances; I interact with people when I need to. While others have found success by making a plan and sticking to it, I need to understand what’s holding me back before I can move forward. I need to understand the difference between the cases where I can engage with society and when I can’t, to develop an attitude that allows me to connect personally with social interactions instead of remaining aloof, to get to a state where I don’t look upon yesterday with regret.

But how? Such introspection is hard, and sometimes painful. It’s easy to get distracted, to run and hide. Perhaps the “go and do it” approach would work for me too, but I can’t shake the feeling that it’s all fake; I’d be a fraud, trying to be someone I’m not. In my dreams I find someone who is also broken; together we work through the pain and come out victorious. But so far that seems to just be more wishful thinking. Movies and books portray growth shaped by friends and acquaintances which certainly sounds good, but I’d have to engage socially — and openly — for that approach to work for me.

Posted in Self | Leave a comment

Understanding Memory: Part 1

This article is meant for programmers who have some familiarity with writing and compiling simple code in C/C++. It assumes the reader knows basic data types like int and double and how to define and use variables and functions. This article will then expose the reader to a basic memory model, explain how the use of variables interacts with this memory, and introduce addresses and pointers.

On a modern platform, memory is presented to a program as byte-addressable blocks. Each byte in this block has an associated integer address; this address is used to identify to the computer which piece of memory to operate on. For this demonstration, let us assume our program has a block of memory with the first byte at address 0×10. Each variable we declare in our program must occupy some of this memory. The compiler we’re using will use this memory to store variables we define. Different data types can be different sizes: an int type is commonly 4 bytes, while a double is usually 8.

int cakes = 10; // 4 bytes starting at 0x10.
double level = 11.5; // 8 bytes starting at 0x14.

To manipulate these variables, we simply assign a value to their symbols, since their addresses have been managed for us by the compiler:

cakes = 15; // the compiler knows where "cakes" is stored in memory

Addresses and Pointers

Now, we would like to modify the values of these variables from an external function. This function does not know about the variables we have declared here because it exists at a different scope. We need two things to accomplish this. First, we need a way to obtain the address of our cakes variable in memory. For this, we can use the address of operator, &. Second, we need a variable into which this address can be stored; this is the pointer type, specified by a data type and a *. The size of the pointer type on this platform is 8 bytes, allowing for a 64-bit address space.

int *pointer_to_cakes; // 8 bytes starting at 0x18.
pointer_to_cakes = &cakes; // the value of pointer_to_cakes is 0x10

To modify the value through the pointer, we dereference, using the * operator.

*pointer_to_cakes = 25; // cakes is now 25

Lets go ahead and modify this value in our function.

/* Function takes a pointer to an int, allowing it to modify the value */
void get_num_cakes(int* how_many_cakes) {
    *how_many_cakes = 17;

get_num_cakes(pointer_to_cakes); // sets cakes to 17.
get_num_cakes(&cakes); // can pass address directly.

The next extension to this happens when we would like someone to modify the value of pointer_to_cakes, so that its value contains a different address. The principle of course is the same: to modify a variable, one must know its address.

void set_cake_ptr(int** cake_ptr_ptr, int* new_cake_ptr) {
    *cake_ptr_ptr = new_cake_ptr;

int another_cake = 1; // 4 bytes at 0x1C
set_cake_ptr(&pointer_to_cakes, &another_cake); // pointer_to_cakes is now 0x1C

Posted in Software | Tagged , | Leave a comment

Shifting My Own Bits: Part 1

Refactoring plays an important role in the software development lifecycle — an opportunity to incorporate lessons learned, improve code quality, and lay down a solid framework going forward. The entropy decay of code over time that necessitates refactoring plays a role in other places as well, such as our minds. We can apply the principles of science and engineering to ourselves, allowing us to control who we are with rigorous analysis and study. This rather long essay won’t be appealing to those who came here looking for code snippets, but I want to share some refactorings I have recently undergone in the hope that they can help others who are suck as I was.

If we accept as a primary goal the maximization of happiness, we can thus analyze our actions, state of mind, and thoughts to determine what causes us to be unhappy. For me, this was simple: people were out doing cool stuff and I wasn’t out doing it. It would have been simple to just go out and do these things, except for some reason, it didn’t feel right. There were times when I would go out and be social, usually at a friends request, but the urge to enjoy society declined when these friends weren’t around. I enjoyed these outings, so I didn’t see myself as someone who fundamentally doesn’t like the company of others. It was time for some root cause analysis.

This yielded some fruit: from the basic human need to feel love and appreciation, to matter, I was able to obtain this from an early age by being smart — I was rewarded in school and at home for being the smart kid, the A student, the one who worked hard and always went the extra mile. Because of this, I was also the special kid — as a nerd from an early age, I was never popular, never had a large group of friends, never really obtained appreciation from social interactions. This special-status became a drug: at first I was pleased to receive, then I was used to it, expectant, demanding.

“Of course I’m special” became the mantra; being smart became my identity.

Excelling on a project was no longer an action, it was who I was. I begin to enter situations with the expectation that I would be treated specially, assuming the regular rules didn’t apply to me, that there was always an exception. Through high school, this was mostly correct — I received a steady supply of alternate assignments, privileges, and modifications to my courses. This has ultimately lead to a very successful career track, which I’m ultimately grateful for, but at the expense of social development.

In college, I hit a wall right away. I was no longer the smart kid. No one knew me, I was a stranger in a town on the other side of the country with a bunch of other strangers who had better educational backgrounds. Right away I began to receive assignments that were actually hard! I could no longer just breeze through them, or demonstrate to the instructor that I required something more interesting — I was to do just the regular assignment with no possibility of praise for an exceptional effort. It wasn’t that I didn’t know how to ask for help, or where to find resources should I have needed them, but asking for help just wasn’t something I did. I was supposed to know how to do it, and if not, certainly wasn’t supposed to be seen showing weakness by asking for help.

I wasn’t that I couldn’t fail because someone would express disapproval, I couldn’t fail because success was my identity — without it, who was I?

My system broke. I could no longer attain the steady flow of appreciation I had become addicted to by working hard. I flipped back and forth between different temporary explanations — maybe stress due to new environment, maybe that class was just hard, maybe I need a break — but none really stuck. One of the major side effects of the appreciation addiction was coming to bear — without the steady reward trail, the path forward was no longer there. I didn’t know what to do. With each failed assignment returned to me (<A was failure), I decayed further. Was I stupid? How come others weren’t having these problems? Why didn’t I know how to do this? What the fuck is wrong with me? I began to blame myself and started a cycle of negative reinforcement, adding more stress to what I had from complete lack of financial stability.

There was enough logic left in me to know that dropping out of college was a terrible plan, so I pulled through it somehow and managed to graduate and get a job that I enjoy. I had more direction at this point certainly, and the job offered the effort/reward cycle that I excelled at easily. Outside of work, however, little progress had been made. With a fresh start in a new city, a car (didn’t have one during most of college), and no more financial worries, I should have been set free. But instead of abundant social interaction, I stayed inside. Part of the internal expectation that I was to know all things was causing a block on learning new things necessary to increasing social interaction — finding things to do, places to go, etc. This was accentuated by living with a roommate who actually did know all things (a lot of things, at least) and was quite adept at pointing out failures in a way that made me feel pretty shitty for not being right. I began to dread pronouncing any discovery of knowledge, for fear that I would get shot down for not knowing the critical flaw or a better way. I also became hypersensative to critical remarks and stressed during situations when I wasn’t performing on a high level. It became easier to restrict myself to activities I already did or just do nothing.

But as the months went by, this became increasingly unacceptable. My friends were out living their dreams (or at least doing what they wanted) and I was stuck inside, barricaded by my fears. I went through several bouts of depression (I guess, never clinically diagnosed/treated) and began to waste large amounts of time browsing the internet, anything to get away from this problem I couldn’t solve. I was searching for a solution that would grant sudden clarity to my situation — I was expecting something to happen to me that would make it all make sense. After all, I was special — whoever was in charge of special people like needed to get on over here and fix it.

That was seriously the attitude I had — I certainly wasn’t wrong, I couldn’t possibly have wasted all these years with this flawed understanding of myself, there had to be something I was missing, some wormhole through which people like myself could jump and get ahead of everyone else, be recognized for our superiority.

Perhaps I was supposed to meet someone randomly (that was my strategy for meeting girls…) perhaps I would go to some place on a whim, receive some correspondence that would save me from my plight.

Looking back now, that attitude seems ridiculous. The world doesn’t give a fat fuck how “special” you think you are. There is no magical system that guides you, the entire effort/reward cycle is a technique used for training pets for obedience. To think of that as anything approaching a replacement for love is flawed. My whole world view was wrong — it had to go. Of course I had heard the saying “you can be anything you want to be” as a kid, but it didn’t really sink in what that meant. I had gotten so used to the appreciation drug that I had forgotten what it meant to do something just because I liked doing it. This world view had to go.

Posted in Self | Leave a comment

Enable WordPress Automatic Updates on a Debian Server

I attempted to get WordPress to update plugins automatically on my Debian server today, and found it a bit less than trivial due to the number of configuration gotchas.

Assuming you’re running a Debian server (I have 6.0 Squeeze), on which WordPress is installed in /var/www/site/public_html:

1) Install required packages. I used vsftpd.

sudo apt-get install vsftpd openssl

2) Configure vsftpd. I set the following options in /etc/vsftpd.conf

# Enable only local users, no anonymous

# Allow only our special FTP user

# Here's the security trick -- listen only on the local interface to 
# prevent external connections

# Enable debugging until everything works :)

3) Add a user for ftp access

# Add the user
sudo useradd ftpsecure -d /var/www

# Set a password. Since vsftpd is only listening on localhost, the 
# security of this password isn't too important.
sudo passwd ftpsecure

# Add to the vsftpd allow list
echo "ftpsecure" | sudo tee -a /etc/vsftpd.allow_list

4) Turn on vsftpd:

sudo /etc/init.d/vsftpd restart

5) Set permissions for ftpsecure to access your wordpress files. I use access control lists (ACLs), but you could use chown/chmod if you want. These may seem like a bit to permissive — keep in mind that the only way ftpsecure can log in is from your server.

setfacl -m u:ftpsecure:r-x /var/www/site/

# The updater needs access to the root site
setfacl -R -m u:ftpsecure:rwx /var/www/site/public_html
setfacl -R -d -m u:ftpsecure:rwx /var/www/site/public_html

7) Tell WordPress about your FTP credentials. In /var/www/site/public-html/wp-config.php:

define('FTP_HOST', 'localhost');
define('FTP_USER', 'ftpsecure');
define('FTP_PASS', '<password>');

6) Run an update. If WordPress asks for the connection type, choose FTP. Try getting WordPress to update a plugin or the entire site. If it fails, view the log with

tail -f /var/log/vsftpd.log

and run the update again. You’ll be able to tell from the log if there was a permission problem.

7) Disable logging. Remove the line


in /etc/vsftpd.conf

8) You’re done!

Comment below if these steps didn’t work for you.

For reference, I used:

Posted in Software | Tagged , | 6 Comments

When you need std::remove_const

I ran across an interesting case where I needed to use std::remove_const to ensure a template parameter wasn’t const by default. I had something like this:

const Matrix<4> m4 = Identity;
Vector<3> v3 = project(m4[3]);

With the library I was using, TooN 2.0.0 beta8, this resulted in a compile error. The error stated that when the vector returned from project() was being created, the compiler couldn’t invoke assign to a read only location. A simplified declaration of project() looks as follows:

template <int Size, typename Precision, typename Base>
Vector<Size-1,Precision> project(const Vector<Size, Precision, Base>& v);

What the project() function returns is not important; what is important is the use of the template parameter Precision in both the argument type and the return type. When I invoke operator[] on a const Matrix object, the returned vector’s precision inherits the const.

template <int Rows, int Cols, class Precision>
class Matrix {
Vector<Cols, const Precision, Slice> Matrix::operator[](int row) const;

When this vector is passed to the project() function above, the function tries to create and return a Vector<3, const double> which can only be initialized with a constexpr. Assigning to it via operator= or a constructor will not work to copy the data from the other vector.

There are several ways one can fix this, all of them involving removing the const qualifier from the Precision type on the returned vector.

It may seem like a simple solution would work:

template <int Size, typename Precision, typename Base, typename P2>
Vector<Size-1, P2> project(const Vector<Size, Precision, Base>& v);

Unfortunately, this requires the function be invoked as project<Size, Precision, Base, P2>(v); which is undesirable.

Solution #1

The first solution is simple, but tedious if you have several functions with similar signatures:

template <int Size, typename Precision, typename Base>
Vector<Size-1, typename std::remove_const<Precision>::type > 
project(const Vector<Size, Precision, Base>& v);

std::remove_const<T>::type is a type expression equal to the original type T, but with any const qualifiers removed. In this way, const double becomes simply double.

Solution #2

Another solution is to prevent the creation of a Vector object with a const precision, the idea that a non-slice vector with const data isn’t very useful — you can’t even construct one properly. Generally the only time you would actually want a vector with const data is when that data is pointing to some already existing area in memory (a slice).

Consider the following toy code for a vector class:

#define DECLARE_TYPES(T) \
    typedef typename std::remove_const<T>::type PlainType; \
    typedef const T ConstPlainType; \
    typedef typename std::remove_const<T>::type& ReferenceType; \
    typedef const T& ConstReferenceType

struct StackBase {
template <int Size, typename P>
class Layout { 
    PlainType data[Size];

struct SliceBase {
template <int Size, typename P>
class Layout {
    P* data;

template <int Size, typename P = double, typename B = StackBase >
class Vector : public B::template Layout<Size, P> {
    using B::template Layout<Size, P>::data;

    ConstReferenceType operator[](int i) const { return data[i]; }
    ReferenceType operator[](int i) { return data[i]; }

When the Vector object is backed by owned storage (StackBase), the data is declared explicitly to be of a non-const type. Similarly, the return types of operator[] are defined to be the const and non-const reference types. The SliceBase, which handles references to un-owned data, retains the original templated type to allow pointing to constant data.

While this method prevents the creation of Vector objects with const owned data, it also means you don’t have to augment functions that interface with these objects to correct the return type.

Posted in Software | Tagged , | Leave a comment

Correcting Message Order with Courier

Recently I moved some local messages from my machine (previously downloaded with pop3) onto the server so I could use imap. I used on Mac OS X 10.5.8 to do this.

For some reason, the messages in this example were uploaded in a way that caused them to be loaded in the wrong order on iOS 5.0.1. Since I run the mailserver myself, I took a look at the message files to see if I could deduce the cause of the issue. I noticed a series of messages on the mail server that looked like this:


The received times of these messages, in the same order as listed above, are:


It turns out that due to the messages in this example having a modification date that doesn’t match their receive timestamp the messages appear in the wrong order on an iOS device, where the mail application assumes the order of the messages it gets from the imap server is already sorted by date. This isn’t a problem with desktop mail clients — they simply fetch all the messages, sort them, and everything is fine. Several google searches on this subject yielded threads where people were trying to get their messages in the correct order and the suggested remedy was “sort them on the client side.”

To fix this, I wrote a perl script script to read the message headers, determine the receive time, and update the file name and modification date to match.

Use the script like this:

perl cur/*

When you’re convinced it will do the right thing:

perl cur/* --output-dir cur_renamed

After ensuring the rename was correct, I swapped the cur and cur_renamed directories, deleted the courierimapuiddb file, and restarted courier-imap. I also had to quit on OS X and delete and re-add the mail account on the iOS device to get the messages to come in in the correct order.

Posted in General | Tagged , , | Leave a comment

Google Authenticator Backup Woes

TL;DR: Google Authenticator doesn’t backup on iOS; before erasing your old device, make sure to re-configure Google Authenticator on your new one.

I use the Google Authenticator app on iOS for 2-factor authentication into Google’s services. Recently, I was transitioning to a new phone after giving my existing one to my mom for Christmas. I did the standard backup -> restore plan which put most of my settings on my new device without issues. Fortunately, before I erased the old device, I made sure all my apps worked, including the authenticator.

Apparently, the data the authenticator app stores is not backed up for whatever reason, which means that instead of being able to generate the keys needed to access my accounts, the authenticator was prompting me to set up a new account. The smart folks over here recommend taking a screenshot of the QR code Google’s site gives you when you set up 2-factor authentication.


To Google: Why doesn’t the authenticator back up its data? Seems this could be a nasty surprise for someone.
To Android users: Does this happen on Android as well?

Posted in General | Tagged , | 1 Comment

Cubic Spline Interpolation

Cubic spline interpolation is a simple way to obtain a smooth curve from a set of discrete points (knots). It has both C1 (first derivative) and C2 (second derivative) continuity, enabling it to produce a continuous piecewise function given a set of data points.

From the algorithm detailed here I have implemented a clamped cubic spline class in C++. It is templated on the type of X and Y, allowing for use of scalar or vector types. It requires only that X and Y define the operators +, -, *, and /, and that Y have a constructor that takes a single scalar argument, initializing all elements to the supplied value.

Usage is very simple. For example, to interpolate a 2D location over time, try this:

#import "glm.hpp"
#import <vector>

std::vector<float> times;
std::vector<glm::vec2> points;
points.push_back(glm::vec2(-303, -572));
points.push_back(glm::vec2(-250, -980));

/* Create the spline interpolating the position over time */
Spline<float, glm::vec2> sp(times, points);

/* Compute the interpolated position at time 0.75f */
glm::vec2 value(sp[.75f]);

The code for the spline class is below:

Continue reading

Posted in Computer Vision, Software | Tagged , , , , | 5 Comments

Houses in Minecraft

So I’ve been playing Minecraft, focusing mainly on the creative aspect, although I play the new Beta client and run my own server locally so I get the features added post-classic. I’ve turned off monster spawning and set the difficulty to Peaceful, so I can focus on bringing creations to life instead of running from scary monsters in the night.

The first time I played with monsters, I found the sound of a zombie’s “murrrrrrrr” in a dark, endless cavern to be frightening enough that I never wanted to hear it again. /shivers.

I find the first-person building experience to be very satisfying to the OCD urge within me that wants to make everything right. As all blocks are destroyable (with the exception of Bedrock), any reality can be created given enough time. I’m fond of using the different kinds of blocks to vary the aesthetics — even if the blocks type is not practical.

My favorite activity is to visualize my buildings at night, as I find the lighting of torches, lava, and glowstone to create a very pleasing effect. I also make frequent use of glass to provide a sense of openness and to allow light to mix between areas.

Here’s some screenshots of a large house on top of a hill that I’ve been working on.

The master bedroom

The spacious master bedroom.

Continue reading

Posted in General | Tagged , , | 2 Comments

Time Machine Exclusions – Snow Leopard

A bit late, but here’s an update of the Time Machine exclusion list for Snow Leopard. Continue reading

Posted in Software | Tagged , | Leave a comment