Moving…

Just finished packing. Was much easier than expected but then again I don’t have a lot of crap. So yeah, I’m moving tomorrow. Officially, anyway. In reality, I’m not moving until mid-month, but I’ll be moving all my shit tomorrow.

Entryway to apartment. Big bedroom seen on right side.

Kitchen.

Uh.. that’s actually the only two places I took pictures of. I made a video too. Comment if you want link since I don’t want to post it in public.

Posted in Life | Tagged , | 4 Comments

Accessing variables in other classes in Objective-C.

This was meant to be a reply to a question on Stack Overflow, but when I’d finally written this all up, the poster had deleted the question. Figured I wouldn’t let all this go to waste so posting it here, hoping some Objective-C wielder might run into it and be helped.

***

There are a number of options, all depending on the situation. I will keep referring to Sender, Receiver, and data as the class holding the information, the class which wants the information, and the information itself respectively.

Option 1 – Point Receiver to Sender at Sender init

Here we keep track of Sender internally. We also preferably do not store data locally in case Sender is updated — instead we use `Sender.data`. This of course requires that there is only one Sender, and that it is instantiated before the Receiver.

    // in Receiver.h
    @interface Receiver : .... {
        Sender *sender;
        // ...
    }
    - (id)initWithSender:(Sender *)aSender andBlabla:....;

    // in Receiver.m
    - (id)initWithSender:(Sender *)aSender andBlerf.... {
        self = [super init];
        if (self != nil) {
            // retain, if aSender may ever dealloc before us!
            sender = aSender;
            // other init stuff
        }
        return self;
    }

    // in Receiver.m, wherever we need "data" from the Sender, we now use
    // Sender.data

Option 2 – Point Receiver to Sender at arbitrary time

Same as option 1 but here we simply put in a Sender as a `@property`. This one actually allows us to have our Sender instantiated after the Receiver, since we can set the `Sender` property at a later point. The danger here is to make sure `Sender` is not used before we’ve actually gotten around to setting it.

    // in Receiver.h
    @interface Receiver : ... {
        Sender *sender;
        // ...
    }
    // ...
    // assign->retain, if Sender might dealloc before us!
    @property (assign) Sender *Sender;

    // in Receiver.m
    @synthesize sender;

    // Someplace in our program, where we're ready to tell the Receiver
    // about the Sender,
    //   myReceiver.sender = mySender;

Option 3 – Point Receiver to Sender at data collection time

Here we simply add a method to Receiver which has an instance of Sender as its argument. Receiver will then grab data from Sender. Here we’re pretending a bit, and the reason is that we may or may not want to get other information out of Sender at a later point in time, so we go the safe route. The alternative is more restrictive but less complex (option 4).

    // in Receiver.h
    @interface Receiver : ... {
        NSData *data;
        // ...
    }
    // ...
    - (void)setSender:(Sender *)aSender;

    // in Receiver.m
    - (void)setSender:(Sender *)aSender {
        // to make things simple, we're presuming that data is not
        // deallocated until we're given new data
        data = aSender.data;
        // potentially do other things with data
    }

    // Someplace in our program, where data has been updated in our
    // Sender and we want Receiver to update,
    //   myReceiver.sender = mySender;

Option 4 – Include a -setdata: method directly in Receiver

This is the simplest but least expandable method we’ve got. In Receiver, we have an instance of our data that we set using a simple method or `@property`.

    // in Receiver.h
    @interface Receiver : ... {
        NSData *data;
        // ...
    }
    // ...
    // if data might dealloc before we're done using, assign -> retain
    @property (assign) NSData *data;

    // in Receiver.m
    @synthesize data;

    // Someplace where we want data to be updated
    myReceiver.data = mySender.data;

Option 5 – Delegation

Code in objective-c works very much like a tree with branches with further branches. This has the fundamental flaw/effect that a branch can’t access the thicker branch to which it’s attached, and it can’t get to the tree trunk either. This can be solved using delegation. The most common case where a “thin” branch accesses a “thicker” branch is view controller / view. A view will tell its view controller things via delegate calls. This is only slightly different from giving its view controller updates to a data object. In our case, Receiver is a controller (delegate) of Sender.

    // in Sender.h
    @protocol SenderDelegate <NSObject>

    - (void)senderDidUpdateData:(NSData *)newData;

    @end

    @interface Sender : ... {
        NSObject <SenderDelegate> *delegate;
        // ...
    }
    // ...
    @property (assign) NSObject <SenderDelegate> *delegate;

    @end

    // in Sender.m
    @synthesize delegate;

    // in Sender.m, whenever we want to notify our delegate (if any)
    // about updates to data, 
    //    [delegate senderDidUpdateData:data];

    // in Receiver.h
    #include "Sender.h"

    @interface Receiver : ... <SenderDelegate> {
        // ...
    }
    // ...
    @end

    // in Receiver.m
    - (void)senderDidUpdateData:(NSData *)newData {
        // do something with newData, e.g. set data = newData;
    }

    // Someplace where we have both the Receiver and Sender instantiated
    //    mySender.delegate = myReceiver;

