Skip to content

Instantly share code, notes, and snippets.

@andfaulkner
Last active May 16, 2016 08:51
Show Gist options
  • Save andfaulkner/b3ba14f2d1169971bedacb072e760fbe to your computer and use it in GitHub Desktop.
Save andfaulkner/b3ba14f2d1169971bedacb072e760fbe to your computer and use it in GitHub Desktop.
Batsignal templates: a simple microtemplate intended for temporary injection of code for debugging: highly obtrusive tag, easy to match, no accidental captures, super-simple.

BATSIGNAL MICROTEMPLATES

  • let your code swoop in and swoop out like a bat. Like a Batman.
  • concept: template markers so absurdly safe they can be injected & extracted without tokenization
    • use: temporary injections of code for debugging purposes
  • only a single template operator / matching tag-set provided.
    • One operator is all you need, when your operator is the batsignal.

Tags - aka the batsignal

  • Upper tag (startbat): #</--_>#

  • Lower tag (endbat): #<__/-END-__>#

  • Aims:

    • create a set of tags so big, obtrustive, and messy that no one could possibly forget to take them out
    • create a pattern that won't trigger a single accidental match in any codebase anywhere.

Matching Regex

#<INJECT><__\/-___-\\__><INJECT>#.+?#<ENDINJECT><__\/-END-\\__><ENDINJECT>#

Demonstration

Random set of text, with sections surrounded by Batsignals

  <&::{}[]!@#$%^&*()-=_+,.<>/?\|;:'"~`
  gaewggawg
  
  aswef
  #<INJECT><__/-___-\__><INJECT>#
  erg
  #<ENDINJECT><__/-END-\__><ENDINJECT>#
  waf
  awegwg
  
  #<INJECT><__/-___-\__><INJECT>#
  nntmine  ergiuh aeriu
  
  ergeg erg egr 
  #<ENDINJECT><__/-END-\__><ENDINJECT>#

Matches found

##ONE: #</--_># erg #<__/-END-__>#

##TWO: #</--_># nntmine ergiuh aeriu

  ergeg erg egr 
  #<ENDINJECT><__/-END-\__><ENDINJECT>#

Rubular!

http://rubular.com/r/EwCj78oxYj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment