Skip to content

Instantly share code, notes, and snippets.

View houdmont's full-sized avatar

Tom Houdmont houdmont

View GitHub Profile
@houdmont
houdmont / levelling-up.js
Last active October 9, 2017 16:20
Levelling up a user.
function attemptLevelUp(addedXp, currentXp, currentLevel) {
var baseAmountForNextLevel = 0;
for (i = 1; i <= currentLevel; i++) {
baseAmountForNextLevel += xpNeededForNextLevel(i);
}
if ((currentXp + addedXp) >= baseAmountForNextLevel) {
// I am levelling up.
<?php
use Zend\Db\Sql\Select;
// basic table
$select0 = new Select;
$select0->from('foo');
// 'SELECT "foo".* FROM "foo"';
@houdmont
houdmont / gist:2922921
Created June 13, 2012 08:58
Use a mixture of php and javascript to create a fast and conditionally executing autocomplete for a large list of items.
// Pass through a couple of dom elements for minor speed improvement,
// Pass through jQuery to avoid conflicts,
// Define undefined.
(function(window, document, $, undefined){
// Define the station list.
var stations = [<?php
$count = count($stations);
$i = 0;
foreach($stations as $station) {
echo '"'.trim($station->stationName).'"';