Archive for category Uncategorized

Moving to the US

I’m moving to the US, and as part of that I’m wrapping up a host of legal things. I have some of this documented for my own benefit, and some friends are talking about similar things, so I decided to just write it all down.

Disclaimer first: I am not a lawyer, do not take this as legal advice, your mileage may vary, I’m talking about my position, not yours, etc etc

Immigration

As a Canadian citizen, I’ll be entering the US on a TN visa. TN is granted at the border, or you can mail in the I-129 form.

I renewed my passport early (more than 12 months before it would normally expire), citing the 3 year period of the TN visa as the reason in the passport application.

My company is handling the TN visa application, I’ll know more once the paperwork goes through.

Taxes in Canada

The CRA has an excellent section on emigrating from Canada.

If you want to be entirely through, the CRA has a form to determine what you should file as – emigrant/deemed resident. I don’t meet any of the deemed resident requirements, so I’ll be considered an emigrant.

I will be filing Form T-1161 along with my tax return for 2017, because becoming an emigrant means that my property undergoes a deemed disposition. Essentially, the CRA will consider all my property to be sold and repurchased at market value, so any capital gains can be taxed.

Note: One of my friends brought up that Canadian deemed residency includes a “183 day rule”, which says that you’re a resident of Canada if you’ve been in Canada for 183 days or more in a calendar year. He was concerned because it could mean that you file as a tax resident of both Canada and the US if you start your job late enough.

In my (see disclaimer) reading of it, it only matters if you’re either entering Canada, or visiting Canada. Since you’re leaving Canada, you’re going to be taxed on all your income prior to leaving Canada, and any income from Canada after you leave. Essentially, the 183 day rule doesn’t apply in this case.

If you want to be perfectly clear on your tax status, ask the CRA what they think of your situation by filing Form NR73.

Taxes in the US

I’m probably going to pay someone to do my taxes, at least for the first year when I move. I believe I would be considered a Dual Status Resident Alien.

The IRS does not like TFSAs (or RESPs, but recent grads are unlikely to have those). I’ve moved everything that I had in a TFSA into a RRSP, which the IRS likes a lot better.

Keeping my Canadian accounts means that additional forms (I know of Form 8938 and the FBAR form with the US Treasury) and will need to be filed for future tax years, which is always fun.

As a side note, California taxes Canadian RRSPs, so it’s a good thing I’m going to Seattle.

1 Comment

CyanogenMod 11 Nightly on a GSM Galaxy Nexus

I have a Galaxy Nexus, and have been pretty happy with it.  Then Google said it wouldn’t update the Galaxy Nexus to 4.4, and 4.4 is all swanky and new and most importantly, supports low memory devices better. So I want it. And guess what? CyanogenMod is pushing out 4.4 in CM11.

The real push for me to flash it is the fact that it has started dying on me – most annoyingly, the screen lit up to maximum brightness (while I was using it), then turned off. I suspect the screen just went dead, because I mashed the power button and tapped the blank screen and it vibrated at my touch, but the screen would only come back on after I pulled the battery and replaced it. Happening once is OK, I’ll chalk it up to cosmic ray events/random glitches. Having it happen 3 times in a single night is a bit much.

So it’s off to CyanogenMod!

First off, backups: I found a full backup method in an XDA thread. Reading through the thread pointed out that SMSes weren’t backed up, so first SMS Backups were handled by SMS Backup+.

Then I tried to get ADB setup. First roadblock: The Google USB Driver wasn’t in the SDK that I downloaded – had to use the SDK Manager to download it. Unfortunately, that still didn’t work, so I had to install the Samsung driver instead. I ended up with a “Samsung Android ADB Interface” entry in the Device Manager, so that was good.

However, adb seemed to have completely crashed, and it was weirdly even resistant to ending the process through Task Manager. adb.exe, java.exe and powershell.exe are all stubbornly refusing to close. This, however, was because Avast was restricting access to it, annoyingly enough. I disabled the Avast shields, and added the SDK folder as exempt from scanning.

One adb pull /sdcard/ and I had a backup of the contents of the internal SD card.  Because I had the shared stuff (I’m assuming that’s what the SD card stuff is), the next thing is adb backup -all -apk backup.ab. However, Google Music threw this for a loop here because the backup includes the cached music, so the final size of the backup was 5.11GB… which is excessively large.

