Skip to content

Instantly share code, notes, and snippets.

Nick Palmer Palmr

Block or report user

Report or block Palmr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View derEncodeECDSASignatureToUinit8Array.js
function derEncodeECDSASignatureToUinit8Array(signatureUint8Array) {
let out_sigder = new ArrayBuffer(72);
let out_sigder_DV = new DataView(out_sigder);
let out_sigder_BA = new Uint8Array(out_sigder);
// Need to caress into dumb der format ..
let i;
let lead_s = 0; // leading zeros
let lead_r = 0;
View TinyFPGA_BX_SPIDriver_flash.py
#!/usr/bin/env python3
## Highly advise running `setserial /dev/ttyUSB0 low_latency` before flashing
from spidriver import SPIDriver
import struct
import time
import sys
import getopt
View gb-link.js
@Palmr
Palmr / ImageUtil.java
Created May 28, 2015
Massive text draw function
View ImageUtil.java
//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 / tag-sorter.js
Created Oct 10, 2014
Sort tags by suggestion text value
View tag-sorter.js
// 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;
});
View trello-solve.js
// 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;
View Database.php
<?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 Nov 25, 2013
VBA to deal with some stock control stuff
View gist:7643101
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 Dec 11, 2015
Subtract A, r instruction for the z80 in a gameboy
View gist:4526839
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 Dec 11, 2015
Return instruction for the gameboy cpu emulator I'm writing
View gist:4520944
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;
You can’t perform that action at this time.