Bluehats

Software Artisans.

How-To Upgrade Your Wordpress Blog to an Octopress Blog

Recently I upgraded this blog from Wordpress to Octopress. I’ll walk you through on the process I followed.

I’ll assume you already have Octopress up & running, if you don’t you can follow setup instructions at Octopress.

Now let’s export your Wordpress data, go to http://yourblog.com/wp-admin/export.php and select to export all your content.

Export All Content

This will give you a .xml file which we will use to transfer your comments to disqus after transfering your posts.

To transfer your posts we’ll use a tool called exitwp

Let’s start by cloning the repo

1
2
git clone git@github.com:thomasf/exitwp.git exitwp
cd exitwp

Install dependencies

1
2
pip install pyyaml
pip install beautifulsoup4

Copy the .xml file into wordpress-xml folder and check if it’s valid

1
2
3
4
5
# copy the .xml file into wordpress-xml
cp ../path_to/exported.xml wordpress-xml/exported.xml
# check xml is properly formated with xmllint
xmllint wordpress-xml/exported.xml
# solve any errors you encounter

Run the converter

1
python exitwp.py

This will generate your posts inside build/jekyll/yourblog/_posts , copy all the posts files into your posts files

1
cp -r build/jekyll/yourblog/_posts ../octopress/source/_posts

You have now finished exporting your posts to your Octopress blog; now let’s export the comments to Disqus.

First create an account at Disqus

After you’ve created your account let’s Register your website at Disqus Add Disqus site

Take note of your ‘shortname’ we will be using it next.

Now let’s add Disqus to your blog, open your _config.yml.

Find the comment #Disqus Comments and add your shortname on disqus_short_name: myblog this will automagically setup Disqus on your blog.

Now lets import the comments on Disqus, we will be using the same .xml file.

Visit the admin panel then click on Discussions and select your newly created site.

Inside here click on Import and the Wordperss import should be already selected, click Choose File and select your .xml file

Click Upload and Import

Import Disqus Comments

This will upload your current comments to Disqus, if your url’s won’t change you can stop here and in a few hours all your comments will be appearing on your new blog! But if your url’s will be chaning you have to map the old url’s with the new url’s.

To do this click on Tools (on the same page you clicked Import) and select the most appropiate method for merging threads, in my case I used Url Mapper.

Migrate threads

Click on the link that says you can download a CSV here that will email you a CSV file which will contain all the old url’s, you will have to map this url’s with the new one’s.

Upload URL maps in CSV format (comma separated value). The correct format is:

1
2
http://example.com/old-path/old/posta.html, http://example.com/new-path/new/posta.html
http://example.com/old-path/old/postb.html, http://example.com/new-path/new/postb.html

You can also add a 3rd party theme to further customize your blog.

Don’t forget to run

1
2
3
rake generate
git add -A
git commit -m "finish upgrading wordpress to octopress"

Which will make all the static files for your website.

You have successfully upgraded your Wordpress Blog to an Octopress Blog, now just Deploy your blog.

How to Bypass Hotspot Logins on a Mac

If you are reading this you have probably faced a Hotspot at an airport, hotel, cafe etc. where the WiFi access was open but you faced a Hotspot login portal asking you to agree terms & conditions or pay a fee.

Luckily there’s an easy way around this which is based on how the portal allows some devices in and the other not.

Every device that connects to a network has a MAC address this address is embedded in your device and is unique. This is what the Hotspot checks to see if you are allowed to access the internet or not.

What we are going to do is called ‘MAC Address Spoofing’. Doing this will help us impersonate another device on the network which hopefully does have internet access.

Open Terminal

We need the MAC address we are going to impersonate. To get all MAC address in you ARP cache run

1
arp -na | sort -u -t' ' -k4,4

This will give you a list of ip address with their corresponding MAC addresses. Save this list we will be using it later.

Now we have to change our MAC address to one of the list and luckily will get internet access. To change(spoof) your MAC address run

1
sudo ifconfig en0 ether 00:00:00:00:00:00

where 00:00… is the MAC address to spoof.

Now just turn off and on your WiFi try and access http://bluehats.mx/blog if you face a Hotspot login try another MAC address from the list, if not you are already connected to the internet!

If running arp -na didn’t give you results or the MAC addresses you tried didn’t give you internet connectivity you will have to ping all devices with nmap here is how to do it:

To ping all devices on the network with nmap you need to have installed nmap on your mac the easiest way is thru brew which if you don’t have installed you have to install it to.

After installing brew  run

1
brew install nmap

Now we need to know which addresses and netmask we are going to ping. So run

1
ifconfig | grep inet

and look for one that starts with 192.168.X.X, 172.X.X.X or 10.X.X.X like:

1
inet 192.168.2.156 netmask 0xffffff00 broadcast 192.168.2.255

To convert the hexadecimal netmask to decimal look it up at http://www.pawprint.net/designresources/netmask-converter.php

Mine is /24

