Skip to content

Instantly share code, notes, and snippets.

@ptvirgo
ptvirgo / main.hs
Last active June 20, 2017 04:21
Attempting Knuth-Morris-Pratt in Haskell for Hackerrank. But - time out ?
module Main where
-- | Return a Knuth-Morris-Pratt index for a given string
stringIndex :: String -> [Int]
stringIndex "" = []
stringIndex txt = indexr [0] 0 1 where
indexr :: [Int] -> Int -> Int -> [Int]
indexr rsf subPos chrPos
@ptvirgo
ptvirgo / byte_size.py
Created August 27, 2017 13:21
I caught a rude character interfering with my data migration...
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
RUDE = b"\xe3\x80\x82".decode("utf-8")
def limit_slice(maxlen, text):
"""Given a maximum length and text, return the text truncated to the provided
length."""
@ptvirgo
ptvirgo / keybase.md
Created October 30, 2018 17:39
Keybase ID confirmation

Keybase proof

I hereby claim:

  • I am ptvirgo on github.
  • I am ptvirgo (https://keybase.io/ptvirgo) on keybase.
  • I have a public key ASAiGKbmaGb-JBhjQfGNtN7lQBNlWm9Bj4hUb0_59iUdnwo

To claim this, I am signing this object: