Author: andrew

Clean Architecture – SOLID Design Principles Summary

Clean Architecture is a book by “Uncle Bob” Robert Martin as a followup to his popular Clean Code. It includes a brief section about the SOLID principles, which are the touchstone of his programming philosophies, and have been described in his other books.

This summary is a cheatsheet to help you remember the SOLID principles in your day-to-day work.

 

The SOLID Principles

  • Single Responsibility – each module should only have one reason to change
  • Open-Closed – Design software so its behaviour can change by adding code – not changing the existing code.
  • Liskov – Use interfaces/protocols to separate interchangeable parts
  • Interface Segregation – Dont depend on things you don’t use
  • Dependency Inversion – High-level code shouldn’t depend on low-level implementation

Solved – Safari can’t load page but Chrome can through VPN

I ran into an issue a few days ago where I couldn’t get through to my work’s git server from Safari, but Chrome was able to access it fine.

I assumed the problem was in Safari, and tried resetting Safari preferences and clearing caches, but that didn’t work. I also edited my hosts file recently, which has been a cause of this complaint for other users, but nothing in that was out of the ordinary either.

The culprit: Charles Proxy.

I use Charles Proxy regularly for work. Charles is a great tool and all, but it makes changes to your computer’s network settings and doesn’t always clean up after itself. It functions by operating a proxy server on your local machine so that you can observe traffic and debug your networking code.

Specifically, it sets up a global proxy in macOS’s native System Preferences > Network. It’ll go into whichever network is currently active, go to the Advanced options and enter the details.

In order to maintain access to the internet after the proxy stops, these values need to be removed. In its normal shutdown process, Charles will usually switch these back. But if it crashes they don’t get cleaned up. Just go in and uncheck the proxies that are enabled.

 

These proxies can also be set on VPN networks that are listed in the System Preferences.

Font Awesome Doesn’t Work with Firefox – SOLVED

Font Awesome is awesome, except that it doesn’t work with Mozilla Firefox or Google Chrome out of the box (see what I did there?). So if you’re seeing little squares instead of the icons you’re expecting, here’s the solution.

Open the .htaccess file for your site and add the following code:

<FilesMatch ".(ttf|otf|eot|woff)$">
  <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
  </IfModule>
</FilesMatch>

This is a great snippet that I found here.

If you don’t already have an .htaccess file, create one in the root directory of your site. It is a plain text file and must be called exactly “.htaccess” (no that’s not just the file extension). I’m using WordPress so this is what my .htaccess file looks like now:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

<FilesMatch ".(ttf|otf|eot|woff)$">
 <IfModule mod_headers.c>
 Header set Access-Control-Allow-Origin "*"
 </IfModule>
</FilesMatch>
# END WordPress

Refresh your browser and your icons should now appear.

If this doesn’t work, make sure you don’t have another copy of font awesome installed. This could happen, for example, if you are using WordPress and you installed a fontawesome plugin, or if you tried uploading a newer version in some previous frustrated attempt to fix this.

Auto Increment Build Number in Xcode

This is a great Copy-Paste solution for every solo iOS Developer. It automatically increases the build number of your Xcode project every time you Run your program.

Two Facts:

  1. You now have a reason to have a build number.
  2. You will spend less than a minute on this. And never worry about it again.

Go to your Project’s Build Phases tab, and click the + button. Choose New Run Script Build Phase then drag the Phase to be second (after Target Dependencies).

In the space after the shell’s /bin/bash, copy this:

<code>#!/bin/bash
bN=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
bN=$((0x$bN))
bN=$(($bN + 1))
bN=$(printf "%X" $bN)
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $bN" "$INFOPLIST_FILE"</code>

 

Works like a charm. Just make sure your build number starts as “1″ and not “1.0″. This great solution was originally posted by RobertL on Stack Overflow but I liked it so much I’m sharing it!

I think this would be particularly powerful if cleverly extended to work with version control.

SOLVED – iMessage Activation error: “An error occurred during activation. Try again.”

While going through the process of migrating to the iPhone 5c, I got the error message: “iMessage Activation An error occurred during activation. Try again.”

iMessage Activation error after restoring iPhone Backup - An Error occurred during activation. Try Again.