Option 6 – Singleton

Using a singleton is sometimes beneficial. See other discussions on this topic for details. A singleton should be avoided unless you will have a single instance of a class throughout your code.

I’m sure there are other options as well, but these are the ones that come to mind right now.

Posted in Code | Tagged , , , | Leave a comment

Robbery.

I went down to the local store to get some beer and milk (a worthwhile combination if you ask me, though I didn’t mix the two). As I went to pay for it, a guy in a gray hood holding a big knife was in the process of robbing the guy at the cash register.

A number of thoughts went through my head. I ultimately decided to turn around and walk back behind the corner and either call the cops or tell an employee to do so. One was actually standing right there so I walked up to her and calmly informed her that a robbery is in progress and to call the cops.

Her: “You’re joking, right?”
Me: “Nope, not joking. Please call the cops immediately.”
Her: “Are you sure?”
Me: “Yes, I’m sure.”

After that cozy conversation she went off and called the cops. Meanwhile, I decided to see what in that store could possibly be better than a big knife. I found a pair of scissors, and figured that was probably not going to work very well. A big rock or, hell, a baseball bat would have been ideal, but alas.

Ultimately the guy ran off and I paid for my beer. The cops arrived and there were others who’d gotten a better description of the guy than I, so I just went home.

Meanwhile, my sister’s in Turkey near where the suicide bombing occurred. She’s apparently fine, according to her husband, but we’re all sort of waiting for her to get back home in one piece. (Edit: sis landed at airport in Sweden earlier)

I’m not sure I like the direction the world is heading in…

Posted in Life | Tagged , | 5 Comments

Google’s Targeted Ads.

I don’t think Google foresaw this one, but I’m starting to feel slightly insulted here.

The ads in Gmail sort of figure out what you “want” and show you ads related to that. If you have an email discussion talking about wanting to get a new BMW, Gmail will show you BMW retailer ads.

So when I the other day got ads about “Chinese women wanting a man”, it got me thinking. For one, I have no interests in Chinese women, whether they want a man or not, and I haven’t been talking about Chinese women anywhere either. Except for the fact I write and receive emails in Japanese.

Then earlier today I got an ad which reassured me that, “there are plenty of reasons why you can’t get an erection”. I’m fine with the emails, really, but when this kind of shit appears as a “legitimate” ad, it’s annoying on a new level.

I wonder if Google ever realized that the better their “targeted ads” become, the more hated they will be, because as they start to “hit home”, that’ll trigger some very sensitive buttons with people.

I mean, if I was having erection issues, do you think I’d be thrilled and excited and grateful that Google blares it in my face? I’m sure I could google it on my own, thanks.

Posted in Life | Tagged , , , , , | 2 Comments

Taking bullshit.

I started university the end of August this year. I’m a late bloomer, what can I say. I like it, though. Wish I’d done this something like 10 years earlier.

I’m so happy I live in this country, where it’s possible to go to uni at the age of 30. In Japan, people start pressuring you about it at the age of, oh, 5. Months.

I digress. At uni, I’m now taking two courses — engineering methodology and linear algebra. The former is a pain, the latter is fun. The former mainly comprises of the following:

Be put into a group with 7 other people, plan and execute a fairly big project (1-2 months of 16 hours/week worth of “work”), and then present the results. And write a bunch of reports about how it all went.

Said project turned out to be assembling and programming a LEGO Mindstorms NXT robot. I was “fairly” lucky with my team mates, except that the majority want to “take the short cut” and sort of just pretend not to exist so they don’t have to do anything.

I don’t blame them, really. We were a pretty disorganized bunch from the get go, and it was really hard to get everyone things to do. There were only so many sub-components of the robot you could make before you ran out, and building the robot required at most two people — more, and there’re too many hands fidgeting.

