## Easy Filter for Moodle

I've been playing around with Moodle plugins for the past few days and have kicked out a couple that are working, at least well enough for me to use.

One of them solved a pretty trivial task for me, but one that should save some time down the road. And that's formatting.

Teaching Computer Science I type a lot of code into question banks. Sure, the WYSIWYG editor in Moodle makes it pretty easy to change fonts. But I wanted something more like BBCode that's popular on web forums or shortcodes in WordPress. Something that lets me keep my hands on the keyboard and not having to mouse around to change fonts.

What I came up with is a filter plugin that I'm calling Easy Filter. From the admin settings pages you can define a tag to wrap around question text and then what the filter puts in place before and after that text as the page is displayed. For example, I have a 'java' tag setup that I'm using to wrap around any Java code in questions or pages. When I wrap Java code like this - [pre]System.out.println("Hello");[/pre] it  wraps it in a <pre> tag to format in a monospaced font.

### And, here's a screenshot...

The screenshot has 3 different tags defined, along with their before and after HTML. The bottom form is for adding more tags. To remove a tag you just blank it out on the list and hit the Update button.

### Download

The plugin is hosted at GitHub. Once you download the zip, you'll need to upload everything to the /filter/easyfilter/ folder under your Moodle root.

Tagged , , ,

## How to override quiz settings for a user in Moodle

Bob was absent yesterday and has to make up the test. Jane didn't do so well and you want to let her have a second attempt. You're only giving students 10 minutes for the quiz today, but Chris just needs a few extra minutes.

What you need is a user override. Not sure when this was added to Moodle, but I found it while setting up my Moodle 2.7 server for next year; and it looks like something that will get a lot of use.

The basics are that you can give a user, or a group, slightly different restrictions on a Moodle quiz. Continue reading

Tagged ,

## One line PHP regex search

Not sure this is the best way to do this, but it works.

Working on a project and I'm writing a lot of code to do RegEx searches. Each match is 3 or 4 lines to do the match, check if there was a match, and then do something with the match. Since I was tired of typing the same code over and over, kicked out a little function to do it for me.

It also was an excuse to try out Gists and embedding them back on my site instead of putting the code directly in a post.

Tagged ,

## Importing into Moodle from Examview - With Images

Edit on 8/7/2014

Well, this script is pretty much worthless now. Not sure when it happened, but Moodle now lets you upload the entire Blackboard zip file, images included, and everything gets imported. No more messing around with the res00000 files.

Going to leave the original post though. Might be handy for someone stuck using an older version of Moodle.

Original Post

I'm a big fan of Moodle, but really don't like the way you have to add questions to banks. There's just too much on that page.

So I normally build question banks in Examview and then import to Moodle. Only catch is that importing that way doesn't allow for images.

So what I've done is create a simple Python script that takes the exported file and replaces the image links with a data scheme URI. Wasn't expecting it to work, but it works without a hitch. Continue reading

Tagged , ,

## WordPress WYSIWYG editor not working

Moment of stupidity today...

For probably the past year or so the visual editor hasn't been working for me in WordPress. Just always plain text. No visual tab at all. And I checked. The disable WYSIWYG editor checkbox was clear for my account.

Today I tried checking the checkbox, saving settings, and then clearing the checkbox and saving again. Went back and the WYSIWYG editor is back.

Guess I should have tried turning it off and back on again a long time ago.

Tagged

## Contrasting color function for PHP

For another site of mine I needed a way to determine whether black or white was a better choice for text on a randomly colored background.

function contrast_color($col) {$d = 0;
$a = 1 - (0.299 *$col['r'] + 0.587 * $col['g'] + 0.114 *$col['b']) / 255;
if ($a < 0.5) {$d = 0;
}
else {
$d = 255; } return array('r' =>$d, 'g' => $d, 'b' =>$d);
}

The function takes a color as an array with elements r, g, and b and returns an array with the same 3 elements. Although in the returned array all 3 elements will either be 0 or 255 so you'll always get either white or black.

The original function came from a post on Stack Overflow. I just took it and ported from C# to PHP.

Tagged ,

## Watercolor book with paint built in

Minnie Mouse Coloring Book

Got to drop into dad mode for a bit...

I found the watercolor book on the right while Christmas shopping last month. Watercolors are one of those go-to activities for the kids, but it's always a bit of a process to get everything out and cleaned up afterwards. These books have the watercolor paint spread right onto each page so you don't need a separate set of paints. And it's perforated so you can pull the paint off afterwards to keep the masterpieces.

