Skip to content

Instantly share code, notes, and snippets.

@rdm
rdm / wp.jq
Created November 7, 2018 21:34
A parser for the wordpress maybe_serialize() format implemented in jq [mostly working, trying to track down an error case]
def q: sub("\\\\";"\\\\";"g")|sub("'"; "\\'"; "g")|sub("^";"'")|sub("$";"'");
def slength: sub("\\\\";".";"g")|length;
def towp:
if "null"==type then "N;"
elif "boolean"==type then if . then "b:1;" else "b:0;" end
elif "number"==type then if .==(.|floor) and .<9e15 then "i:"+(.|tostring)+";" else "d:"+(.|tostring)+";" end
elif "string"==type then "s:"+(.|slength|tostring)+":\""+.+"\";"
else "a:"+(.|length|tostring)+":{"+(.|[to_entries|map(to_entries)[]|map(.value|towp)|add]|add)+"}"
@rdm
rdm / z
Created November 7, 2018 21:32
an arbitrary json structure as represented by wordpress's maybe_serialize()
a:10:{s:14:"cooked_version";s:5:"1.4.1";s:16:"difficulty_level";s:1:"0";s:9:"prep_time";s:1:"5";s:9:"cook_time";s:0:"";s:7:"content";s:941:"<div class="recipe-content margin-40-bottom">\r\n<div class="image-container">[cooked-image]</div>\r\n<div class="recipe-meta-container clearfix">[cooked-info left="servings,prep_time,cook_time,total_time"]</div>\r\n[cooked-info left="author,difficulty" right="print,fullscreen"]\r\n<div class="recipe-summary margin-8-bottom">\r\n<div class="margin-0-auto">[cooked-excerpt]</div>\r\n</div>\r\n<div class="clearfix recipe-ingredients-instructions">\r\n<div class="sidebar padded-mobile padding-8 grid-item grid-7-of-16">\r\n<div class="partial recipe-ingredients">\r\n<h2>Ingredients</h2>\r\n<p>[cooked-ingredients]</p>\r\n</div>\r\n<div class="partial recipe-ingredients">[cooked-nutrition]</div>\r\n</div>\r\n<div class="recipe-steps padded-mobile padding-8-top float-left grid-item grid-9-of-16">\r\n<div class="recipe-instructions margin-0-auto">\r\n<h2 class="margin-0-auto">How
@rdm
rdm / gist:52d851f5f1cf15641950
Created July 14, 2015 11:19
interpreter calling a function in a dynamically linked shared object whose argument types (and entry point name) are specified at runtime
; switch(cnt){ case 0: r = fp(); break; case 1: r = fp(d[0]); break; case 2: r = fp(d[0], d[1]); break; case 3: r = fp(d[0], d[1], d[2]); break; case 4: r = fp(d[0], d[1], d[2], d[3]); break; case 5: r = fp(d[0], d[1], d[2], d[3], d[4]); break; case 6: r = fp(d[0], d[1], d[2], d[3], d[4], d[5]); break; case 7: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6]); break; case 8: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7]); break; case 9: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8]); break; case 10: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9]); break; case 11: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10]); break; case 12: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10],d[11]); break; case 13: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10],d[11],d[12]); break; case 14: r = fp(d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10],d[11],d[12],d[13]); break; case 15: r = fp(d[0], d
NB. Mike Day
NB. 6/25/15
load'viewmat'
'BLACK BLUE GREEN CYAN RED MAGENTA YELLOW WHITE'=:#:i.8
msc=:mysquarecolours =: 3 : 0
:
gl3lab_run''
get_pixels 10 10
@rdm
rdm / gist:3170282b06532400ccc8
Created March 13, 2015 13:03
keybase.io verfication
### Keybase proof
I hereby claim:
* I am rdm on github.
* I am rdm (https://keybase.io/rdm) on keybase.
* I have a public key whose fingerprint is D3CE 2BCC 07BC 89E2 B49B 8822 6C88 FCF8 618C C6E0
To claim this, I am signing this object:
@rdm
rdm / nif.ijs
Created February 16, 2014 21:42
Draft nif handling code. Parses nif.xml and some Morrowing nif files
NB. roughly patterened after http://rpmfind.net/linux/RPM/sourceforge/p/py/pyffi/OldFiles/PyFFI-0.0-1.noarch.html
NB. you should not expect to read this any faster than you read the whole of PyFFI
NB. and if you are new to J you should also expect to spend some time learning the language
NB. recommendation: take breaks occasionally, play with this, try to make it fun
require '~user/nifxml.ijs'
coinsert 'nifxml' NB. for cond expressions
NB. FIXME: do not inherit from nifxml - factor out the expr support
NB. FIXME: most of this nif.ijs should be factored out into readnif.ijs which inherits from nif.ijs
@rdm
rdm / copy.ijs
Created February 6, 2014 13:40
require 'csv'
stordir=: <'c:\voxtst\' NB. note < and trailing \
NB. Convert the csv file to a boxed J array
csvdata=: readcsv 'c:\voxtst\prophecy.csv'
NB. filenames
sourcefnames=: }. 0 {"1 csvdata
targetfnames=: stordir,each (}. 2 {"1 csvdata),each <'.wav'
assert (-: ~.) targetnames NB. unique file names
cocurrent 'CurveFp'
Help=: 'Elliptic Curve over the field of integers modulo a prime.'
create=:3 :0
NB. The curve of points satisfying y^2 = x^3 + a*x + b (mod p).
'P A B'=: x:&> y
poly=: B,A,0,1
)
p=:3 :'P'
a=:3 :'A'
@rdm
rdm / Example use:
Created January 30, 2014 22:07
Draft: extract data from wavxml files (or similar xml files)
filename=: 'name'&extract_fromxmlfile_
directory=: 'hash'&extract_fromxmlfile_
sosgatetime=: ('utterance';'startofspeechgate';'time')&extract_fromxmlfile_
sosgatevalue=: ('utterance';'startofspeechgate';'value')&extract_fromxmlfile_
sostime=: ('utterance';'startofspeech';'time')&extract_fromxmlfile_
sosvalue=: ('utterance';'startofspeech';'value')&extract_fromxmlfile_
eostime=: ('utterance';'endofspeech';'time')&extract_fromxmlfile_
eosvalue=: ('utterance';'endofspeech';'value')&extract_fromxmlfile_
finalresult=: ('utterance';'finalresult';'value')&extract_fromxmlfile_
confidence=: ('utterance';'finalresult';'confidence')&extract_fromxmlfile_