I also don’t blame them for starting to talk shit about me behind my back. It happened after we had been sitting in a “seminar” which was obligatory, talking about a chapter in the engineering methodology book we had been required to read. First though, to get some perspective, this is the deal:

I’m working 50% plus attending school. That means I have 4 less hours each (week)day to studying or relaxing. This is considered normal in most countries, but in Sweden, being a uni student is considered the equivalent of working approximately 125%. In effect, I’m now occupied 175% with work and/or school. That’s 70 hour weeks.

So there we are in the seminar, and people haven’t done what they were supposed to. The assignment clearly said “read the book and then pick out stuff from parts 2-4 and bring to the seminar”, and people interpreted “parts 2-4″, conveniently, as “chapters 2-4″ (which were all in part 1). So we take 15 mins where people read up “real quick” on the other parts, and then discuss… and…

… it’s just retarded. Absolute, raw, unfiltered retardation. People were saying things like,

A. “Okay guys, so! The next item on the list goes: ensuring group unity. Anyone have anything to say?”
B. “Oh yeah, we totally need to have group unity. It’s like, super important. Without group unity we won’t be as effective and such.”
A. “That’s awesome, B. How do we ensure group unity?”
B. “You know, we have to stick together and shit. Back each other up.”
A. “Perfect.” (writes this whole thing down on lap top)

And it spirals downward from there. I’m sitting there watching these people with this empty, glazed over expression in my eyes, and at some point I just involuntarily start grunting agreement in an extremely sarcastic voice. I’m serious when I say I felt like someone was controlling me, because even though I knew how bad it was, I couldn’t stop myself.

Meanwhile someone pulls out their math book, walks over to me, and starts asking me questions about some problem. In the middle of the seminar. I look at the book for a brief moment, then turn back to the room and pretend nothing’s happened. So totally not me.

Then eventually I just stand up and say, “Well since you guys are doing math, I’m gonna head home and work.” and leave.

And that’s where it sort of started. People laughing for no reason when I say or do something. It bothered me initially, but then I stopped caring. I also stopped caring about courtesy in the group, coming at appointed times and leaving when we’re done, doing everything I can for the project, but nothing for the people in it. They’d stop talking when I came into the room, or even say things like “The group is already falling apart, *laugh laugh chuckle chuckle*” when I did. I always felt like confronting them when that happened, but instead I just grinned back and said something like “Yeah, me and (random name of person who’s also not there at the moment) have decided to dump you guys from the project.” And I realized it was because I actually don’t mind that they use me as “the bad guy” to talk about whenever I’m not around.

I’m comfortably fine being an asshole, and I know I’m being one. And I know it’s partly my fault. It feels good. It’s so unlike me, it’s as if it’s not me at all.

It’s partly my fault. When I started my classes I was determined at a completely separate level from the others in my group — all of them. I was dead set on doing everything in my power to get everything done as fast and efficiently as possible. I just came into it with this zero tolerance for “unnecessity” that made me lash out or do things I normally never would. The others ranged from “want to get grade” to “want to do something good with the time”, which I’d say is the healthy, normal state (or the latter, at least).

And I just don’t take bullshit the way I used to. At some point in the last couple of years, my patience has just… diminished.

Not great, perhaps. But there are other, good things too in this.

Throughout all of this, I realized something dark and dirty about myself. Throughout my life, I’ve loathed being hated. The mere thought of someone out there hating me, or even slightly disliking me, has always haunted me and affected my actions. Now, seeing these people around me being petty as they are (and they are; even if it is partly my fault), I’m struck by the realization that I absolutely couldn’t care less if they hate, or dislike, me, and if I don’t care about people I’ve been around 16 hours a week for the last two months, why on earth should I care what a stranger on the street thinks about me?

I should rather care about what those I care about think, or those I respect think, or not care about what anyone thinks and just do what I think is right. Not thinking about what other people think is a mindblowing concept, to me.

Late bloomer, what can I say.

Posted in Life | Tagged , , , , , | 6 Comments

Democracy and voting.

Today was the election here in Sweden, where everyone was supposedly voting for their preferred government in state, municipality and city. Well, in fact, it’s been possible to vote ahead of time for the last 1 or 2 weeks, but today was The Day. When today is over, the (new? same?) government will have been announced, and we’ll play by their rules for the next 4 years.