Next step was actually unlocking the bootloader. fastboot required a different driver, so I ended up using the “Universal Driver” from XDA. After running fastboot oem unlock. I booted back into stock 4.2 (hadn’t flashed CM11 yet), and tried to restore my data using adb restore. It worked through ~half the apps, then died on restoring the google play store. Instead of retrying the restore, I forged ahead and flashed CM11.

I ended up using the instructions in CM’s HowTo install CM on maguro. I flashed the recovery with ClockWorkMod (discovering later that I could have actually used ClockWorkMod Touch instead), and then flashed PlayfulGod’s fork of CM11 for the Galaxy Nexus followed by flashing GApps Standard. (I specifically chose GApps standard because I wanted to get the camera APK integrated by default)

Now that I had CM11 installed, I then tried to restore my data. Which is where the weird part hit – The restore ran for a second or two, and then said “Restore completed”. After retrying a few times and getting the exact same thing, I hooked up adb logcat to monitor the restore and see what was happening.

Now I’m not too sure what was wrong, but BackupManagerService was consistently reporting “Incorrect password”. I tracked down the source, which I eventually decided that either it meant I was truly using the wrong password (I deemed this unlikely because the failed restore partially worked) or comparing the calculated key checksum with the stored key checksum failed. I heard stuff about Android’s encryption being weak, so they might have changed something, but a quick glance over the 4.2.1 and 4.4.2 BackupServiceManager files showed no obvious difference.

Whatever the case, my full adb backup was well and truly dead. So I just reverted to reloading my apps from the Play Store (ran through the list in My Apps) and waiting for the backup manager to restore whatever data Google had backed up. After installing everything, I restored Whatsapp from the database I backed up, and ran SMS Backup+ to restore all my SMS messages/call log from the backup.

So I had pretty much everything back where I wanted it, so the next thing in the list was to install a new kernel that would give me more RAM (since apparently TI ION maps a whole bunch of stuff into the RAM range, so the full 1GB wasn’t usable). That was a download and reboot into recovery mode to flash it, but straight forward since I’d already been poking around CWM.

And that was pretty much that. A shiny new (clean) install of Android 4.4.2 on an older phone, that actually revitalized it.

Future stuff:

  1. Use ClockWorkMod Touch instead of the standard ClockWorkMod (since my volume up button is broken, and scrolling through the list is tedious)
  2. Install the Genie widget to get the stock weather/news widget back
  3. In case I ever need it, recovering data from the internal memory
  4. List of potentially useful GNex resources

, ,

No Comments

Getting Django running on CentOS 6

Trying to follow this guide: www.digitalocean.com/community/articles/how-to-install-and-configure-django-with-postgres-nginx-and-gunicorn

epel6 rpms only seem to install 8.4 at this time, not 9.3 (strangely, since 8.4 isn’t supported anymore, so… I have many questions)

Official 9.3 installation go! wiki.postgresql.org/wiki/YUM_Installation

But WTF1: It was installed to /usr/pqsql-9.3, which wasn’t in the search path, so all the createdb and etc commands didn’t work.

Had to su postgres, cd /usr/pgsql-9.3/bin, ./createdb trailstest, ./createuser -P -s trails

And I only discovered it was in /usr/pqsql-9.3 because I did rpm -ql postresql93-server

yum install virtualenv step went fine

yum install libpq-dev python-dev was wrong, yum install postgresql93-devel python-devel was the correct command

pip install psycopg2 failed because pg_config wasn’t in $PATH – surprise surprise. export PATH=$Path:/usr/pgsql-9.3/bin fixed that… (Also, I discovered that there’s no spacing for a reason! Bash syntax!)

And then I got a gcc not found message. My bad, though it’s not a dependency of python-devel? a yum install gcc later, and we’re good…

And now it’s password authentication. I created a user, but it’s not working… even root is failing…

>Pizza Interlude<

So, had “Peer authentication failed” messages, and “Ident authentication failed” messages. I fixed the issue – remove everything from the config file, it defaults to connecting over the local UNIX socket, and using the username which it is running as, so the user has to exist in postgres. If I want it to work with a specific username/password combination, I’d have to edit the hba.conf file to get any other authentication scheme running.

Trying to get DNS working… new domain isn’t resolving on the UWaterloo DNS servers, but it’s showing up on other servers. Trying to get dig installed, but I’m getting yum timeout errors. Realised belatedly that I blocked outgoing HTTP connections. Rerun iptables rule adding with dport and sport swapped for input and output. Now everything is working, dig is showing the domain is resolving, so I’m just going to wait a while for UW to realise that a new subdomain exists…

