Here’s a simulation of the Monty Hall Problem.
Switching really doubles the probability to win. Dang it. ;)
Here’s a simulation of the Monty Hall Problem.
Switching really doubles the probability to win. Dang it. ;)
Just a reminder for myself. How to fold and unfold code in XCode:
I’ve just uploaded my new app. It is called “Zones” and it’s one of those desktop helper tools for Mac OS X. You can take a look at Zones here.
It was fun to do and I learned a bunch of stuff about Mac OS X. It was probably also the last side-project ever written in Objective-C for me, since the Apple world is switching to Swift now. (Which is good.)
Sadly, I cannot distribute the app through the AppStore, because it cannot be sandboxed using the APIs it does (Accessibility). Which means I will probably never earn enough money to buy a happy meal with it.
I needed to go back to iOS 7 after a few apps, most notably Whatsapp, no longer worked properly. I also had no restore points for some reason.
Here’s a way to turn your iOS 8 iPhone back into an iOS 7 iPhone:
You don’t need to donwload any images before hand, iTunes will do it for you.
In my case I ended up with a completely blank iPhone. But I could restore Contacts, some settings etc. from iCloud.
Another iOS code-snippet:
I had a UIPageViewController in scrolling-mode that would allow to pan between view-controllers using a finger gesture. However, I wanted to restrict the panning area to a certain area of the screen, for example as shown in this screenshot:
I do it by subclassing the UIPageViewController, finding its UIScrollView, and adding a new UIPanGestureRecognizer to that scrollView.
I set my subclassed UIPageViewController to be the delegate of that new UIPanGestureRegognizer. I then implement two delegate methods:
In the last override I decide if I want to “eat the event” (reply YES) or if I want the original UIPanGestureViewRecognizer of the UIScrollView to handle it (reply NO). So, the YES-reply means the UIPageViewController will not scroll to the next ViewController.
Here are two code snippets for rotating and resizing UIImage’s without using UIGraphicsBeginImageContext(), because it is not thread-safe and can lead to weird behavior.
In my case the camera-preview when taking a picture in an app I was writing, turned black from time to time. The problem was that I was rotating and resizing the images using UIGraphicsBeginImageContext().
Here’s some code I’ve found and tweaked to resize images:
And here’s how to rotate them:
Because the above takes radians, convert using something like this:
Just put these methods into a category on UIImage.
This kept me busy for a while until I found a super simple way to do it: In this tutorial/code-snippet I’ll show you how to write an image-cropper for your iPhone-app.
What do I mean by image-cropper?
Bascially, it’s about giving your users a simple way to select part of an image using pan and pinch gestures. This can be handy when they upload a profile picture or something similar.
Here’s the end result:
How it’s done:
There is one UIScrollView with a large contentSize. Embedded in the scroll-view is a UIView (baseView). And embedded in the baseView is the UIImageView with the Ferrari-picture.
The yellow boxes in the above image represent the iPhone screen and the cropping area.
Because the contentSize is bigger than the bounds of the screen (= frame of _scrollView), the user can pan to select the desired image. Because minimumZoomScale and maximumZoomScale are set, the user can pinch to zoom. (Although I am not sure why it helps to set the initial zoomScale after all other initialization. If it’s done earlier it won’t scroll until zoomed.)
The actual cropping is done by rendering the contents of the view-controller’s view into an ImageContext and then cutting out the portion that (here: roughly) corresponds to the non-dimmed “window” in the center.
The image is then saved to the phone’s photo gallery.
Get the example project from Github and take a look at the code. It’s actually very simple and self-explanatory.
Here’s the actual cropping code that is executed when you tap the “OK”-button.
Very straightforward stuff.
But as I said, it took me a while. For some reason I never thought of taking a screenshot first.. ;)
Also this solution has the limitation of pixel size. If you want to crop an image of for example 10000 times 10000 pixels and get half of it, you would expect a 5000x5000 pixel result. However, because of the screenshot technique, the cropped area will never be bigger than the pixels on the iPhone screen.
I’ve scrapped the website where I offer setting up your email-server. While it was fun to learn and experiment with, and while some have expressed interest in the offer, it’s neither pracitcal nor profitable for me to continue offering it.
Please refer to this post for information how to start with the email topic yourself. It describes a simple way of setting up an emailserver with Ubuntu.
I just ditched Google Analytics. It’s like a reflex to add it into website projects, but I don’t really need it. Nor do I want it. I think Google has enough information about us already. And they freely share with the American government it seems. So yeah, goodbye.
Now I’m using one of these tools. I can execute a shell script on my computer now and seconds later I have all the analytics I need. Good looking, useful and best of all, not shared with Google.
There are very good reasons to want your own e-mail server. I’ve tried several setups and found the Courier-mailserver the simplest to work with. Here’s a tutorial on how to set it up.
This should take about 15 - 30 minutes.
Here’s what you will have in the end:
Here’s what you need:
Ok, I will explain to you now how to install the Courier mail suite. I know there are several popular other ones, but this just happens to be a guide about Courier.
If you get stuck or have special config needs, then please also refer to the end of the article where I list a few helpful links.
First, connect to your email-server using SSH. Make sure you can execute commands with sudo. Start with
to update your packet sources.
Installation time:
telnet is in there for testing. You can remove it if you you want, but telnet is nice to check if SMTP works and what its configuration is.
Enter your domain in /etc/courier/locals. Do the same in /etc/courier/esmtpacceptmailfor.dir/domains.
Run sudo makeacceptmailfor to have these changes accepted.
Create a user, let’s say “suntke” (I think that’s a Frisian first name..).
And create a password for him.
This user can login to your linux-box now using the password you specified. Now, let’s create a maildir for him.
(prefix with sudo as needed. The -q flag sets a quota. Just use some high number..)
So, let’s say the domain-name was “example.com”, then this means you have just created the email-address “suntke@example.com”. Incoming email will be stored in /home/suntke/Maildir.
You can add as many users and domains as you like.
You can now go ahead and send and receive emails. However, I suggest you add some extra security through encryption.
In /etc/courier/esmtpd-ssl set AUTH_REQUIRED to 1. This forces authentication. In /etc/courier/esmtpd set ESMTPAUTH=”LOGIN PLAIN”.
/etc/courier/esmtpd.pem should exist and be not world-readable. This should automatically enable ESMTP STARTTLS, encrypted SMTP.
When you are done, you can restart everything: (added newlines for readabilty)
So, this was the server-side. Let’s go ahead and configure a mail-client. I will jsut go ahead and use the fictional user/address suntke@example.com here, as well.
Here’s the settings in Mail on OSX. It’s pretty much analogous with Thunderbird etc.
Use your domain registrar’s console (or do it yourself) to set the MX record. In this case you’d just set example.com, because you didn’t configure any subdomains such as mail.example.com.
Your Mail-program or OS will probably complain about the certificates not being signed. You can decide if you want to have them signed. It doesn’t make much sense if it’s just for yourself. Mark the certificate as “trusted” or add them to your “trusted certs” collection in your keychain.
Try restarting both the server processas as well as your mail-client. Make sure your system trusts the certificates. Double-check your passwords.
As I was trying to verify this tutorial on a testing server it wouldn’t work at first, but restarting the client and accepting the certs permanently did the trick.
That’s it, congratulations. You have your own email-webserver. Here’s a few ideas on what you could do next:
Here are some links that might help you with Courier:
If you have something to add or correct, please let me know so I can update this guide. Let’s spare others extra work and frustration..
In case you mess up along the way and then get errors like “Mailbox unavailable” (but you have already solved the underlying problem), you can reset a mailbox like this:
I needed this recently when I could not figure out what the problem is. Turns out, I solved the problem earlier but didn’t clear the “broken mailbox flag”.