Category Archives: Uncategorized

Install any Linux distribution on a Mac

Installing Linux on an new Mac is getting more and more difficult, especially if you want to keep your MacOS installation bootable. There is two particular factor which makes it a little bit harder. The first one is SIP (system integrity protection) and the second is apples new filesystem, APFS.

This is a walkthrough which helps you install the latest Ubuntu Linux LTS alongside with a new MacOS system. If you don’t want Ubuntu, the process is pretty much the same with any other Linux distribution like Debian, Fedora, CentOS etc.

Step 0: Make sure to have a full backup

As installing linux is formaly not supported on macs, it is very important to make a complete backup of your system before starting the procedure. Either by TimeMachine, or by a third party app like Carbon Copy Cloner.

1. Make at least one empty partition for linux.

The absolute minimum is one partition which you will need, but it’s always a wise thing to consider making separate partitions for the swap and/or your home directories.

You can create new partitions with disk utility which is a GUI application or with diskutil, which is a terminal application. If you not used to command line interface, i recommend using Disk Util. Make at least an 5-10GB partition for your Linux system.

It’s very important to create a new physical partition, and not an APFS container! If you can’t create a new partition, you might need to disable local timemachine backups. The following command disables it and deletes local snapshots:

sudo tmutil disable
tmutil listLocalSnapShots / | cut -d '.' -f 4 | xargs -n 1 sudo tmutil deleteLocalSnapshots

Don’t forget to re-enable it after you done with the partitioning (if you need local snapshots on MacOS)

sudo tmutil enable

It is okay to format your partitons to MS DOS FAT, because you can reformat it to ext4 or anything else during the installation.

2. Install refind bootloader

While grub is a very good bootloader, i think refind is much more easier to use.
Because of SIP, the installation of refind is a bit more complicated.

– First download the latest refind and unzip it somewhere on your system disk. Write down the exact location and directory name where you unzipped it.
– Restart the mac holding CMD+R while it boots.
– when it started, open terminal from the utilities menu
– now you need to find the unzipped refind folder. If it is in Downloads, you have to type something like this:

 /Volumes/Macintosh\ HD/Users/[YOUR USERNAME]/Downloads/refind-bin-0.11.3/refind-install

Don’t forget to replace [YOUR USERNAME] with your actual username (without brackets) and check if your refind version matches the name of the directory. Follow the instructions of the installation procedure and restart your mac normally.

3. Install linux

The last step is installing linux on the newly created partition. I highly recommend making a bootable usb drive with etcher or unetbootin. Reboot your computer with the newly created usb disk pluged in.
Choose the USB drive from refind’s drive list.

When the installer starts, never, ever select “remove everything” or anything like this, if you will need the original MacOS partition. In Ubuntu you need to choose “something else”. Set up your newly created MS DOS partitions to format as ext4 or similar, set their usage and mount points.

If you have only one partition, you need to set the mount point to /, and format it as ext4 any other filesystem your system can be installed to. If the installer asks, choose NOT to install grub bootloader to /dev/sda, choose instead the partition you will mount as /.

Make sure to not touch any of MacOS’s partition! Only the ones you just created.

After the installation completed, and it reboots the system, you will see the newly installed linux system in the refind bootloader.

For fully utilize the capabilites of your hardware, you might need to install some closed source drivers.

How to set up a private L2TP VPN server for your iOS or MacOS devices on DigitalOcean

Step 1. Sign up for DigitalOcean

You can get free $10 in credits if you sign up through this link: https://m.do.co/c/ecbd53848776

Step 2. Create a new droplet

Choose the newest Ubuntu distribution. (currently 18.04)
You can choose the smallest standard droplet which costs $5/mo. It is perfectly enough for your private VPN server. You don’t need to change anything else, although you can choose which region you would like to use.

Step 3. Log in to the droplet

You can use your favourite ssh client or you can open the console directly through the web interface.

Step 4. Install Docker on Ubuntu

If you succesfully logged in to your droplet you need to run the following commands to install docker and the vpn container on your system.

# install neccessary packages and docker's gpg key
apt-get update
apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
apt-key fingerprint 0EBFCD88
# add docker repository
add-apt-repository \
   "deb https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
