Skip to content

Instantly share code, notes, and snippets.

View Lif3line's full-sized avatar

Adam Hartwell Lif3line

View GitHub Profile
@Lif3line
Lif3line / timer.js
Created May 26, 2014 16:25
A custom timer that can be paused and restarted
function timer(callback, timeOut) {
var store, timeStarted; // Use store for holding data to allow clearTimeout
var remaining = timeOut;
this.start = function() {
timeStarted = new Date();
store = setTimeout(callback, remaining);
}
this.pause = function() {
@Lif3line
Lif3line / connection.php
Last active August 29, 2015 14:01
Simple connection script to be included for dealing with MySQL databases
<?php
$db_host = '';
$db_username = '';
$db_pass = '';
$db_name = '';
@mysql_connect("$db_host","$db_username","$db_pass") or die ("Could not connect to mysql");
@mysql_select_db("$db_name") or die ("Database not found");
?>
@Lif3line
Lif3line / centeredImg.css
Created May 26, 2014 19:13
Center image in css (applies to anything though)
.centeredImg {
display: block;
position: relative;
padding: 0px;
margin: 0px auto auto auto;
}
@Lif3line
Lif3line / stickyFooter.css
Last active August 29, 2015 14:01
Sticky footer that sticks to the bottom of a webpage
#footerWrap {
width: 100%;
border-top: 1px solid #A1A1A1;
background-color: #333333;
position: absolute;
bottom:0;
left:0;
overflow-x: hidden;
}
@Lif3line
Lif3line / toggle.js
Created May 27, 2014 07:51
Generalised toggling of an element using jQuery; could be a button, a panel that opens/closes, pause button etc
function toggle(id, callbackOn, callbackOff) {
if($('#' + id).data("toggledOn")) { // Turn off
$('#' + id).data("toggledOn",false);
callbackOff();
} else { // Turn on
$('#' + id).data("toggledOn",true);
callbackOn();
}
}
@Lif3line
Lif3line / toggle.js
Created May 27, 2014 07:58
Static toggling function for a single element - could be a button, sliding panel etc
function toggle() {
if($('#toggleElement').data("toggledOn")) { // Turn off
$('#toggleElement').data("toggledOn",false);
/* Do something */
} else { // Turn on
$('#toggleElement').data("toggledOn",true);
/* Do something */
}
}
@Lif3line
Lif3line / popUp.php
Last active August 29, 2015 14:01
Pop up box for displaying messages over a page
<div id="overlay">
<div id="messageBox"></div>
</div>
<script type="text/javascript">
function popUp(message) {
document.getElementById("overlay").style.visibility = "visible";
}
function closePopUp() {
@Lif3line
Lif3line / mailer.php
Created May 28, 2014 11:00
Send an email from a server
<?php
$headers = 'From: ' . "\r\n";
$to = "";
$subject = "";
$body = "";
mail($to, $subject, $body, $headers);
?>
@Lif3line
Lif3line / greed_human.js
Created June 15, 2014 00:14 — forked from schmatz/greed_human.js
Winning Greed tournament entry
// constants -------------------------------------------------------------------
var alliedTypes = {
peasant: 'peasant',
soldier: 'soldier',
knight: 'knight',
librarian: 'librarian',
griffinRider: 'griffin-rider',
captain: 'captain'
};
@Lif3line
Lif3line / gridmancer.js
Last active August 29, 2015 14:02
My solution to CodeCombat's Gridmancer Challenge. Attempts to draw the minimum number of rectangles onto the level (used for path finding and what not), manages to find the optimum number too <3
// Calculate positioning of rectangles by using a 2D array with a one-one mapping to the environmenet where a 1 indicates a
// potential mappable square and a 0 represents an unmappable square. Squares are 4mx4m
// Find rectangles by sweeping up then right to find the max possible rectangle for each section
// Adam Hartwell 2014, Idea shamelessly taken from post of the best algorithms for this challenge
var tileSize = 4;
var grid = this.getNavGrid().grid;
var gridArr = [];
var row, counter, x, y;
// Create an array with grid size 4m and each square being 1 to indicate free and 0 otherwise