Skip to content

Instantly share code, notes, and snippets.

@joemfb
joemfb / string-srch.hoon
Last active June 28, 2016 00:23
brute force and KMP string search
:: brute force and KMP string search
:: arms accessible in dojo after /+ string-srch
:: try test:string-srch
::
:::: /hoon/string-srch/lib
::
/? 314
!:
:::: ~novlen-hanweb
::
{
"intros": [
"Just write some Hoon that",
"Just compose Nock formulas that",
"Just use Arvo to"
],
"ships": [
"~zod",
"~fyr",
"~ped",
:- %say
|= {{@da eny/@uvI beak} $~ $~}
:- %tang =< (to-tang (easy))
|%
++ to-tang
|= l/(list tape)
^- tang
%- flop %+ turn l
|=(t/tape ^-(tank [%leaf t]))
++ dlists $:
~novlen-hanweb@ grants that it's a little heavy-handed
--------------| for '=' /urbit-meta
--------------| --met ~tanpem-rolnul-danneb-hoslyt--socnyl-figteg-fotlev-datben
--------------| for '=' /urbit-meta
--------------| --met ~bolryl-niddem-poctyv-sapwep--fogsur-tornux-fotlev-datben
-------[12.955]
~lavbyr_datben* now anyone can be a _dotben!
~haclud_malfep= looks pretty good to me
~lavbyr_datben deploys an audience fix
~haptem-fopnys= why are people's audiences messed up
@joemfb
joemfb / cartesian-product.hoon
Created June 14, 2016 04:40
produces the cartesian product of two sets-of-strings in Hoon
:- %say |= * :- %noun
=< (cartesian-product (sy ['a' 'b' 'c' ~]) (sy ['x' 'y' 'z' ~]))
::
|% ++ cartesian-product
|= {a/(set @t) b/(set @t)}
=+ r=*(set {@t @t})
|- ?~ a r
=+ b=b :: shadow b for inner loop walkthru
|- ?~ b
=+ ^= r
:- %say |= * :- %noun
::
:::: sets (http://urbit.org/docs/hoon/exercises/data-structures/)
::
=+ s=(silt `(list @t)`['urbit' 'arvo' 'hoon' 'arvo' ~])
~& 'original set'
~& s
::
:::: #1
::
@joemfb
joemfb / search.peg
Created February 1, 2016 19:09
PEG.js search grammar
{
function joinNested(x) {
return x.map(function(y) {
return Array.isArray(y) ? joinNested(y) : y
}).join('')
}
}
// match all rules, consuming the entire input
root = a:all EOF { return a }
@joemfb
joemfb / structured-query-utils.xqy
Last active April 13, 2016 13:30
MarkLogic structured query conversion functions
xquery version "1.0-ml";
(:~
: Utility module from converting structured queries to/from JSON, XML, and cts:query
:)
module namespace sq = "http://marklogic.com/mlpm/structured-query";
import module namespace ast = "http://marklogic.com/appservices/search-ast"
at "/MarkLogic/appservices/search/ast.xqy";
import module namespace sut = "http://marklogic.com/rest-api/lib/search-util"
@joemfb
joemfb / aggregates.xqy
Last active August 29, 2015 14:19
aggregate function metadata
xquery version "1.0-ml";
declare variable $numeric-scalar-types := ("int", "unsignedInt", "long", "unsignedLong", "float", "double", "decimal");
declare function local:scalar-types()
{
xdmp:read-cluster-config-file("database.xsd")/xs:schema
/xs:simpleType[@name eq "scalar-type"]/xs:restriction/xs:enumeration/@value/fn:string()
};
@joemfb
joemfb / mlpm_deploy.rb
Last active August 29, 2015 14:14
Roxy app_specific.rb module for deploying mlpm packages
require 'json'
class ServerConfig
alias_method :original_deploy_modules, :deploy_modules
def deploy_modules
# if @properties['ml.deploy-include-packages']
# deploy_packages
# end