Fixing Stepic unresponsiveness

Stepic is a great tool for learning, especially for Bioinformatics course, but one thing is really annoying – it forces you to resize your browser (you will see on the video below). It really annoys me so I decided to fix it and contact Stepic authors.

Lecture wrapper is not on center if the menu is opened.

After you open the menu, lesson is not on center anymore. If your browser is not very wide, this behaviour forces you to resize your browser and it annoys me.

This happens because they used webkit-transform: translateX for positioning. Better approach is to animate lesson wrapper just by changing it’s padding-left property. Also, menu’s position should be controlled by left property.

Lecture wrapper is not repositioned on resize event.

For some reason, Stepic developers applied position: fixed; on lesson wrapper. Just removing this fixes the thing.

Code that you can paste in inspector and temporary fix this bad behaviour can be found on my gist.

Extracting slice method

I was astonished today when I found following js snippet on MDN.
var slice = Function.prototype.call.bind(Array.prototype.slice);

After you have it initialised, you are free to use something like
var args = slice(arguments);

It has blown my mind when I realised how powerful bind and call functions are.

BTW if you fully understand it, I think you got how bind and call work.

Adding default custom fields on new posts in WordPress

Custom fields are essential part of every WordPress site. You know how to add it – Enter new – [type some name] – [type some content] – Add custom field. It’s not complicated process, but it is not as simple as it could be, especially if all of your posts need to have same custom fields, for example, price, size or some very general values. If it is your case, use this snippet and make your life easier.

[php]

add_action('wp_insert_post', 'mk_set_default_custom_fields');

function mk_set_default_custom_fields($post_id)
{
	if ( $_GET['post_type'] != 'page' ) {

		add_post_meta($post_id, 'price', '', true);
		add_post_meta($post_id, 'link', '', true);

	}

	return true;
}

[/php]

Simple, right?

You can put numerous custom fields or put just one. It’s up to you.
Oh, I forgot. This adds an empty custom field (with no value). For adding custom field with some value add  [php]

add_post_meta($post_id, 'custom field name', 'custom field value', true);

[/php]