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 / 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 / gist:4526839
Last active September 3, 2022 16:12
Subtract A, r instruction for the z80 in a gameboy
void Instructions::do8bitSubRegToA(CPU* cpu, BYTE (Registers::*getRegFunc)()){
BYTE lInitialValue = cpu->reg->getA();
BYTE lToSub = (cpu->reg->*getRegFunc)();
WORD lTotal = lInitialValue - lToSub;
// If the lower nibble of the original value is less than the lower nibble of what we're subtracting, it'll need a half carry
cpu->reg->setFlagH((lInitialValue & 0x0f) < (lToSub & 0x0f)? 1 : 0);
// If the original value is less than we're subtracting it'll carry
cpu->reg->setFlagC(lInitialValue < lToSub ? 1 : 0);
@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 / 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;
@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 / 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) {