Skip to content

Instantly share code, notes, and snippets.

View LiamKarlMitchell's full-sized avatar

Liam Mitchell LiamKarlMitchell

View GitHub Profile
@LiamKarlMitchell
LiamKarlMitchell / Clone keys of an object
Created December 11, 2014 22:13
Copies the keys from passed in object and returns a new object that references all the same kerys.
function Clone(o) {
var n = {};
for (var a in o) {
if (o.hasOwnProperty(a)) {
n[a] = o[a];
}
}
return n;
}
@LiamKarlMitchell
LiamKarlMitchell / Quad-Tree-Implementation---Including-AI.markdown
Created February 27, 2015 23:05
Quad Tree Implementation - Including AI

Quad Tree Implementation - Including AI

We needed a Quad Tree to handle spartial positioning in our MMORPG server over at github.com/LiamKarlMitchell/InfiniteSky

So this was born. I have been wanting to implement it for a while anyway.

Using Pixi.js for rendering it so I can see what is going on.

Add a few moving objects by using the button or click in the quad area to add static ones.

// Dump a bunch of things into it, it will queue them up and either send them when the queue is full or add more.
// Using some to call the callback function for the queued things.
// If you want you could view the array, process just the first or last thing and return true to break
// then no further execution would be done.
// Callback should expect value, index, array as arguments
function GroupOverTimeThenCall(callback, options) {
if (!(callback instanceof Function)) {
throw new Error('GroupOverTimeThenCall expects callback to be a function.');
}
// Sometimes when using Send and Recv API it will not send or recv all the data. You will notice your socket might have an error and gets disconnected.
// Such as the other end wont be able to recv the entire packet correctly or something. The bytes that were not sent are never sent.
// This is horrible of course, I did not read the fine print and just expected it to work -_- (okay I guess an error could happen half way through sending or receiving some data and thats why it works this way.
// Email: liamkarlmitchell@gmail.com
// License: MIT - do whatever you want with this code.
// Borrowed from UNIX Network Programming: Sockets Introduction
// By Andrew M. Rudoff, Bill Fenner, W. Richard Stevens Feb 27, 2004
// http://www.informit.com/articles/article.aspx?p=169505&seqNum=9
// I license this as MIT do whatever you want with it basically.
// I can't be assed including the header you know what it is.
// If you don't want Mutex.h comment it out, check out my other gists for it if you need it.
#ifndef __CLOG_H
#define __CLOG_H
#include "Mutex.h"
#include <fstream>
// Another thing I made ages ago feel free to use :)
// licensed under MIT / Public / do whatever.
#ifndef __MUTEX_H
#define __MUTEX_H
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <windows.h>
// A way to compare two floating point numbers for "equality".
const EPSILON = 0.00000001;
function fEqual(a, b) {
return ((a - b) < EPSILON && (b - a) < EPSILON);
}
// An infamous mistake by rookies is to notice the following.
// 0.1 + 0.2 == 0.3
// And think it is a mistake when the language says false. Us humans would just say 0.3.
// But because of how float points work in computer you end up with something like 0.30000000000000004.
@LiamKarlMitchell
LiamKarlMitchell / unicode_card.js
Last active February 18, 2016 03:14
A way to output unicode information for a card number.
// https://en.wikipedia.org/wiki/Standard_52-card_deck
function unicodeCard(cardNumber) {
// As of Unicode 7.0 playing cards are now represented. Note that the following chart ("Playing Cards", Range: 1F0A0–1F0FF) includes cards from the Tarot Nouveau deck as well as the standard 52-card deck.
if (cardNumber < 0 || cardNumber > 56) { throw 'Invalid cardNumber '+cardNumber }
cardNumber += 2*Math.max(Math.ceil(cardNumber/14),1);
return String.fromCodePoint(127136-2+cardNumber);
}
function unicodeCardHTMLEncoded(cardNumber) {
// As of Unicode 7.0 playing cards are now represented. Note that the following chart ("Playing Cards", Range: 1F0A0–1F0FF) includes cards from the Tarot Nouveau deck as well as the standard 52-card deck.
@LiamKarlMitchell
LiamKarlMitchell / circledNumberHTMLCode.js
Created September 8, 2016 01:51
Circled Number 0 to 20 & html escape unicode code.
// ⓪ &#9450; Circled Digit Zero
// ① &#9312; Circled Digit One
// ② &#9313; Circled Digit Two
// ③ &#9314; Circled Digit Three
// ④ &#9315; Circled Digit Four
// ⑤ &#9316; Circled Digit Five
// ⑥ &#9317; Circled Digit Six
// ⑦ &#9318; Circled Digit Seven
// ⑧ &#9319; Circled Digit Eight
// ⑨ &#9320; Circled Digit Nine
@LiamKarlMitchell
LiamKarlMitchell / mysql helper.js
Last active January 25, 2017 03:42
A node.js script to help find missing indexes, FK, PK and mismatched ENGINE types (prefers INNODB).
// This script will connect to the DB and look for potential missing indexes.
// Author: Liam Mitchell
var db = 'database here';
var async = require('async');
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'host here',
user : 'username here',