<commit_before>hx.deprecatedWarning = (deprecatedItem, messages...) ->
  heading = "Deprecation Warning: #{deprecatedItem}"
  messages = ['Alternatives:'].concat messages.map (d) -> '  ' + d
  messages = messages.map (d) -> '  ' + d
  console.warn [heading].concat(messages).join('\n')
  console.trace('Stack Trace')

hx.consoleWarning = (heading, messages...) ->
  #messages = messages.map (d) -> '  ' + d
  console.warn.apply(console, [heading].concat(messages))
  console.trace('Stack Trace')

# consistent string to int hashing
hx.hash = (str, max) ->
  res = 0
  len = str.length-1
  for i in [0..len] by 1
    res = res * 31 + str.charCodeAt(i)
    res = res & res
  if max then Math.abs(res) % max else res

# transposes a 2d array
hx.transpose = (data) ->
  if not data.length? then return undefined
  w = data.length
  if w==0 or not data[0].length? then return data
  h = data[0].length
  transposed = new Array(h)
  for i in [0...h] by 1
    transposed[i] = new Array(w)
    for j in [0...w] by 1
      transposed[i][j] = data[j][i]
  transposed

supportsTouch = undefined
supportsDate = undefined

hx.supports = (name) ->
  switch name
    when 'touch'
      supportsTouch ?= 'ontouchstart' of window
    when 'date'
      if supportsDate is undefined
        input = document.createElement("input")
        input.setAttribute("type", "date")
        supportsDate = input.type != "text"
      supportsDate

hx.debounce = (duration, fn) ->
  timeout = undefined
  return ->
    origArgs = arguments
    if timeout then clearTimeout(timeout)
    f = ->
      timeout = undefined
      fn.apply(this, origArgs)
    timeout = setTimeout(f, duration)

hx.clamp = (min, max, value) -> Math.min(max, Math.max(min, value))

hx.clampUnit = (value) -> hx.clamp(0, 1, value)

hx.randomId = (size=16, alphabet='ABCEDEF0123456789') ->
  chars = alphabet.split('')
  alphabetSize = chars.length
  v = (chars[Math.floor(Math.random() * alphabetSize)] for _ in [0...size] by 1)
  v.join('')

hx.min = (values) -> Math.min.apply(null, values?.filter(hx.defined))

hx.minBy = (values, f) ->
  if not values? or values.length is 0 then return undefined

  if f
    min = values[0]
    maxValue = f(min)
    for i in [1...values.length] by 1
      v = values[i]
      fv = f(v)
      if minValue is undefined or (fv isnt undefined and fv < minValue)
        min = v
        minValue = fv
    min
  else
    min = values[0]<commit_msg>Fix a copy paste error<commit_after>hx.deprecatedWarning = (deprecatedItem, messages...) ->
  heading = "Deprecation Warning: #{deprecatedItem}"
  messages = ['Alternatives:'].concat messages.map (d) -> '  ' + d
  messages = messages.map (d) -> '  ' + d
  console.warn [heading].concat(messages).join('\n')
  console.trace('Stack Trace')

hx.consoleWarning = (heading, messages...) ->
  #messages = messages.map (d) -> '  ' + d
  console.warn.apply(console, [heading].concat(messages))
  console.trace('Stack Trace')

# consistent string to int hashing
hx.hash = (str, max) ->
  res = 0
  len = str.length-1
  for i in [0..len] by 1
    res = res * 31 + str.charCodeAt(i)
    res = res & res
  if max then Math.abs(res) % max else res

# transposes a 2d array
hx.transpose = (data) ->
  if not data.length? then return undefined
  w = data.length
  if w==0 or not data[0].length? then return data
  h = data[0].length
  transposed = new Array(h)
  for i in [0...h] by 1
    transposed[i] = new Array(w)
    for j in [0...w] by 1
      transposed[i][j] = data[j][i]
  transposed

supportsTouch = undefined
supportsDate = undefined

hx.supports = (name) ->
  switch name
    when 'touch'
      supportsTouch ?= 'ontouchstart' of window
    when 'date'
      if supportsDate is undefined
        input = document.createElement("input")
        input.setAttribute("type", "date")
        supportsDate = input.type != "text"
      supportsDate

hx.debounce = (duration, fn) ->
  timeout = undefined
  return ->
    origArgs = arguments
    if timeout then clearTimeout(timeout)
    f = ->
      timeout = undefined
      fn.apply(this, origArgs)
    timeout = setTimeout(f, duration)

hx.clamp = (min, max, value) -> Math.min(max, Math.max(min, value))

hx.clampUnit = (value) -> hx.clamp(0, 1, value)

hx.randomId = (size=16, alphabet='ABCEDEF0123456789') ->
  chars = alphabet.split('')
  alphabetSize = chars.length
  v = (chars[Math.floor(Math.random() * alphabetSize)] for _ in [0...size] by 1)
  v.join('')

hx.min = (values) -> Math.min.apply(null, values?.filter(hx.defined))

hx.minBy = (values, f) ->
  if not values? or values.length is 0 then return undefined

  if f
    min = values[0]
    minValue = f(min)
    for i in [1...values.length] by 1
      v = values[i]
      fv = f(v)
      if minValue is undefined or (fv isnt undefined and fv < minValue)
        min = v
        minValue = fv
    min
  else
    min = values[0]
{'fraction_non_alphanumeric': 0.14482616745525612, 'fraction_numerical': 0.01440032915038058, 'mean_word_length': 2.861795075456712, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '793230', 'n_tokens_mistral': 1716, 'n_tokens_neox': 1673, 'n_words': 475}