Counting the number of letters in a number in binary using PHP

This code is inspired by Matt’s recommendation to “double check” in this video: https://youtu.be/LYKn0yUTIU4?t=4m43s <?php $limit = 1000000; // this is the only thing you’ll want to change, this is the highest number we’ll check against $eighteen = 0; $thirteen = 0; $i = 0; while ($i < $limit){ $i++; $currentStop = countLetters($i); if ($currentStop […]

Expand

Random Color Generator in Javascript

Below is a script for a random color generator using Javascript. An explanation of how it works is in the code comments: <script> function randomColor(){ return “#” + // start with a leading hash Math.random() // generates random number .toString(16) // changes that number to base 16 as a string .substr(2,6); // gets 6 characters […]

Expand

Check if a number is prime using PHP

The below function named checkPrime() uses a modulus (remainder) to check if a provided number is prime. You can update the “return” lines to provide a more pragmatic response (like TRUE or FALSE), or just echo it out as shown. In the specific example, we’re checking if the number 989 is prime, but you can […]

Expand
class="post-296 post type-post status-publish format-standard has-post-thumbnail hentry category-uncategorized"

* i hate spam and will never share your email address *

class="post-296 post type-post status-publish format-standard has-post-thumbnail hentry category-uncategorized"
nilakantha-series

Calculating Pi with PHP using the Nilakantha Series

The below code calculates pi to 13 decimals using PHP and the Nilakantha Series. We loop through the series 15468 times to get an accurate result. <?php $pi = 3; $counter = 2; $direction = 1; for ($x = 0; $x

Expand

Collatz Conjecture with PHP

First, do a search for “Collatz Conjecture” to find out what it is (no need for me to explain it here…) Although PHP isn’t the fastest language around, it’s extremely popular, and its my language of choice, so I wanted to make a basic program to try and solve this problem in PHP. So far, […]

Expand
Fast Performance - Cheetah Running

Performance Testing With Different Data Types

Have you ever been about to write an IF statement, and stopped to think about the performance implications of using various data types, or the difference between using the double equals == vs triple equals ===. I have, and I decided to test this using the following basic code: <?php $start = microtime(true); $data = […]

Expand
Same folder

Absolute File Paths VS. Relative File Paths VS. Root Relative Paths

When you’re creating any type of link to another file on your website, there are basically three ways to write the file path. They are (as the post tile implies) Absolute, Relative, or Root Relative. Each one has its own advantages. This can relate to linking to an external stylesheet, javascript file, images, or even […]

Expand

A Simple Solution To Add rel=”canonical” Sitewide

Adding a rel=”canonical” link to the head of a webpage is extremely important for SEO. Very simply, a rel=”canonical” link tells Google that multiple pages on your website are actually the exact same page. Why do I need a rel=”canonical” ? Lets take my home page for example, there might be four incoming links from […]

Expand

How To Track External Links As Events In Google Analytics

Event tracking in Google Analytics is extremely useful for tracking pretty much anything on your website. Use this code snippet to track all links to external websites. Note that this script does use jQuery, so you’ll need to include that as well as your regular Google Analytics tracking code. This script works best if you […]

Expand

How To Bypass Access-Control-Allow-Origin Using PHP

If you’ve ever gotten this message in the developer console: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Then here’s how to fix it, you essentially have two options. The less secure way is to just allow access from any origin, you can do that by adding this as the first line in the […]

Expand

Enable gzip Compression On NGINX Servers

Delivering your files using gzip on an NGINX server is simple, and will substantially improve your page load time. Just add the following code to your config file gzip on; gzip_comp_level 2; gzip_http_version 1.0; gzip_proxied any; gzip_min_length 1100; gzip_buffers 16 8k; gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; # Disable for IE < […]

Expand
Bad Website

Never Do This On Your Website!

Adding a small “loader gif” is a nice feature to add to your site if you know that the page takes a second or two to load additional content, especially if its via ajax. But the key to that last sentence is “a second or two”… If your site takes longer than that to load […]

Expand

How To Set Expires / Cache-Control Headers For All Files On Your Website

Setting up caching for your static files is a quick and easy way to greatly reduce your page load time. It’s great for user experience, and will also get you a small SEO boost. Its as easy as putting one line of code in your .htaccess file. Google likes to see the expires headers to […]

Expand
gzip icon

How To Deliver Files With gzip On Apache Servers

If you’ve gotten to this page, you probably already know a little bit about gzip. If not, its basically just a way to compress your files for delivery to your user’s browsers. Although gzip can work with any file type, its only recommended on text based files, meaning HTML, CSS, and JavaScript. There are a […]

Expand
Google Plus

Why You Should Be Using Google +

I bet you’re like the vast majority of people, you pretty much never use your Google + account. With more popular social networks like Facebook, Linkedin and Twitter, why would you? The original concept of a SOCIAL NETWORK was to be social. If your friends are on Facebook, your colleagues are on Linkedin, and your […]

Expand
Fade In And Out

Make your web pages fade in and fade out

Before you go ahead and implement this, I recommend a few things.

Expand
Relative Positioning Example CSS

What’s the difference between Static, Relative, Absolute and Fixed Positioning?

There are 4 different types of CSS positioning, which are as the title of this post states: Static, Relative, Absolute, and Fixed. Each one has its uses and special circumstances for when to use them. Static Position Static is the default type of positioning. When elements don’t have a position specifically set, they default to […]

Expand

How to Add Elements onScroll using CSS Transitions

Have you ever seen a website that seems to add elements to the page as you continue to scroll down? Check out this demo (which uses only Javascript and CSS, no jQuery) Scroll down in the demo to see the added elements If you read my last post on using onscroll in javascript, then you […]

Expand

How to make a sticky header or nav

Instead of describing exactly what a sticky header / nav is, check out the demo and scroll down to see some MAGIC See a Magic Sticky Div! I’m sure you’ve seen websites with a top header / navigation which at first has a static position, but then when you start to scroll down the page […]

Expand
Fade Text Out At The Bottom

How to make text fade out at the bottom or top

This is another easy, but very cool CSS effect. Check out the demo. The CSS is simple: <style> div#fadeout { height:200px; width:100%; position:fixed; bottom:0; background: -moz-linear-gradient(top, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 90%); background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,0)), color-stop(95%,rgba(255,255,255,1))); background: -webkit-linear-gradient(top, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 90%); background: -o-linear-gradient(top, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 90%); background: -ms-linear-gradient(top, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 90%); background: linear-gradient(to […]

Expand
Swap CSS Stylesheets

Swap Style Sheets Instantly On The Fly

Being able to swap out stylesheets on the fly with javascript is both simple and useful. Practical applications would be Changing the font size if the person clicks on a button because they’re visually impaired If you have a theme for sale, on the preview screen you could display multiple color variations. Check out a […]

Expand

How to autofill an Email with a subject and body text

Using the mailto: on an anchor tag is a great way to help visitors email you more easily, but did you know that you can actually pre-populate their message with a subject, and even the message itself? Its actually really simple. <a href=”mailto:webdevbydoing@gmail.com?subject=I Love your site&body=Tell me more about web development!”>Email Me</a> Email Me As […]

Expand

Making Better Forms with only CSS using :focus and :checked pseudo classes

A lot of people like to style their forms with javascript, and why not, its the most common way to handle user interaction on any website. But there’s another way too. Using the :focus and :checked pseudo classes, along with some other less common CSS syntax, you can make really interesting forms with all the […]

Expand
Responsive Borders

How to make Responsive Borders

I’m sure a lot of you have had a similar problem to me.  You’re trying to make a responsive website, and you try to put a border around one of the boxes, but find that borders can’t be put in a percentage.  As an example, lets say you have three divs each with a margin […]

Expand