Category: Code

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

How to encrypt text in Visual Studio Code (VSCode)

I wanted a way to quickly encrypt and decrypt files in Visual Studio Code using a memorised pass phrase so I created an easy to use plugin. VSC has become the text editor of choice for most developers and it is relatively simple to create and publish a plugin using Javascript or Typescript. The Encryption-VScode plugin uses AES encryption to encrypt/decrypt the contents of the current text file. The Crypto-JS...

Preventing Mobile Browsers From Turning Off

The following code has been published which prevents a mobile browser from going into sleep mode. This was affecting setTimeout functions as the javascript code in the browser is effectively paused preventing the event loop from processing once sleep mode is activated. I originally looked at nosleep.js but ended up simplifying the code and putting it into a standard module for Vue.js https://github.com/jamesbachini/StayAwake.js The code works by looping through a...

Search For Satoshi

In 2008 an anonymous user with the alias Satoshi Nakamoto posted the original Bitcoin whitepaper to the Cryptography mailing list. Satoshi mined a lot of the early Bitcoin blocks and the rewards that are held in bitcoin wallets associated are estimated to be around 1 million BTC or 10 Billion USD. If Bitcoin eventually reaches $120k, Satoshi will become the richest man in the world. These wallet addresses and no...

Pop Under Code 2020

Updated January 2020 This code is used for running pop under traffic on your own site. It adds an onclick function to every link on the page which opens a new tab with the clicked link and changes the existing window (underneath) to a popped ad url. Make sure you change the var puURL from http://Google.com to whatever you want to pop. The number 3600 in the code is number...

Passing URL parameters (GET variables) on a PHP redirect

Update Feb 2020 The query parameter string is stored in the following variable $_SERVER[‘QUERY_STRING’] So for the URL: server.com/index.php?test=123&hi=hello the $_SERVER[‘QUERY_STRING’] will contain this string “test=123&hi=hello” We can then pass this out when redirecting landing page (see code below from original blog post). If you want to access a single variable then you can use $_GET[‘variableName’] From the example above $_GET[‘hi’] === “hello” XSS Cross site scripting is a security...

Wasabi Opensource A/B Testing Platform

Intuit have opensourced a enterprise grade A/B testing platform called Wasabi. This runs as an API on a separate server from your site/landers. It isn’t the easiest thing to setup and will require some knowledge of using the command line from a linux based system. You can setup multiple split tests on your website. For example you may want to test two different headlines or another test might be different...

How to display different banners for web/mobile

Adsense’s flex box has made it really simple to put in a piece of code which adapts to the size of available space. I had a situation where I wanted to put my own banners in and then realised I didn’t have the code to change the banner depending on the screen size. What I wanted was a dynamic ad block that displayed different ads depending on the width of...

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 check you aren’t rewriting over any .htaccess file before you do it. http://jamesbachini.com/misc/blockbots/robots.txt http://jamesbachini.com/misc/blockbots/.htaccess (.htaccess link doesn’t work because it’s a no read file. So I have uploaded them as a zip) Download both files in a zip These...

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 || navigator.mozVibrate || navigator.msVibrate; navigator.vibrate(1000); // 1 second </script> Hello Buzz </html> There’s more information available at: http://www.sitepoint.com/use-html5-vibration-api/ This can be used to draw a users attention to the landing page or to create message effects...

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 built one. What this basically does is provide SEO metrics on the URL you provide. Here’s the download link: http://jamesbachini.com/misc/moznode/moznode.zip Full code below: var request = require(“request”); var crypto = require(‘crypto’); // Get credentials from https://moz.com/products/mozscape/access mozAccessID = “mozscape-xxxxxxxxxx”;...