I was also missing incoming iMessages that I could see coming into another device.

My situation is unique in that I am not recovering lost data or a corrupted iPhone. I backed up my old iPhone to iTunes on my computer, and then restored the iTunes Backup onto my new iPhone. There were also errors installing many of the Apps onto my phone. But if you’ve received this error while trying to restore your iPhone backup, this confirmed solution will work for you!

iPhone Battery Icon Drained

iOS Battery Issue – SOLVED

I upgraded my iPhone 5 to iOS 6.1.2 this week, and was disappointed to see a huge drop in battery life.

Previously, I could easily make it through the day without charging but after upgrading I was down to 3-4 hours on standby and my phone was constantly over-heating!

I FIXED IT!

UPDATE: Definitely worked for me. 99% after 1.5 hrsstandby. 100% after 1 hrs regular usage!

UPDATE: Added confirmed solutions for iOS 6.1.3 and iOS 6.1.4.

I had read that a bug in iOS 6.1.1 was causing problems with battery life and that it was related to having a Microsoft Exchange Email on your phone. So I thought, maybe this is a similar bug. Different things seem to be working for different people, but it looks like there’s some sort of (UPDATE: try disabling Push email. See below)

Solution 1 – Re-Install Microsoft Exchange Email

Add Account

Step 1 – Delete Exchange Email Account

Go to Settings > Mail, Contacts, Calendarsand click on your Exchange email account. Make sure you have your emails backed up on the server (login to the email account on your computer) and then click Delete Account.

Step 2 – Reset Phone

Hold down both the Lock and Home buttons until the phone shuts off. Then turn it back on.

Step 3 – Set up Exchange Account

Create New Exchange Email

Return to the Mail, Contacts, Calendars page and click Add Account. Enter all your account information and voila! Your battery life should be back up again!

Didn’t work? Try it with all of your Hotmail and Gmail accounts at once.

Still didn’t work? Try the next solution.

Solution 2 – Disable Push Email 

A very popular solution seems to be disabling Push email. Go to Settings > Main, Contacts, Calendars > Fetch New Data. Set Push to OFF. Then click Advanced, and make sure that each email is set to Fetch instead of Push.

Still didn’t work? Try these other solutions.

Solution 3 – Router firmware

Multiple users on the Apple forums have reported seeing the WiFi and 3G/LTE icons switching back and forth every 15 seconds or so while connected to a WiFi network. This seems to be caused by out-of-date firmware for their NetGear routers, which caused the iPhone to constantly reconnect to the network. Their solution was to update or revert your router’s firmware and hope for the best. This has worked, but it only applies to the alternating icons problem.

Other Solutions

Lot’s of other options have cropped up, all related to network activity. Other people online have found these things to be solutions:

  • Quit Apps with Hanging Downloads. If you have iTunes U, iTunes Match, or the App Store running with downloads waiting in the background, they are fighting for data. To quit these apps, Double-Tap the Home Button to show the multitasking tray,Press and Hold an App Icon, and tap the red QUIT icons.
  • Update to the latest version of iOS. Apple does in fact try to fix these problems so the latest update is always worth a shot.
  • Disable Documents in the Cloud.
  • Remove the SIM card, disable all network connections, restart iPhone, insert SIM card (only seems relevant to people outside the US)
  • Remove ALL email accounts, restart iPhone, re-install ALL email accounts
  • Sign out of Facebook, restart iPhone.
  • Do a completely fresh install of iOS (Don’t forget to back up to iTunes or iCloud)
  • In iTunes, go to edit>preferences>devices and check “prevent ipods, iphones and ipads from syncing automatically”
  • Check that the SIM card is seated properly in it’s tray. If the contacts aren’t cleanly connecting to the phone, you could be wasting energy. This is especially important if you cut your own SIM card out of the old one.
  • DONT USE AN ALUMINUM CASE. This aluminum blocks the 3G signal from reaching your phone. When the phone is struggling to get service, it works much harder and runs the radio signal at a higher power level. Your case is forcing your phone to work too hard!
  • NOTE: You may need to let your battery die and then recharge before the changes take effect!!

What worked for you?

Other solutions?

Leave a comment below!

Page 2 of 2

Powered by WordPress & Theme by Anders Norén