All pastes #1550945 Raw Edit

Mine

public text v1 · immutable
#1550945 ·published 2009-09-01 23:55 UTC
rendered paste body
'*-----------------------------------------------------------------*'
'  Debuging Helper Functions
function to_str( var )
	to_str = ""

	Dim ttype : ttype = TypeName(var)
	Dim str_items
	
	
	If IsArray(var) Then 
		Set str_items = CreateObject("Scripting.Dictionary")
		
		Dim item 
		For Each item in var
			str_items(to_str( item )) = 1
		Next
		to_str = to_str & "[" & Join(str_items.Keys, ", ")  & "]"
		Set str_items = Nothing
	ElseIf IsObject(var) Then 
		If ttype = "Dictionary" Then
			Dim key

			Set str_items = CreateObject("Scripting.Dictionary")
			For Each key In var.Keys
				pair = to_str(key) & ": " & to_str(var(key))
				str_items(pair) = 1
			Next 
	
			to_str = to_str & "{" & Join(str_items.Keys, ", ")  & "}"
			Set str_items = Nothing

		Else
			to_str = to_str  & "{" & ttype & "}"
		End If
	ElseIf IsEmpty(var) Then 
		to_str = to_str  & "{empty}"
	ElseIf IsNull(var) Then
		to_str = to_str  & "{null}"
	ElseIf ttype = "String" Then
		'Replace quotes with doble quotes, and put in quotes
		to_str = to_str  & "{""" &  Replace(var, """", """" & """" )  &  """}"
	Else
		to_str = to_str & var 
	End If


end function 

sub pp(var)
	Response.Write( to_str(var) )
end sub 

sub ppl(label, var)
	Response.Write( label & ": <pre>" & to_str(var) & "</pre>"  )
end sub

sub ppe(var)
	all_tags = Array("address", "applet", "area", "a", "base", "basefont", "big", "blockquote", "body", "br", "b", "caption", "center", "cite", "code", "dd", "dfn", "dir", "div", "dl", "dt", "em", "font", "form", "h1", "h2", "h3", "h4", "h5", "h6", "head", "hr", "html", "img", "input", "isindex", "i", "kbd", "link", "li", "map", "menu", "meta", "ol", "option", "param", "pre", "p", "samp", "script", "select", "small", "strike", "strong", "style", "sub", "sup", "table", "td", "textarea", "th", "title", "tr", "tt", "ul", "u", "var", "table", "table", "table", "table", "table")
	close_tags = "</" & Join(all_tags, "></") & ">"

	Response.Write close_tags & "<plaintext>"
	pp(var)
	Response.End
end sub 

'*-----------------------------------------------------------------*'
'* Actual Useful Stuff

'**
'* Gets a simple hash for the given string
'** 
Function SimpleHash( str )
	Const CHUNK_SIZE = 8	
	Const BIG_PRIME = 2146351343

	Dim hex_str : hex_str = ""
	For i = 1 To Len( str )
		hex_str = hex_str & CStr( Hex( Asc( Mid( str, i, 1 ))))
	Next 

	Dim num : num = 0
	Do While Len( hex_str ) > 0
		' Pull off the first Chunk Size characters
		Dim small_hex_str : small_hex_str = Left(hex_str, CHUNK_SIZE )
		
		If Len( hex_str ) > CHUNK_SIZE  Then 
			hex_str = Right(hex_str, Len( hex_str ) - CHUNK_SIZE )
		Else
			small_hex_str = hex_str
			hex_str = ""
		End If
		
		mod_num = BIG_PRIME Mod CLng( "&H" & small_hex_str )
		num = num + mod_num
	Loop 
	
	SimpleHash = CStr(num)
End Function

Call ppl( "ab", SimpleHash("ba" ))
Call ppl( "chickens have eggs", SimpleHash( "chickens have eggs" ))
Call ppl( "eggs have chickens", SimpleHash( "eggs have chickens" ))
Call ppl( "http://www.thelongestlistofthelongeststuffatthelongestdomainnameatlonglast.com/wearejustdoingthistobestupidnowsincethiscangoonforeverandeverandeverbutitstilllookskindaneatinthebrowsereventhoughitsabigwasteoftimeandenergyandhasnorealpointbutwehadtodoitanyways.html", SimpleHash( "http://www.thelongestlistofthelongeststuffatthelongestdomainnameatlonglast.com/wearejustdoingthistobestupidnowsincethiscangoonforeverandeverandeverbutitstilllookskindaneatinthebrowsereventhoughitsabigwasteoftimeandenergyandhasnorealpointbutwehadtodoitanyways.html" ))

' Ack a collision!
Call ppl( "aaaaaaaabbbbbbbb", SimpleHash("aaaaaaaabbbbbbbb" ))
Call ppl( "bbbbbbbbaaaaaaaa", SimpleHash("bbbbbbbbaaaaaaaa" ))