apt-get update
# install docker community edition
apt-get install docker-ce

Step 5. Install the vpn server Docker container

docker pull hwdsl2/ipsec-vpn-server

Step 6. Set up your password in an env file

Replace the words between brackets with your desired passwords. You can check your passwords later if your run “docker logs vpn-server”

cat << EOF >.env
VPN_IPSEC_PSK=[your_ipsec_pre_shared_key]
VPN_USER=[your_vpn_username]
VPN_PASSWORD=[your_vpn_password]
EOF

Step 7. Load the af_key kernel module

modprobe af_key

Step 8. Start the Docker container

docker run \
    --name vpn-server \
    --env-file .env \
    --restart=always \
    -p 500:500/udp \
    -p 4500:4500/udp \
    -v /lib/modules:/lib/modules:ro \
    -d --privileged \
    hwdsl2/ipsec-vpn-server

Step 9. Set up your device

You need to set up a new L2TP type VPN connection on iOS or MacOS.

Your server will be your DigitalOcean droplet’s public IP which is visible on DigitalOcean’s dashboard.
The account will be what you set as VPN_USER
The secret will be the VPN_IPSEC_PSK’s value
The password is what is in the VPN_PASSWORD variable

Missing spaces in laravel mail subject

Laravel uses swiftmailer, which by default, encodes e-mail headers with Qp (quoted-printable) encoding. It works perfectly fine with most of e-mail clients, but there are some of them which seems that couldn’t implement correctly this encoding.

On these clients (for example, outlook connector for mdaemon or yahoo mail which i’m aware of), the space characters are missing in the subject.

In Qp encoding you can represent a space character with an underscore character. (see RFC 2047) Thats what these e-mail clients somehow did not implement correctly. Instead of showing a space character, they simply ignore the underscore character and print the subject without that part.

Fortunately, you can configure swiftmailer to use base64 encoding instead of Qp encoding in the headers, which is essentially solves the problem.

The best way to do it in Laravel, is to create a new MailServiceProvider class in the app folder and register it instead of laravel’s default MailServiceProvider. Then in your newly created MailServiceProvider class, you can simply override SwiftMailer’s default settings.

The MailServiceProvider class in the app folder:


It overrides the original MailServiceProvider’s registerSwiftMailer method, with a new one which configures SwiftMailer’s dependency injection to use the base64 header encoder class.
After this step, if you set the provider in the config/app.php file, your e-mail’s headers will be encoded as base64.

That will be solve this weird problem with these exotic e-mail clients. The space characters will be rendered correctly.

Replacing your Macbook Pro Retina batteries

I’m counting the parts which I didn’t replace in my old 2012 retina macbook pro. It’s not that I wouldn’t like to fix things, but my keyboard, speakers, batteries, and two magsafe cables is a little bit much.

Anyway, I bought an Ifixit repair kit, and it worked fine. They sent all the tools i needed to do the replacement.
They also have a repair guide which is very clear. A few notes I would add.

  • drain your old batteries fully to prevent any fire caused by physical impact while removing the old battery
  • you dont need to cover your screen if you place your computer on the edge of the desk, hanging the screen down.
  • be careful with the glue stripes, you cannot move the batteries if they stuck on the top case.
  • After the installation, the measured capacity changed erratically. Don’t worry, just keep doing recalibration a couple of times, and it will work correctly.

Replacing a Macbook Pro Retina keyboard

I have a 4 year old MacBook Pro Retina 13″. A few months ago a very small amount of liquid spilled on my keyboard. I started to belive that I got away with this, but last week, my T key started to work improperly. Here is where the story begins.

I started doing my usual research to find the best way to replace or fix the keyboard. I’m a long time apple user so I didn’t expect any good news. If you have a retina MacBook Pro or MacBook Air, and you need to replace your keyboard, the first shock is finding out that your keyboard is riveted to the top case. Unlike screws, rivets are permanent fasteners. This means you cannot remove them without damage. An authorized apple service provider would just replace the whole top case, and probably your local apple service shop may do the same. The top case contains the keyboard, the trackpad, and the batteries, so it is definetely not the cheapest solution.

