Liferay Mobile Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Thursday, 26 January 2012

Hexlify in Clojure

Posted on 11:44 by Unknown
Looking at this gist, I have created functionality similar to EMACS hexlify-buffer. In EMACS, it reads a binary file and presents two views by breaking the file into 16 bytes sections.  Each section is shown on the same line as in example below:







The first column is the offset into the file, in hex.

The 8 columns are the hex representation of the 16 bytes represented in the line.

The last column is a printable representation of the 16 bytes, with unprintable characters represented as a period.



The hexlify clojure function accepts a seq of bytes or chars and returns a vector, each element of the vector represents 16 bytes of the input.



For example:



(hexlify "The quick brown dog jumped over the lazy fox") 

 

=> ([("54" "68" "65" "20" "71" "75" "69" "63" "6b" "20" "62" "72" "6f" "77" "6e" "20")
("T" "h" "e" "." "q" "u" "i" "c" "k" "." "b" "r" "o" "w" "n" ".")
(84 104 101 32 113 117 105 99 107 32 98 114 111 119 110 32)]

[("20" "64" "6f" "67" "20" "6a" "75" "6d" "70" "65" "64" "20" "6f" "76" "65" "72")
("." "d" "o" "g" "." "j" "u" "m" "p" "e" "d" "." "o" "v" "e" "r")
(32 100 111 103 32 106 117 109 112 101 100 32 111 118 101 114)]

[("20" "74" "68" "65" "20" "6c" "61" "7a" "79" "20" "66" "6f" "78")
("." "t" "h" "e" "." "l" "a" "z" "y" "." "f" "o" "x")
(32 116 104 101 32 108 97 122 121 32 102 111 120)])


The first
element of each vector is the 16 hex values, one for each byte in the partition.  The second element in the vector is the printatble character representation and the last element in the vector is the numeric representation.



This allows inspection of byte arrays within clojure quickly and easily.





The code is repeated below:
Read More
Posted in clojure | No comments
Newer Posts Older Posts Home
Subscribe to: Comments (Atom)

Popular Posts

  • ASP.NET caching based on a cookie
    You have to use VaryByCustom parameter. Your OutputCache directive will look like this and you have declare the following method in which w...
  • Chapter�16.�Portlet MVC Framework
    Spring Portlet MVC applies the same principles to portlet development as the the Spring Web MVC framework applies to servlet development. F...
  • Wicket and Guice
    Are you sick of XML? I sure am. While I really like Spring Framework, I am sick of all the XML. Writing unit tests is hard enough, but ho...
  • Open Source Technical Support by OpenLogic
    This gets filed under the category of "Why didn't I think of this?". What an excellent business model. Take a free product a...
  • Linux.com | GNU Emacs 22 finally released
    I have just recently switched from Emacs to Eclipse for my Java development work. I still use Emacs almost everyday I even have an Emacs r...
  • Clojure: lazy seq + database = bad
    In my work on topoged-hibernate I naively thought that it would be great to return a lazy-seq of the results of a query like: However, th...
  • Hexlify in Clojure
    Looking at this gist , I have created functionality similar to EMACS hexlify-buffer. In EMACS, it reads a binary file and presents two views...
  • Watch "Advanced Topics in Programming Languages: Java Puzzlers, Episode VI"
    Advanced Topics in Programming Languages: Java Puzzlers, Episode VI 1 hr 13 min 49 sec - Jul 23, 2007 Average rating: (23 ratings) Descr...
  • LISP Cycles
    I admit it, I like LISP. There are a certain set of programming problems that it handles elegantly. I feel the same about AWK, BASH, SQL a...
  • Coding Horror: The "Works on My Machine" Certification Program
    I think we will be doing this at work. Coding Horror: The "Works on My Machine" Certification Program : " 1. Compile your a...

Categories

  • 1.3.0
  • abiword
  • apache
  • archiva
  • browser
  • clojure
  • ClojureScript
  • derby
  • exception
  • java
  • javaone
  • javascript
  • jdk
  • jquery
  • lein
  • Liferay
  • page background
  • patterns
  • swank
  • watermrk

Blog Archive

  • ►  2013 (3)
    • ►  November (1)
    • ►  July (1)
    • ►  May (1)
  • ▼  2012 (5)
    • ►  December (3)
    • ►  February (1)
    • ▼  January (1)
      • Hexlify in Clojure
  • ►  2011 (5)
    • ►  October (1)
    • ►  September (1)
    • ►  August (1)
    • ►  February (1)
    • ►  January (1)
  • ►  2010 (6)
    • ►  September (6)
  • ►  2009 (10)
    • ►  July (2)
    • ►  June (1)
    • ►  April (5)
    • ►  March (1)
    • ►  January (1)
  • ►  2008 (23)
    • ►  December (1)
    • ►  November (1)
    • ►  October (1)
    • ►  August (1)
    • ►  July (2)
    • ►  June (3)
    • ►  May (6)
    • ►  April (4)
    • ►  March (2)
    • ►  February (1)
    • ►  January (1)
  • ►  2007 (45)
    • ►  December (7)
    • ►  October (5)
    • ►  September (1)
    • ►  August (4)
    • ►  June (3)
    • ►  May (15)
    • ►  April (7)
    • ►  March (3)
Powered by Blogger.

About Me

Unknown
View my complete profile