Skip to content

Instantly share code, notes, and snippets.

@tiltedlistener
tiltedlistener / gist:dbb267f88dacc247e5df5d0718de345e
Last active May 14, 2017 03:58
JavaScript A* with Manhattan Distance
// A*
// Much thanks to http://www.geeksforgeeks.org/a-search-algorithm/
// Extending array
Array.prototype.empty = function() {
return this.length == 0;
};
// Constants
var SQUARE_SIZE = 100;
@tiltedlistener
tiltedlistener / equation.js
Created December 7, 2016 07:48
Parse math strings and solve
var equation = "1+(3+(3-2))*5/2";
var process = function(arr) {
if (arr.length == 1) {
return parseFloat(arr[0]);
}
var number = arr[0];
var operator = arr[1];
@tiltedlistener
tiltedlistener / .java
Created October 7, 2015 23:31
NU: Hangman Partway Wrong
public class Hangman {
private String wordToGuess = "t";
private boolean gameRunning = true;
private int guessCount = 4;
public void playGame() {
while (gameRunning) {
@tiltedlistener
tiltedlistener / .java
Last active October 7, 2015 23:30
NU: Hangman Partway
public class Hangman {
private String wordToGuess = "t";
private boolean gameRunning = true;
private int guessCount = 4;
public void playGame() {
while (gameRunning) {
@tiltedlistener
tiltedlistener / gist:f272434825c0cc8ab5a4
Created October 7, 2015 23:06
Prep code for Hangman
/**
* Prep Code
*/
// PICK A WORD
// LOOP
// LET THE PLAYER GUESS
// IF GUESS == TRUE
// CHECK IF WORD IS COMPLETE
// YOU WIN
@tiltedlistener
tiltedlistener / gist:8dc4258a1360d3002b12
Created April 2, 2015 05:43
Scrolling Background in Java
public void drawBackground() {
// CIRCLE is a static var defined as MATH.PI * 2
// graphics() returns a Graphics2D context in this case from a BufferedImage createGraphics() method
rotationOfBackground += 0.05;
if(rotationOfBackground >= CIRCLE) {
rotationOfBackground -= CIRCLE;
}
// In this case we're assuming that 300 is the height that we need
int width = (int)(background.getWidth(this));
@tiltedlistener
tiltedlistener / gist:795ea00e24210177f443
Created February 8, 2015 04:08
where() function for jQuery
(function ( $ ) {
$.fn.where = function(status) {
var len = this.size();
for(var i=0; i < len; i++) {
if ($(this[i]).is(status)) {
return $(this[i]);
}
}
return [];
@tiltedlistener
tiltedlistener / gist:5a0ba5a285f5719f339e
Last active August 29, 2015 14:10
Possible Drupal index.php that clears caches on each request
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
menu_execute_active_handler();
drupal_flush_all_caches();
/**
* The intent is to clear the caches so that when multiple people are sharing the same db in dev,
* CSS / Template caching collisions don't occur.
@tiltedlistener
tiltedlistener / gist:4a6df7c96ca65677159b
Created November 18, 2014 20:44
Sample MySQL dump on command line
mysqldump -h localhost -p -u root cookbook > cookbook.sql
@tiltedlistener
tiltedlistener / gist:d7b6f4b442aa3bb71a6f
Last active August 29, 2015 14:08
Remove all docker containers
docker rm $(docker ps -a -q)
# From https://coderwall.com/p/ewk0mq