Link shortening using your own domain

Short links; they’re all the rage, amiright? There are a ton of services out there; Goo.gl and Bitly.com just to name a couple popular ones. Not only do they provide the link shortening, but they also give you some analytics so you can see how many clicks you got on your short url and where they came from. The only problem with using a service, though, is you don’t have much control. You’re also sharing links that everyone else using that same service is sharing.

I came across the open-source YOURLS site. It pretty much consists of a few PHP scripts that allow you to run your own link shortening service on your domain. I played around with it on one of my test servers to see what was involved and was impressed with the simplicity. It took me about 20 minutes to get everything setup and functioning.

Alright, let’s get to it.

Read More

Custom searches for your browser

Let’s say you have some websites that you frequent on a regular basis. Let’s also say you have some websites that you frequent but also send custom information in the URL to – say, a specific commit to your git repository. Wouldn’t it be neat if you could get to those websites faster and with less keyboard mashing  typing? Enter custom searches for your browser!

Alright, let’s add some custom searches to your browser

First off, this will definitely work for Chrome and Firefox. I’m not certain if it works for others.

Adding custom searches to Chrome

edit search engines screenshotRight-click on the address bar and select the Edit Search engines… option. This should open a new tab and bring you to “chrome://settings/searchEngines” (Alternatively, you could just enter that to the address bar). On this page you’ll find the default search engines like Google and Yahoo but below that list you’ll see a list of search engines labelled “other”. This is where the magic is.

add search engine form

  1. Click the input box for Add a new search engine and add a name. For example: My Repo.
  2. In the input box for Keyword add the keyword you want to use to activate this new search. For example: autourl.
  3. In the input box for URL with %s in place of query add the URL you want to head to when entering the keyword in step 2. For example: https://github.com/dougdragon/automate_URL_test/.

Now, when you enter autourl in the address bar, you’ll be taken right to https://github.com/dougdragon/automate_URL_test/.

Pretty good magic, right? Want even more magic? Check this out: say you wanted to see a specific commit on the repo above. Follow these steps to add a custom keyword that also takes a parameter.

  1. In the input box for Add a new search engine and add a name. For example: My repo commit.
  2. In the input box for Keyword add the keyword you want to use to activate this new search. For example: autocommit.
  3. In the input box for URL with %s in place of query add the URL you want to head to when entering the keyword but this time you’ll want to add a %s for the query. For example, to see a specific commit from the github.com/dougdragon/automate_URL_test/ repository, I would add the following to the URL input box: https://github.com/dougdragon/automate_URL_test/commits/%s.

Now, when you enter autocommit in the address bar and press the space bar, the address bar will show the name of your search engine and prompt you for the parameter. Paste in the commit hash into the address bar and hit enter and you’ll be looking at that specific commit on your repository!

screenshot of repocommit

 

Adding custom searches to Firefox

Adding custom searches to Firefox is a little more involved. Here are the steps:

  1. First, you have to save the URL to your favorites.
  2. After saving the URL to your favorites, you’ll need to go to the bookmark library
    1. You can get there by clicking the Show All Bookmarks or pressing Ctrl+Shift+B
  3. Locate your saved bookmark and select it.
  4. Once it’s selected, you should see a More button on the bottom of the page.
  5. Clicking the More button shows some extra information about this bookmark, one of them being Keyword. Enter your desired keyword here.
  6. If you want to be able to add a parameter to the query, throw in the same %s where you want to add the parameter to and it’ll perform just like the Chrome search.

Hover event in Selenium

Hover using Selenium webdriver’s ActionChains

I was recently trying to figure out how to perform a hover event using Selenium’s webdriver. The team I had previously worked on wrote a nifty function using execute_script invoking jQuery. It looked something like this:

self.driver.execute_script("jQuery('%s').mouseover()" % (hover_selector))

This didn’t always work the way I expected so I did some research and came across webdriver’s ActionChains. From Selenium-Python’s ReadTheDocs:

ActionChains are a way to automate low level interactions such as mouse movements, mouse button actions, key press, and context menu interactions. This is useful for doing more complex actions like hover over and drag and drop.

I whipped open my terminal, fired up webdriver and headed over to the trusty the-internet to give it a whirl.

The page I ran this test on was the-internet.herokuapp.com/hovers.

Here’s the code:

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Firefox()
driver.get("http://the-internet.herokuapp.com/hovers")
image = driver.find_element_by_css_selector("div.figure:nth-child(3)")
link = driver.find_element_by_css_selector("div.figure:nth-child(3) a")
# Now comes the magic
ActionChains(driver).move_to_element(image).click(link).perform()

When I ran this in my console, the browser hovered over the image then clicked on the View Profile link that appears after the hover.

Magic.

 

IFTTT to the rescue!

I recently received an email from TimeHop letting me know they had decided to sunset their Daily Email feature and will be focusing on their mobile app. The Daily Email feature was a simple email sent each day with your social media posts from a year ago. It’s a simple enough feature but I enjoyed seeing my posts from a year ago that day and didn’t want to stop receiving them.

I started to think about writing my own simple application that would remind me to check the TimeHop page each day when I remembered about the amazingly useful site called IFTTT. Read More

Enabling 2-step verification on your Google account

Want to add another layer of security to your Google account – try enabling “2-step verification”.

Some things to understand before enabling 2-step verification for your Google account:

  • Certain applications won’t work with your normal Google password with 2-step verification enabled. These applications include:
    • Smartphone (Android, iPhone, etc) email apps
    • Email clients that use IMAP/POP (Outlook Express, Thunderbird, etc)
    • Chat clients (Google talk)
  • Anytime you log into your Google account from a different computer than you’ve specified as a trusted computer – more on this below
    Read More