Luckily, there are some clever people who tried to replace only the keyboard with success. And they are shareing their experience. There are a lots of videos on youtube, a lots of posts on forums, and replace guides on ifixit about replacing macbook keyboards. I’m sure you can find at least one guy who have the same model number as your’s and posted some information about the process.

I have an A1425 model and I’m writing this post to share my experiences.

Buying the replacement keyboard

  • The backlit and the keyboard are two different part, and usually you need to buy them separately.
  • yes, you have to replace both, its very hard to remove the backlit without damaging it.
  • you should double check that you are buying the right model, the right layout (language), and your enter key and left shift key has the correct size.
  • You can buy them on e-bay, or from some more reliable source, but don’t spend too much on it. You are going to get a cheap chinese copy anyway.

Preparing for the surgery

  • You need some special screwdrivers for the pentalobe and tamper free TORX screws. The list depends on your model.
  • You really need a good wire cutter to remove the rivets. it’s going to be a nightmare even with a good tool. I can recomend something like this: http://www.amazon.com/dp/B00FZPDG1K/?tag=tolnaiz-20
  • watch as many videos as you can, especially if you are not really experienced in repairing electronic devices.

Doing the repair

  • Only start the repair if you have several hours distraction free. You are gona need to remove the complete logic board, and thats not a five minute task.
  • Only start if you are ready for a really stressful job. Those rivets are going to drive you crazy.
  • Try to remember which screws going to where. Better if you take notes about it.
  • There is this little plastic layer on the end of the keyboard connector. You don’t need to remove it.
  • It some keys are not working after the replacement, try to move the keyboard cable a little bit.
  • If you cannot remove some rivets, thats not a big problem, but remove as many as you can and put screws in their place. The more screws you put in, the more sturdy your new keyboard will be.
  • Do the repair with an open lid. Place the laptop on the edge of the desk, with a hanging display. This way the screen remains clean.

These are the most important thinks to keep in mind I think.

Good luck with your repair!

00:39:30,377 –> 00:39:33,247
If you’re wondering if this hurts…

00:39:33,281 –> 00:39:35,949
Yeah. It hurts a lot, but…

00:39:35,982 –> 00:39:38,552
I get it.

00:39:38,585 –> 00:39:42,022
I’ve known Angela since I was eight.

00:39:42,056 –> 00:39:44,458
This is what she does.

00:39:44,491 –> 00:39:47,427
She doesn’t love the
people who love her.

00:39:47,460 –> 00:39:50,464
She loves the people who don’t.

00:39:50,498 –> 00:39:53,835
This is her power-saver mode.

How to receive push notifications from your rtorrent client

1. step:

Download pushover to your device, register, and create a new app on their site:
Name it as you like, eg. rtorrent. Pick a nice icon for the app.

You will need 2 keys for the next step:
– your user key
– and your app’s key

2. Set up a script which will handle the rtorrent’s events.

Ruby needs to be installed on your system.
Open your favourite editor and paste the following script:

#!/usr/bin/env ruby
require "net/https" url = URI.parse("https://api.pushover.net/1/messages.json")
req = Net::HTTP::Post.new(url.path) 
req.set_form_data({ :token => "YOUR_APP_KEY", :user => "YOUR_USER_KEY", :message => "start " + ARGV[0], }) 
res = Net::HTTP.new(url.host, url.port) 
res.use_ssl = true res.verify_mode = OpenSSL::SSL::VERIFY_PEER 
res.start {|http| http.request(req) }

Replace the two placeholders with your keys (YOUR_APP_KEY and YOUR_USER_KEY)
You would save it to /usr/local/bin (you need administrator privileges) and then make it executable:

chmod +x /usr/local/bin/rtorrent-pushover.rb

At this point, you can try it working with the following command:

/usr/local/bin/rtorrent-pushover.rb "test message"

3. Change your rtorrent config to call the notification script.

Add the following line to your ~/.rtorrent.rc file:

system.method.set_key = event.download.inserted_new,notify_me,"execute=/usr/local/bin/rtorrent-pushover.rb,$d.get_name="

If you would like, you can set up another notification for the finished torrents.
In this case, the only thing you should change is the “event.download.inserted_new” to “event.download.finished”.

If you’ve set up everything correctly, you should receive notifications about new torrents to your device.