Whenever I go to vote, something inside of me is always different. The emphasis, or focus, is tilted toward something new each time. This time, unsurprisingly, it was Japan. I saw everyone around me who came to make their voices heard, however small, and I thought about the vote rate for Japan — something like 40-45% usually (it was higher last time, thanks to Obama, I suspect). I saw a mix of Swedes and foreigners around me all with their voting envelopes in their hands, and I felt a sort of wonder at how they cared when so many people who’d been born and raised here did not. Perhaps my time in Japan as a foreigner put more presumptions into my head than it discarded…

Whenever I go to vote — and I have, since I was allowed to, which puts me at #3 today — I go through this range of emotions which is different each time.

I feel intrigued, looking at those around me, wondering who’s with me and who’s against me, wondering what would happen if everyone suddenly started yelling out their choices.

I feel good, for actually giving a damn. Even if I don’t put a lot of faith into these politicians, I at least make a statement as to which one I think sucks the least.

I feel bad, for not knowing enough about the available parties. For not looking into, asking, scrutinizing agendas and watching debates they had going on TV*. I made my choice but it wasn’t a firm, absolute one, it was of the wavering kind. Perhaps it’s the times…

I feel guilty, because even though I do vote, I do so whilst in the aforementioned predicament, and I’m afraid that if those around me vote as “lightly” as myself, our democracy is pretty much a castle on a mountain of sand — a single tremor could send it sliding.

I feel moody, because of the times changing. My own views have changed radically, as have those of the world around me. The Social Democrats, my obvious candidate in the past, are struck from my list, possibly forever, at the very least until Thomas Bodström is removed. The Pirate Party is a joke, or I’d go “the responsibility-less route”**.

I feel uneasy. I mean, some fairly nutty parties have gotten a lot of support lately. I’d probably give up and move out of this country if SD got into the government***.

Regardless, I’ve at least performed my duty, if half-assed, as a believer in democracy.

(* from what it sounds though, the TV debates were fairly useless — a truckload of shitflinging, mostly)

(** they have “no views” on anything other than letting people download shit (and, they try to claim, “on privacy/integrity”).)

(*** SD = Sverigedemokraterna, a bunch of racist pigs who had something like 7% of people’s votes in a poll a couple of months ago. In Sweden, you need 4% or more to get into government, and in rare cases where the two major alliances (left and right) are very close, those 4% can give you a lot of control, because in essence, if left goes ‘yes’ and right goes ‘no’, you decide if the answer is yes or no (if you say yes, yes gets “48+4=52%”! If you say no, no gets “48+4=52%!”, presuming left and right had 48% each and you the remaining 4).)

Posted in Democracy | Tagged , , , | Leave a comment

Let me tell you all the ways …

… in which I hate you.

800 MBs of RAM. And you know what? I haven’t even used Flash since I started Chrome.

So in the midst of Flash versus Apple (well, we’ve sort of blown past it, but anyway), let me just point something out here…

You blow.

Posted in Software | Tagged , , , , | 4 Comments

There now, let’s not be completely fucking retarded.

Kalle-Alms-MacBook-Pro:trunk me$ svn st
?       build
?       universe.orig
?       scratchpad.rtf
M       asynchro.xcodeproj/user.perspectivev3
M       asynchro.xcodeproj/project.pbxproj
M       asynchro.xcodeproj/user.pbxuser
?       Classes/multilineTableViewController.h
?       Classes/multilineTableViewController.m
M       Classes/gridreaderViewController.h
M       Classes/gridreaderViewController.m
M       Classes/mgXMLWorld.h
M       Classes/mgXMLWorld.m
!       Classes/MultilineTableViewController.h
!       Classes/MultilineTableViewController.m
?       tavern/world.xml
?       universe/uni.jpg-files
M       asynchro-Info.plist
?       examples/stiles

Oh, right, I renamed that “MultilineTableViewController” to “multilineTableViewController” (lowercase M) because everything else has lower-case-initial-letter.

Kalle-Alms-MacBook-Pro:trunk me$ svn rm Classes/MultilineTableViewController.h
D         Classes/MultilineTableViewController.h
Kalle-Alms-MacBook-Pro:trunk me$ svn rm Classes/MultilineTableViewController.m
D         Classes/MultilineTableViewController.m

Great! Let’s add the new lower-case one to SVN now while at it…

Kalle-Alms-MacBook-Pro:trunk me$ svn add Classes/mult*tab**tab**tab**beep**beep*

Hm?

