Skip to content

Instantly share code, notes, and snippets.

<?php
class Database {
private $dbHandle;
private $preparedStatements = array();
public $rowCount;
public $lastInsertId;
public function __construct($host, $database, $username, $password, $errorMode='silent') {
try {
@Palmr
Palmr / trello-solve.js
Created September 26, 2014 15:34
JS solution for the challenege on https://trello.com/jobs/developer
// for some reason the challenege only let you use these letters, not full A-Z
var letters = "acdegilmnoprstuw";
// Implementation of their hash function to test against
function doHash(string) {
var hash = 7;
for(var i = 0; i < string.length; i++) {
hash = (hash * 37 + letters.indexOf(string[i]));
}
return hash;
@Palmr
Palmr / tag-sorter.js
Created October 10, 2014 11:10
Sort tags by suggestion text value
// This is whatever has your JSON before you call the tagger
var tagItemsJSON = ...
// This takes the JSON and splits it into an array of the items in it
// It then sorts that array by the suggestion field on each item
var sortedBySuggestion = $.map(tagItemsJSON, function(p){return p;}).sort(function(a, b){
if(a.suggestion < b.suggestion ) return -1;
if(a.suggestion > b.suggestion ) return 1;
return 0;
});
@Palmr
Palmr / ImageUtil.java
Created May 28, 2015 15:55
Massive text draw function
//Draw a wrapped sting
private static boolean isBreakable(char c) {
return (c == ' ' || c == '\t' || c == '-' || c == '\\' || c == '/' || c == '_');
}
private static boolean isNewLine(char c) {
return (c == '\n' || c == '\r');
}
/**
* Draw a string onto a graphics2d object, wrapping words at pWidth pixels wide.
@Palmr
Palmr / XFUtil.java
Created August 12, 2011 16:43
Inelegant Coding
//Because the normal initcap function lowercases the string first
private static String upperFirstchar( String pString) {
return pString.substring(0,1).toUpperCase() + pString.substring(1);
}
//Use java reflection to try and get private member values from an object
// MemberPath is of format "Object.Object.lPrivateVariable", the first object being a member of pStartingObject
//This function is quite possibly the inelegant thing I've coded for a while
public static Object getPrivateMembers (String pMemberPath, Object pStartingObject)
throws ExInternal {
if (pStartingObject == null) {
@Palmr
Palmr / gist:1339675
Created November 4, 2011 15:54
PL/SQL Reddit Browsing (Crude, but effective at making me look like I'm doing work in the office)
CREATE OR REPLACE PACKAGE SCOTT.np_reddit IS
g_xmldata XMLTYPE;
PROCEDURE get_top_25 (p_subreddit VARCHAR2 default null);
PROCEDURE get_comments (p_item NUMBER);
PROCEDURE get_image (p_item NUMBER, p_scale NUMBER default 10, p_end VARCHAR2 default null);
END;
/
@Palmr
Palmr / gist:4520944
Last active December 11, 2015 01:08
Return instruction for the gameboy cpu emulator I'm writing
void Instructions::doReturn(CPU* cpu, BYTE pOpcode) {
if (pOpcode == 0xc9
|| (pOpcode == 0xc0 && cpu->reg->getFlagZ() == 0)
|| (pOpcode == 0xc8 && cpu->reg->getFlagZ() == 1)
|| (pOpcode == 0xd0 && cpu->reg->getFlagC() == 0)
|| (pOpcode == 0xd8 && cpu->reg->getFlagC() == 1)) {
cpu->reg->setPC((WORD)((cpu->mem.readByte(cpu->reg->getSP() + 1) << 8) | cpu->mem.readByte(cpu->reg->getSP())));
cpu->reg->incSP(2);
cpu->clock.m += 5;
cpu->clock.t += 20;
@Palmr
Palmr / gist:7643101
Created November 25, 2013 15:32
VBA to deal with some stock control stuff
Attribute VB_Name = "Module1"
Sub Stockreport1()
Attribute Stockreport1.VB_ProcData.VB_Invoke_Func = " \n14"
' Comments start with apostrophes :)
' Select a bunch of columns, then remove them
Range("F:F,I:I,X:X,AD:AD,AE:AE,AA:AC,AH:AP").Select
Selection.Delete Shift:=xlToLeft
' Insert a new column and put "Stores OOS" in the first item to be the title
@Palmr
Palmr / ascii.php
Created November 4, 2011 15:57
Image to ascii art converter (not great)
<?php
if(!isset($_GET['pure'])){
?>
<style>
pre {
line-height: 11px;
font-family:"Courier New", Courier, monospace;
}
#error {
font-family: Arial, Helvetica, sans-serif;