We didn't buy them online, but looks like Amazon has a bunch of different versions of watercolor books like this. Wish I had known a long time ago.

Tagged

## Moving Enemies with Waypoints

Getting enemies to move tends to be one of the more difficult things for me to get right. It just doesn't always seem natural. And I'm not talking about moving with any type of AI. Just moving around the screen in a pattern.

Sure, straight lines are pretty easy. But games get really boring if all the enemies just go from right to left or left to right.

For this post we're going to explore moving an enemy through a series of waypoints using ActionScript 3. I'm going to create a movie clip symbol in Flash named Enemy_mc.

## Let's see it

Doesn't do much good to explain with words. This is what we're going to create.

One minor difference. I set this demo up to loop so the enemy goes back to its starting position and sets its current waypoint back to 0 when it gets to the last one. The real deal will remove the enemy from the stage.
Continue reading

Tagged , , ,

## Distance Formulas

It's a pretty common task to get the distance between 2 points. Maybe you're wanting to see if two points are close enough to have collided. Maybe you're making a golf game and the closer the ball is to the hole the higher the score. Either way, you need to know the distance.

## The Math

The math for this is related to the Pythagorean Theorem. You know, or can find, the differences between two x values and two y values. What you're looking for is the hypotenuse of the right triangle formed by those legs.

Here's the formula. We'll talk in a bit.

This should look a lot like the formula Pythagorean Theorem, because it is. Distance is C, the difference between x1 and x2 is A, and the difference between y1 and y2 is B.

Everywhere I've seen this formula it's always listed as x2 - x1 and y2 - y1. It really doesn't matter though. Because you're squaring the difference, it will always be a positive number so you don't need to worry about which number is bigger.

## In Code

In the examples below we're going to use helper variables just to keep it a bit cleaner.

#### ActionScript

var dX:int = x2 - x1;
var dY:int = y2 - y1;
var distance:Number = Math.sqrt(dX * dX + dY * dY);

ActionScript also has a Point class that does the math for you.

import flash.geom.Point;
var p1:Point = new Point(0, 0);
var p2:Point = new Point(100, 100);
var dist:Number = Point.distance(p1, p2);

#### Java

int dX = x2 - x1;
int dY = y2 - y1;
double distance = Math.sqrt(dX * dX + dY * dY);

And like ActionScript, Java also has a Point class.

import java.awt.Point;
Point p1 = new Point(0, 0);
Point p2 = new Point(100, 100);
double distance = p1.distance(p2); 

The Java class also has a few more methods that will let you get the distance from a point to a specific X, Y value without creating a new Point reference and can get the distance squared as well if you need that.

#### Python

dX = x2 - x1
dY = y2 - y1
distance = math.sqrt(dX * dX + dY * dY)

## Other languages?

Pretty much any language that has a function to get the square root of a number will be able to get the distance between two points. Looking at the 3 languages listed above, the formula is the same for all 3. It's just the commands that differ a bit.

## Converting between degrees and radians

There are two ways to measure angles.

You probably learned to measure angles in degrees early in school. A circle has 360 degrees, a perfect corner is a 90 degree angle, and 180 degrees forms a straight line.

1 radian is when the radius is equal to the arc created

But then you took trigonometry or pre-calculus and were introduced to a radian. A radian does the same thing as a degree. It's a way to measure an angle. But instead of going 0 to 360 like degrees, radians go from 0 to .

The image to the right, sourced from Wikipedia, shows that 1 radian is the angle created when the ratio between the radius and arc along the circle is 1.

What happens with most people is that a degree makes more sense than a radian because degree was learned first. Similar idea to going between imperial and metric measurements. If you grew up in the US, measuring in inches probably makes more sense than centimeters. Can't speak for everybody, but I have the same vibe measuring in centimeters and radians compared to inches and degrees.

## Why?

The catch is that much of what we need to do with angles involves trigonometry, and trig uses radians. So we can work in radians, but there will also be times when we have to convert back and forth between radians and degrees.

## Formulas

The conversion formulas to go from radians to degrees or degrees to radians are inverses of each other.

## With Code

Since you can't type into your IDE, you'll need to use something else. For most cases, using an approximation of like 3.1415 is probably close enough.

Most languages do have a constant for . For Java and ActionScript it's Math.PI. Python uses math.pi.

So in ActionScript, we could use the following two conversions.

radians = degrees * Math.PI / 180;
degrees = radians * 180 / Math.PI;
Tagged , , , ,