Kalle-Alms-MacBook-Pro:trunk me$ svn add Classes/*tab**tab*
.DS_Store                     gridreaderViewController.h    mgImageSourceRequest.m        mgScrollView.m                muddyGrid.m
.svn/                         gridreaderViewController.m    mgImageView.h                 mgWindow.h                    tile.h
UIImage+Scaling.h             gridreaderViewController.xib  mgImageView.m                 mgWindow.m                    tile.m
UIImage+Scaling.m             mg2DTileSet.h                 mgMinimap.h                   mgXMLParser.h                 worldViewController.h
fileIO.h                      mg2DTileSet.m                 mgMinimap.m                   mgXMLParser.m                 worldViewController.m
fileIO.m                      mgImageSource.h               mgMinimapButton.h             mgXMLWorld.h
gridreaderAppDelegate.h       mgImageSource.m               mgMinimapButton.m             mgXMLWorld.m
gridreaderAppDelegate.m       mgImageSourceRequest.h        mgScrollView.h                muddyGrid.h

Wait.

Where’s my class…?

Turns out SVN fucktardedly presumed “oh im shure he ment delt da fl thats lcase here insted lolstfucoksknmfur”. Luckily I had the files in memory.

The wonderful adventure continues.

svn: Failed to add file 'foo/Doc-credits.png': an unversioned file of the same name already exists
Kalle-Alms-MacBook-Pro:iphone me$ rm foo/Doc-Credits.png
Kalle-Alms-MacBook-Pro:iphone me$ svn up
Restored 'foo/Doc-Credits.png'
svn: Failed to add file 'foo/Doc-credits.png': an unversioned file of the same name already exists
Kalle-Alms-MacBook-Pro:iphone me$ masturbate furiously
-bash: masturbate: command not found

This time, the file Doc-Credits.png exists and the file Doc-credits.png needs to be added.

For the record, Mac OS X is at fault here — Apple decided to “be compatible” with Windows and not allow filenames of the same size with different capitalization, which *NIX does allow.

That doesn’t make SVN any less retarded though. After all, it’s running on the OS, so it should know the OS.

Posted in Work | Tagged , , , , , , | 10 Comments

The equivalent of ‘toString’ in Objective-C.

If you’ve ever wondered if there’s a convenient way in Objective-C to write a function for “expressing” the value of an object of yours, as a string, just like “toString” in e.g. JavaScript (and Java? I think), I’ve got good news:

-(NSString *)description

Add the above method to your Objective-C class and you’ll be able to NSLog it or get its string value anywhere using [OBNAME description]. In short, it will now respond with its ‘description’ to ‘%@’ in an NSString stringWithFormat expression.

Example:

@interface Person : NSObject {
  NSString *name;
  NSString *phone;
  NSInteger age;
}

-(NSString *)description;
[...]
-(NSString *)description
{
  return [NSString stringWithFormat:@"%@ (%d): %@",
        name, age, phone];
}

Then somewhere we have a Person object and we want to see its value.

NSLog(@"We've got %@", aPerson);
myLabel.text = [NSString stringWithFormat:@"Details: %@", aPerson];

(pardon any errors in code above — untested as is)

Posted in Software | Tagged , , , , , , , , | 2 Comments

Tackling spam.

Let’s face it: the spammers are so sophisticated these days it’s only a matter of years before they’re identically copying “real” people, “real” content.

One of the simplest ways of doing this is to simply scan for identical blog entries, or blogs which focus on specific content. The recipe is simple, and if done right, impossible to detect:

1. Find 2+ blog posts about “chocolate pudding”.
2. Grab a random comment from each post.
3. Post each comment as your own user to each other blog, so that each comment appears entirely new, and genuine.
4. Put your spam URL in URL field.

There you have it. The only thing that could spoil you is if you accidentally grab a random comment that itself is spam from somebody else.

The way to combat this is to start ignoring the content of messages. In email, in blog entries, everywhere. We need to just give up on the whole idea. Instead our spam filters look at individual sites point to in URLs provided by said spammers.

Because you know what? These sites look almost exactly today, the way they looked 5, 10 years ago. They’re identical, because once we’re “there”, we either close the browser or we fall for the trap. It’s incredibly easy to scan for general spammy crap, like “viagra” or “penis enlargement” etc. Basically doing it the way it’s been done all this time so far, but applying it to web sites rather than emails or blog comments.

That’s all I had to say, really.

Posted in Security | Tagged , , | Leave a comment