Skip to content

Instantly share code, notes, and snippets.

@martok
martok / gist:6f855c8887fd4f33454d
Last active August 29, 2015 14:16
IKEv1 Parser
<?php
define('IND','&nbsp;&nbsp;');
function hex2bin( $str ) {
$sbin = "";
$len = strlen( $str );
for ( $i = 0; $i < $len; $i += 2 ) {
$sbin .= pack( "H*", substr( $str, $i, 2 ) );
}
@martok
martok / counter.py
Created January 13, 2015 18:22
MCEdit Block/Height filter
from pymclevel import items
def itembyname(name):
if name in items.items.items:
return items.items.itewms[name]["id"]
return 0
def namebyitem(id):
item = items.items.findItemID(id)
if type(item["name"]) == str or type(item["name"]) == unicode:
@martok
martok / SystemExceptionHandling.pas
Created September 10, 2013 23:06
Custom exception handler for use with FPC
unit SystemExceptionHandling;
// Inspired by what is described at FPC's forums:
// http://bugs.freepascal.org/view.php?id=12974 [^]
//
// especially in comment 0040683 by Bernd Kreuss
{$mode objfpc}{$H+}
{$AsmMode intel}
-- Automatic Treefarm
-- * Works with or without Bonemeal
-- * Optimized for Birchwood, but should work with any 1x1 tree that doesn't branch
-- Martok 2013-04-05
local WORK,WORK2,SAPLING,LOG = 13,14,15,16
if (turtle.getItemCount(WORK) ~= 0) or (turtle.getItemCount(WORK2) ~= 0) or (turtle.getItemCount(SAPLING) == 0) or (turtle.getItemCount(LOG) == 0) then
print("Please clear Slots ",WORK,"+",WORK2,", put 1 Sapling in Slot ",SAPLING," and 1 Log in Slot ",LOG,".")
print("Bonemeal may be placed in any Slot not mentioned before.")
return
end
decode[text_String, key_String] := Module[{textCode, keyCode},
textCode =
Cases[ToCharacterCode[
ToUpperCase@
text], _?(IntervalMemberQ[Interval@{65, 90}, #] &)] - 65;
keyCode =
Cases[ToCharacterCode[
ToUpperCase@
key], _?(IntervalMemberQ[Interval@{65, 90}, #] &)] - 65;
keyCode = If[Length[textCode] < Length[keyCode],
@martok
martok / gist:2789728
Created May 25, 2012 18:39
TClass.ImmediateMethods
// Parses a classes vmtMethodTable and finds all `published` methods this class declares.
// Find all available functions by recusing up the hierarchy with .ClassParent
// Martok 2012 - Public Domain / CC0
TMethodTable = array of record
Code: Pointer;
Name: String;
end;
TTest = class
function TryTrunc(x: Extended; out Val: Int64): boolean;
var
oldcw, cw, sw: word;
asm
fld x
fwait
fnstcw oldcw
fnstcw cw
fwait
@martok
martok / gist:1223953
Created September 17, 2011 13:48
ASCIIoverUTF8
//Ref: http://twitter.com/BenBE1987/statuses/115050893115797505
ASCIIoverUTF8 = {
write: function(msg) {
var result = '';
(msg.length%2) && (msg+=String.fromCharCode(0));
for (var i=0;i<msg.length; i+=2) {
var a=msg.charCodeAt(i)&0xFF,
b=msg.charCodeAt(i+1)&0xFF;
result+=String.fromCharCode((a<<8) | b);
}