Gunicorn is complaining about missing django project files when I try to run it and bind to port 8001. Mkay, noted. The Django dev server (python manage.py runserver example.com:8001) gives me a
working page, and I can get to it, so Django is set up! Wohoo! Time to get some GPS encoded in EXIF images up…

No Comments

On LED driver chips

I have found the TLC5940 chip, which I thought would solve my problems. It didn’t, not all of them, or at least there are a few downsides to it.

The main one being the timing requirements.

The 5940 kind of does PWM. It doesn’t have an internal clock, so it relies on an external clock signal. Generating that signal is tricky in my case, because I was planning to do Pi -> TLC chips -> LED, with the added complexity of multiplexing being thrown into the mix. These chips are designed for stuff like driving LED displays – single layer stuff, not 8 layers deep. And I’m switching between layers, not doing one layer completely then moving on. So the benefit of the chip doing PWM is lost, because I need to update the information in the chip each time I move to the next layer.

In terms of timing, the Pi can only do a max of 2Mhz, and that was measured in a infinite loop that just switched a single signal on and off. To get smooth motion, I’d need to do at least 24Hz refresh rate (guesstimate, based on movies). Because I have 8 layers, that becomes 192Hz. The chips take a 12 bit brightness value for each LED, and it’s serial in, so I’d need at least 192 clock cycles to get all the information in, not counting blanking/starting signals. So that gets us to ~37kHz.

My worry is that the Pi’s setting of pin output levels is synchronous, so I have to wait for 1 pin to go high/low before moving on. If the Pi can endlessly do one complete cycle at 2Mhz, I now have 16 outputs I need to cycle. Which isn’t too bad, that gets me ~167kHz cycles, not counting the clock signal generation. To make the math nice, I shall assume I have a round 20 outputs each cycle (I’ll have at least 1 – the clock signal for the chips), so it becomes 2000kHz/20 = 100kHz. However, a quick bit of calculation shows that I could do 60Hz refresh rate, and that’d need a ~92kHz data transfer rate, so I’m still within boundaries. It would just take an extra bit of complexity in the code.

But why is this a concern? The timing requirements are a lot tighter than if I was using a basic shift register. That generally takes in 8 bits at a time (serially), and outputs in parallel – so the requirements of 192 clock cycles to put in all the information would drop to 1/24th. While it’s only 8 bits/chip, chips can be chained to get the 16 bits. But the timing requirements would still be only 1/12th of what using the 5940 needs. And there’s known to be kernel glitches that affect the output – where the pins lock for ~500 microseconds periodically, presumably because of background processing. I’d be nice-ing the program running on the Pi, clearly.

Also, the fast timing requirements may give me the chance to implement 192 level fading – or 7.5 bits of brightness control, because I could hook up the PWM counter/clock to the same line that drives the input clock, so every input cycle is one PWM cycle, which would get me the 192 levels of brightness. Bitmasking and other bit-level screwery would be required though – though that’s more experimenting than anything else.

However, the pros of the 5940:

  1. Built in current limiter – no need for an extra resistor
  2. Single chip gives you 16 outputs
  3. Free from TI’s lovely wonderful sample program, thanks to the fact that I’m in uni.

Possible explorations once I finish the cube include looking at driving the cube standalone with an Arduino clone, and other stuff as I think of it…

No Comments

Django development on Heroku

Because the setup doesn’t match the ‘quick start’ guides…

First, get the dev environment up. I’m using Fedora 17.

  1. The toolbelt install didn’t get properly setup – bash couldn’t find heroku. It was putting it into the $PATH in .profile, but I’m not sure if Bash on Fedora sources that file. Ended up adding an alias to .bashrc: “alias heroku=/usr/local/heroku/bin/heroku”
  2. Installing psycopg2 from pip failed. First it wanted gcc, then postgresql-devel to be installed. (Hat tip to Stack Overflow for the solution.)
  3. PostgreSQL on Fedora didn’t want to start/appear in systemctl until I ran postgresql-setup initdb. This was possibly because I was typoing it, but I’m not sure…
  4. I had to activate PostgreSQL through the addons panel in Heroku, it wasn’t automatically activated. Then again, apparently once a Django application is detected, a database is automatically setup.
  5. Because I used Heroku on another system, ssh keys were setup. Added the dev one with heroku keys:add.
  6. Despite adding the PostreSQL addon, I had to ‘promote it’ to the primary database; it wasn’t done automatically.

