Skip to content

coding

Google Spreadsheet: The Gateway Drug of Programming

You might not know it, but if you have used Google Spreadsheet (or its much more powerful equivalent, Microsoft Office Excel), you have already programmed. And if you like using these products a lot, then you know you are hooked! It’s a sure way to find out if you are a nerd in hiding – if a pivot table makes you excited, you know you will come jonesing back for more.

Read More →

Javscript Regex Cheatsheet

I always forget how to do this:

r = /^[^0-9]+/;
regex = new RegExp('^[^0-9]+');
string = '1a';

me = 'b2';

/* these return false and null, respectively */

string.match(r);
regex.exec(string);

/* this returns true and an Array of matches respectively */

me.match(r);
regex.exec(me);

then how about capture groups – you can’t iterate over them in one go, that’s the problem, you have to do it via exec() which you run multiple times on the same str variable, weirdly enough. The return value is an array with always just two elements: the entire match and the capture group match.

let str = '<h1>Hello, world!</h1> <h1>Hello1, world!</h1> <h1>Hello3, world!</h1>';
 
 let reg = /<h1>(.*?)<\/h1>/g;
 
 let match;
 
 while (match = reg.exec(str)) {
 console.log(match);
 }

voila – you get first the 2 elements, “<h1>Hello, world!</h1>” and “Hello, world!” and then the two elements, “<h1>Hello1, world!</h1>” and “Hello1, world!” and so on

How Complex Is It To ‘Re-skin’ WordPress Pages

Someone asked me this recently, and further explained themselves:

I have a WordPress template that I’m using and I want to completely re-design a couple of pages (visual changes only). I can create the front-end layouts, but I’m interested in learning about how complex/lengthy the process can be to implement said front-end layout, or if it’s a fairly minimal task.

Here’s what I said back: It depends on how familiar with frameworks where the front-end is generated on the server-side (HAML with Ruby, say, as another example.) WordPress uses PHP based server-side rendering –

Read More →