Makeout Point

Makeout Point, menu closed

Thank my housemate Alanna for this theme. Alanna has wanted to blog for a while, but Alanna has also wanted to procrastinate and play video games in her free time. :) She hopes that because she asked for a unique theme for her site, and drove me to build it, she might be more likely to blog out of a sense of responsibility to the work undertaken.

And here I am two weeks later, just about finished with Makeout Point. The theme is clean, minimal, responsive, and not half-bad compared to my earlier efforts. The theme is built for Anchor, a PHP Facebook-lite. The available functions are bare bones compared to WordPress, the upshot is that you don’t have WordPress’ cruft. Want to loop comments? Loop comments. Want to get a count of comments? Get a count of comments. There’s a really nice straightforwardness to Anchor that I’ve enjoyed working with.

The design is clean, responsive (smartphone through to desktop), fast, has a strong focus on code snippets, and makes use of burger menus for both site navigation and article comments.

Makeout Point, menu open

Anchor isn’t perfect-you can freely use a mix of both HTML and Markdown, and this leads to occasions where previously-escaped HTML and XML code snippets in <pre> tags are parsed. Whoops. It’s nice though, don’t mistake me! I’d love to work with Anchor more in future.

You can fork or pull Makeout Point from it’s GitHub repo.


Merde

Boilerplate can be bad, and I was an idiot for using it. I used the same @font-face boilerplate code across three sites: Here, 091 Labs, and Alanna’s new Anchor site. The boilerplate is:

@font-face {
    font-family: 'Source Code Pro Regular';
    src: 
        url('fonts/source_code_pro/scp-r.eot?') format('embedded-opentype'),
        url('fonts/source_code_pro/scp-r.woff') format('woff'),
        url('fonts/source_code_pro/scp-r.otf')  format('opentype'),
        url('fonts/source_code_pro/scp-r.ttf')  format('truetype'),
        url('fonts/source_code_pro/scp-r.svg')  format('svg');
}

Here is a typical piece of the font-family selection code I recycled:

h1, h2, h3, h4, h5, h6 {
    color: #343537;
    font: bold 2.75em 'Source Code Pro', impact;
    letter-spacing: 0;
    text-align: left;
}

I declare the @font-face, but never actually use it. And even if the font-face would happen to load, it is also the incorrect file: The typeface file in question is actually the bold version. It was pointed out to me in a Reddit thread last night when a user complained about ugly typefaces on a site I submitted for critique.

So, fuck. Lesson learned. The solution was to move from self-hosted @font-face’s to Google Fonts, for at least common typefaces, and then triple-check @font-face boilerplate in future.


I feel strangely proud about my first recursive function

I need to move the bottom-most of a given set of divs as part of a parallax effect, so I progress down through them until I hit bottom.

function left(amount, obj) {
    $(obj).children().each(function() {
        if ($(this).children().length > 0) {
            left(amount, this);
        } else {
            $(this).css('left', parseInt($(this).css('left')) - amount + 'px');
            wrap(this);
        }
    });
}

function wrap(obj) {
    var x = $(obj).offset().left;
    var y = $(obj).offset().top;
    var w = $(obj).width();
    var h = $(obj).height();

    if (y + h < 0) {
        $(obj).css('top', $(window).height() + 'px');
    } else if (x + w < 0) {
        $(obj).css('left', $(window).width() + 'px'); 
    } else if (x > $(window).width()) {
        $(obj).css('left', 0 - w + 'px');
    } else if (y > $(window).height()) {
        $(obj).css('top', 0 - h + 'px');
    }
}

/toot


Project Euler Problem #18

I am beginning to feel as if my head is full of mush every time I have to deal with a jagged array in a loop. I stole the solution from here, but the code is entirely my own.

In short, you begin at the bottom-left corner of the jagged array. You move to the right and evaluate each pair of numbers. You add the higher of the two to the number above. Take the first three numbers:

63
04 62

Weigh 04 and 62. Add the higher of the two – 62 – to 63:

125
04 62

Repeat this cascade. Ultimately everything will be added to a[0][0]. Output this. Problem #67 repeats this problem exactly, and except for some additional file handling the solution below can be used.

using System;

public class Eighteen
{
	static void Main()
	{
		int[][] a = new int[15][];

		a[0]  = new int[1]  {75};
		a[1]  = new int[2]  {95,64};
		a[2]  = new int[3]  {17,47,82};
		a[3]  = new int[4]  {18,35,87,10};
		a[4]  = new int[5]  {20,04,82,47,65};
		a[5]  = new int[6]  {19,01,23,75,03,34};
		a[6]  = new int[7]  {88,02,77,73,07,63,67};
		a[7]  = new int[8]  {99,65,04,28,06,16,70,92};
		a[8]  = new int[9]  {41,41,26,56,83,40,80,70,33};
		a[9]  = new int[10] {41,48,72,33,47,32,37,16,94,29};
		a[10] = new int[11] {53,71,44,65,25,43,91,52,97,51,14};
		a[11] = new int[12] {70,11,33,28,77,73,17,78,39,68,17,57};
		a[12] = new int[13] {91,71,52,38,17,14,91,43,58,50,27,29,48};
		a[13] = new int[14] {63,66,04,68,89,53,67,30,73,16,69,87,40,31};
		a[14] = new int[15] {04,62,98,27,23,09,70,98,73,93,38,53,60,04,23};

		for (int i = 14; i > 0; i--)
			for (int j = 0; j < a[i].Length-1; j++)
				if (a[i][j] > a[i][j+1])
					a[i-1][j] += a[i][j];
				else if (a[i][j+1] > a[i][j])
					a[i-1][j] += a[i][j+1];

		Console.WriteLine("\n{0}\n", a[0][0]);
	}
}

Project Euler Problem #12

This was a question of two parts:

  1. Calculate the next triangle number in sequence.
  2. Take said triangle number and calculate how many divisors it has. Loop until you find one with 500, and break.

The first part was simple:

Start with n = 1. For every iteration of the loop, add n to n, and add 1:

n = 1
n = n + n + 1

The second part…not so simple. I’ll honestly say I am struggling with understanding the correct way to test for divisors; this works, however:

Take a number, i. Find the square root of i. Loop. Check every integer up to n to see if it divides evenly. Increment the count. Double the answer and return it.

using System;

public class Twelve
{
	static void Main()
	{
		long a = 1;
		long b = 1;
		long c = 0;

		while (c < = 500)
		{
			c = factors(a);

			if (c > 500)
			{
				Console.Write("\n{0}\n", b);
				break;
			}
			else
			{
				a += b + 1;
				b++;
			}
		}
	}

	static long factors(long a)
	{
		long b = 1;

		for (int i = 1; i < = Math.Sqrt(a); i++)
			if (a % i == 0)
				b++;

		return 2 * b;
	}
}

Project Euler Problem #6

using System;

public class Six
{
	static void Main()
	{
		double a = 100;
		double b = 0;
		double c = 0;
		
		for (int i = 1; i < = a; i++)
		{
			b += (i * i);
			c += i;
		}

		c = c * c;

		if (b > c)
			Console.WriteLine("n{0}n", b - c);
		else if (c > b)
			Console.WriteLine("n{0}n", c - b);
	}
}