<commit_before># namespace and constants

@Bu =
	version: '0.3.0'

	# shapes related
	DEFAULT_STROKE_STYLE:       '#048'
	DEFAULT_FILL_STYLE:         'rgba(64, 128, 192, 0.5)'
	DEFAULT_DASH_STYLE:         [8, 4]

	# interaction related
	DEFAULT_STROKE_STYLE_HOVER:   'rgba(255, 128, 0, 0.75)'
	DEFAULT_FILL_STYLE_HOVER:   'rgba(255, 128, 128, 0.5)'

	# texts related
	DEFAULT_TEXT_FILL_STYLE:    'black'

	# default size
	DEFAULT_IMAGE_SIZE: 20
	POINT_RENDER_SIZE: 4


	# bounds related
	DEFAULT_BOUND_STROKE_STYLE:  '#444'
	DEFAULT_BOUND_DASH_STYLE:    [6, 6]

	# computation related
	DEFAULT_NEAR_DIST: 5

	# mouse interact
	MOUSE_BUTTON_NONE:   -1
	MOUSE_BUTTON_LEFT:   0
	MOUSE_BUTTON_MIDDLE: 1
	MOUSE_BUTTON_RIGHT:  2

###
# math
###

# calculate the mean value of several numbers
Bu.average = ()->
	ns = arguments
	ns = arguments[0] if typeof arguments[0] is 'object'
	sum = 0
	for i in ns
		sum += i
	sum / ns.length

# calculate the hypotenuse from the cathetuses
Bu.bevel = (x, y) ->
	Math.sqrt x * x + y * y

# generate a random number between two numbers
Bu.rand = (from, to) ->
	if not to?
		to = from
		from = 0
	Math.random() * (to - from) + from

###
# utils
###

# get current time
# TODO use performance
Bu.now = Date.now

# combine the given options(last item in arguments) with the default options
Bu.combineOptions = (args, defaultOptions) ->
	defaultOptions = {} if not defaultOptions?
	givenOptions = args[args.length - 1]
	if typeof givenOptions is 'object'
		for i of givenOptions
			defaultOptions[i] = givenOptions[i]
	return defaultOptions

###
# polyfill
###

# define a property for a class
Function::property = (prop, desc) ->
	Object.defineProperty @prototype, prop, desc

# throttle
Function::throttle = (limit = 0.5) ->
	currTime = 0
	lastTime = 0

	return () =>
		currTime = Date.now()
		if currTime - lastTime > limit * 1000
			@apply null, arguments
			lastTime = currTime

# debounce
Function::debounce = (delay = 0.5) ->
	args = null
	timeout = null

	later = =>
		@apply null, args

	return () ->
		args = arguments
		clearTimeout timeout
		timeout = setTimeout later, delay * 1000


# Array
Array::each or= (fn) ->
	i = 0
	while i < @length
		fn @[i]
		i++
	return @

Array::map or= (fn) ->
	arr = []
	i = 0
	while i < @length
		arr.push fn(@[i])
		i++
	return @
<commit_msg>use `window.performance`<commit_after># namespace and constants

@Bu =
	version: '0.3.0'

	# shapes related
	DEFAULT_STROKE_STYLE:       '#048'
	DEFAULT_FILL_STYLE:         'rgba(64, 128, 192, 0.5)'
	DEFAULT_DASH_STYLE:         [8, 4]

	# interaction related
	DEFAULT_STROKE_STYLE_HOVER:   'rgba(255, 128, 0, 0.75)'
	DEFAULT_FILL_STYLE_HOVER:   'rgba(255, 128, 128, 0.5)'

	# texts related
	DEFAULT_TEXT_FILL_STYLE:    'black'

	# default size
	DEFAULT_IMAGE_SIZE: 20
	POINT_RENDER_SIZE: 4


	# bounds related
	DEFAULT_BOUND_STROKE_STYLE:  '#444'
	DEFAULT_BOUND_DASH_STYLE:    [6, 6]

	# computation related
	DEFAULT_NEAR_DIST: 5

	# mouse interact
	MOUSE_BUTTON_NONE:   -1
	MOUSE_BUTTON_LEFT:   0
	MOUSE_BUTTON_MIDDLE: 1
	MOUSE_BUTTON_RIGHT:  2

###
# math
###

# calculate the mean value of several numbers
Bu.average = ()->
	ns = arguments
	ns = arguments[0] if typeof arguments[0] is 'object'
	sum = 0
	for i in ns
		sum += i
	sum / ns.length

# calculate the hypotenuse from the cathetuses
Bu.bevel = (x, y) ->
	Math.sqrt x * x + y * y

# generate a random number between two numbers
Bu.rand = (from, to) ->
	if not to?
		to = from
		from = 0
	Math.random() * (to - from) + from

###
# utils
###

# get current time
Bu.now = if window?.performance? then -> window.performance.now() else -> Date.now()

# combine the given options(last item in arguments) with the default options
Bu.combineOptions = (args, defaultOptions) ->
	defaultOptions = {} if not defaultOptions?
	givenOptions = args[args.length - 1]
	if typeof givenOptions is 'object'
		for i of givenOptions
			defaultOptions[i] = givenOptions[i]
	return defaultOptions

###
# polyfill
###

# define a property for a class
Function::property = (prop, desc) ->
	Object.defineProperty @prototype, prop, desc

# throttle
Function::throttle = (limit = 0.5) ->
	currTime = 0
	lastTime = 0

	return () =>
		currTime = Date.now()
		if currTime - lastTime > limit * 1000
			@apply null, arguments
			lastTime = currTime

# debounce
Function::debounce = (delay = 0.5) ->
	args = null
	timeout = null

	later = =>
		@apply null, args

	return () ->
		args = arguments
		clearTimeout timeout
		timeout = setTimeout later, delay * 1000


# Array
Array::each or= (fn) ->
	i = 0
	while i < @length
		fn @[i]
		i++
	return @

Array::map or= (fn) ->
	arr = []
	i = 0
	while i < @length
		arr.push fn(@[i])
		i++
	return @

{'fraction_non_alphanumeric': 0.12187833511205977, 'fraction_numerical': 0.031163287086446105, 'mean_word_length': 3.4, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3655618', 'n_tokens_mistral': 1918, 'n_tokens_neox': 1740, 'n_words': 505}