Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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);
}
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: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
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],
-- 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
@martok
martok / syncrotron.cmd
Created April 17, 2017 22:05
Sync/Backup script based on Robocopy
@echo off
setlocal
echo ************************************************
echo **** Martok's Syncrotron ****
echo ************************************************
echo **** 1: Copy from this machine to exHDD ****
echo **** 2: Copy from exHDD to this machine ****
echo **** anything else: exit ****
echo ************************************************
set /p select="Choose option: "
@martok
martok / Al.meam
Created June 15, 2017 11:14
Testcase LAMMPS MEAM/C #1
Cmin(1,1,1) = 1
repuls(1,1) = 0.4770183040558415
nn2(1,1)=1
rc = 5.0
ialloy=1
augt1=0
delr=1
emb_lin_neg=1
bkgd_dyn=1
units metal
dimension 3
boundary p p p
atom_style atomic
timestep 0.001
variable min2th index 20
variable max2th index 90
lattice bcc 3.147