The rest of my problems were django based. (Also, unexpectedly long commitments. Oh well.)

 

No Comments

Nginx & php-fpm configuration

Edit: Everything below is pretty much superseded by a new post.

php-fpm: /var/lib/php/session was owned by root:apache, so php-fpm couldn’t create session files. Fix was chgrp nginx /var/lib/php/session. For some reason, after doing  yum update, /var/lib/php/session was changed back to root:apache, but that was only noticed on one system so far, haven’t observed it on others, but also haven’t looked for it.

nginx: By default, index.php files aren’t though of as index files. Fix is to add ‘index.php’ to the ‘index index.html’ line.

Alternatively, autoindex.

 

No Comments

Review of the Manfrotto 055CXPro3

I picked up a Manfrotto 055CXPro3 tripod for Christmas 2011. At that time, I started off writing a short review of it, comparing it with my then-current 055XProB.

Amazon shipping

  • no problem, earlier than expected
  • price went up after I put it in the cart though
  • center column was damaged in transit, cosmetic marks made by the 3 legs

Tripod itself – compared to 2007era 055XProB

  • 1st impression: Locking different – not really good or bad
  • Good:
    • Covering of screws on latch is gone, washer integrated into screw itself
    • Less parts to loose is always good
  • Bad:
    • Screws to secure latch are now hex head instead of phillips head. Why? I now need a semi-specialized screwdriver to take it apart.
  • Indifferent:
    • Latch and screws on upper & lower leg segments are subtly different. Need to keep track or compare all visually before reinstallation
    • Leg segment tops aren’t molded – additional plastic part used as stoppers. This is probably a direct result of using carbon fiber instead of aluminium.
    • No hand warmers. Using it in winter… is going to be fun.

I’ve also completely dismantled it, cleaned it and rebuilt it. There weren’t any manuals, but I found a part diagram/listing on Manfrotto’s site that helped show how the part fit together. (If that link breaks, I found it under the spare parts section here.)

Took some practice, and a few missteps (particularly with the tension(?) spring securing the center column), but it ended up working fine after clearing the sand out of it. (Where I got sand on it from, I have no clue.)

Once again though, I was disappointed in the need of specialized tools. In this case, a 3/8 (I think) hex key.

, ,

No Comments

A grab bag of half-finished posts

Because I’ve started a bunch of posts, haven’t finished them, don’t really want to delete them but stuff looks potentially useful, and I’m clearing stuff out.

Read the rest of this entry »

,

1 Comment

Fixing the RPC: S-5:AEC-0 error in Google Play

Fix in short: switch Google Play to a different Google Account, and switch back to the original account. It can be a new Google account, or one that already exists on your phone.
I hope that helps, and if you want screenshots & more details, read on. 🙂

(Short version because, apparently, this post is #3 on Google for “Google Play RPC:S-5”, and variations thereof, and putting the fix in the description that Google will show seems like a Good Thing to Do.)
==
If you’re unlucky, like me, you’re getting an error like this when you try to update stuff on your shiny Android 4.1(.1) device: (Edit: Apparently, not just Android 4.1.1, I’ve seen reports of 4.2 breaking too.)

The most common ‘solution’ I’ve seen is to completely remove your Google account, and re-add it.

Which seemed a bit extreme, given that it’d (supposedly) wipe all your stuff off the phone. A solution that I stumbled upon is to simply switch to a different Google account in Google Play (Tap the options button at the top right), install an update, then switch back to your original account, and install the rest of the updates.

Yes, the third option on the list that appears. (I’m not showing my accounts screen because that has my email addresses.)

That got it working for me. It’s possible that you don’t even need to install an app in the other account – just switching back and forth might be enough to get Google Play to update whatever cached file is breaking. (I’m assuming it’s a cached file, that is.)

Apparently, this is an unexpected result of flushing and restarting the Google Services Framework in an attempt to force Android to detect/receive the update to Android 4.2. (Which, sadly, didn’t work for me, possibly because I’m on Wind in Canada. Oh well.)

,

15 Comments

The wonders of the internet

The co-op program here at UW is probably the biggest reason I chose to come here – I much prefer applying stuff I’ve learnt instead of learning all theory (why I’m in Software Engineering rather than plain CS). So as part of that, I’m brushing up my resume (and over the holidays, my personal site, and possibly this blog template, finally fix the annoying picture div problems). And as part of brushing up, I (re-)found an old thing that got published about me. Read the rest of this entry »

, ,

No Comments