Friday, November 24, 2017
Home Code

Code

A place for code php, ruby, javascript, jquery, html, css etc.

Block bots and crawlers with .htaccess and robots.txt

If you want to block search engine and crawler bots from visiting your pages you can do so by uploading the following files to the / directory on your site. Double...
vibrating phone

Using javascript to make a mobile landing page vibrate the phone

The following javascript uses the Vibrate API to make a phone vibrate when a page is loaded. You can time it with setTimeouts or onclick/onscroll if required. <html> <script> navigator.vibrate = navigator.vibrate || navigator.webkitVibrate...
node moz api

Node.js client for Moz API (MozScape)

I was doing some work with SEO domains and realised there wasn't a node.js client for the MozScape API... so after Googling and not finding what I was looking for I...

Regex’s | Regular Expressions in Programming

Today I saw a nice script which redirects mobile traffic by searching the useragent string for a list of search terms related to mobile devices. This is PHP but I'll show...

A simple floating feedback/support button

It can be very useful for online businesses to collect feedback from their customers. This gives us priceless insight in to their wants, needs and problems. One quick way to start...

Alert box on click through to offer

The following example will allow you to create an alert box when the user clicks through from your landing page to the offer page. This can be useful to remind users...

A simple iOS / Android traffic splitter in PHP

The following basic PHP code will split traffic by device with iOS traffic going to the first out link, Android to the second and leftovers to the third. <?php     $ua = strtolower($_SERVER);   ...

Splitting traffic to different offers on mobile

If you are buying bulk traffic to a mobile offer the chances are that you can split some of your traffic off to different offers. For example if  you have a...

Resize youtube/vimeo iframe to maximum available height and width

Here is the code to make a flexible youtube.com or vimeo.com video fit both the height and width of the containing div. Like a flexible adsense unit it will take up...

Calculate distance between two geocooridnates

Here is a javascript function to calculate the distance between two latitude and longitude coordinates. function deg2rad(deg) { return deg * (Math.PI/180) } function calcDistance(lat1,lon1,lat2,lon2) {   var R = 6371; // Radius of...