Now let’s ping all the devices, depending on the address and netmask you got is what you will ping.

Examples:

For 192.168.2.156 netmask 24

1
nmap -sn 192.168.2.0/24

for 172.16.0.156 netmask 16

1
nmap -sn 172.16.0.0/16

for 10.5.4.2 netmask 8

1
nmap -sn 10.0.0.0/8

Now run again

1
arp -na | sort -u -t' ' -k4,4

The list will now have all devices connected to the network.

My Top Aliases and Functions for Terminal

This are my top aliases for terminal, I’ve order them on how frequently I use them and separated by topics.

To add this aliases and functions to your terminal simply run 

1
 vim ~/.bash_profile

if it doesn’t exit it will create a new one.

Git

1
2
3
4
5
6
7
8
alias psh="git push origin" #push to origin specifying branch, ex. psh master
alias pll="git pull origin" #pull from origin specifying branch, ex. pll master
alias cmm="git commit -m" #commit
alias cmma="git commit -am" #commit and add modified files
rgc() {
  git commit -m"`curl -s http://whatthecommit.com/index.txt`" #get a random commit message from whatthecommit.com
}
function gc() { git clone "$1" && cd `echo "'$1'" | cut -d/ -f2 | cut -d. -f1`; } # clones git repository and cd's into it

Files and Folders

1
2
3
alias dev="cd ~/Copy/Development" #cd to my development folder
alias editbash="mvim ~/.bash_profile" #open my bash_profile in MacVim (you can change this to the editor you wish)
function mcd() { mkdir -p "$1" && cd "$1";} #mkdir a folder and cd into it

DNS

1
alias cleardns="sudo killall -HUP mDNSResponder" #clear dns on 10.8+

Changing Mac Address(I’m using en0 check which interface you use running ifconfig)

1
2
3
4
5
6
7
alias mac="sudo ifconfig en0 ether" #specify a mac address, ex mac 11:22:33:44:55:66
alias mymac="sudo ifconfig en0 ether 11:22:33:44:55:66" #revert back to my mac address, you have to check you mac address first.
alias chkmac="ifconfig en0 |grep ether" #check the mac I currently use
alias ranmac="openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'" # generate a random mac address
rmac(){
  sudo ifconfig en0 ether `ranmac`; #apply a random mac address
}

Beautiful Terminal (when on a git repository it show the branch you are on)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Git branch in prompt.
parse_git_branch() {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
function prompt {
  local GRAY="\[\033[0;37m\]"
  local WHITE="\[\033[1;37m\]"
  local GREEN="\[\033[0;32m\]"
  local CYAN="\[\033[0;36m\]"
  local MAGENTA="\[\033[0;35m\]"
  local RED="\[\033[0;31m\]"
  local BLACK="\[\033[0;30m\]"
  local YELLOW="\[\033[0;33m\]"
  local BLUE="\[\033[0;34m\]"
  export PS1="${GREEN}\u@${WHITE}mbp:${RED}acrogenesis${WHITE}\$(parse_git_branch) \w \`if [ \$? = 0 ]; then echo -e '\[\e[01;32m\]\n\xF0\x9F\x9A\x80'; else echo -e '\[\e[01;31m\]\n\xF0\x9F\x9A\x80'; fi\` \[\e[01;34m\]\[\e[00m\] "
  export CLICOLOR=1
  export LSCOLORS=GxFxCxDxBxegedabagaced
}
prompt

[gallery columns=“2” link=“none” type=“slideshow” ids=“48,47”]

How to Bypass API Restrictions

Don’t you hate it when a free API has limits on the number of request you can do? I was hitting the wunderground.com and openexchangerates.org API’s limits often. The problem was when we had a traffic spike. We didn’t want to pay for premium the same way we don’t want to pay extra bandwidth in case of a spontaneous traffic surge. So we came with the idea to cache it. Here’s an easy way to ‘cache’ the API’s JSON response.

First of all let’s create a shell script (.sh) (I’ll be doing the example for the wunderground API) and add some code (I use VIM, the vim command will create the file)

1
vim getWeather.sh
1
2
3
#!/bin/bash
cd /home/user/pathto/weatherapi
wget -O http://api.wunderground.com/api/heregoeskey/forecast/lang:SP/q/Mexico/Monterrey.json

This script works as follows: It goes to the path where you created the getWeather.sh  get’s the json from the API we are trying to bypass restrictions.

Now instead of calling api.wunderground.com on your website call mywebsite.com/pathto/weatherapi/Monterrey.json this will give us the same file but locally bypassing the amounts of calls done to the api server.

Now we need to refresh the file we made locally so for this we make a cronjob, to make a cronjob type

1
crontab -e

This will open the cron editor, just add the following and we should be refreshing our local json every hour

1
0 * * * * /home/user/pathto/weatherapi/getWeather.sh

The api call to the service will only be done every hour instead of every hit on your website. Now we are good to go!

Good luck! @acrogenesis

Thanks /u/Cixis for some suggestions