This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- | |
| -- hmlgrep - Haskell Multi-Line Grep | |
| -- | |
| {- | |
| TODOs: | |
| * FIX: '-' and '--' handling in optparse-applicative | |
| * https://github.com/pcapriotti/optparse-applicative/pull/99 | |
| * Use Cabal for build? | |
| * Use Boyer-Moore for non-regex patterns using stringsearch library: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dropLast n bstr = BS.take (BS.length bstr - n) bstr | |
| takeLast n bstr = BS.drop (BS.length bstr - n) bstr | |
| reComp pat = makeRegexOpts compBlank execBlank pat | |
| breakNextRegex re bstr = | |
| if pos >= 0 | |
| then BS.splitAt pos bstr | |
| else (bstr, BS.empty) | |
| where (pos, len) = bstr =~ re :: (MatchOffset,MatchLength) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| afterLastRegexOf :: ByteStr -> ByteStr -> ByteStr | |
| afterLastRegexOf pat bstr = revSearchRE 0 bstr | |
| where | |
| re = makeRegexOpts compBlank execBlank pat | |
| revSearchRE n s | |
| | BS.null s = bstr | |
| |_ | |
| | otherwise = revSearchRE (n+lastlinelen) () | |
| where | |
| lastline = afterLastRegexOf (pack "\n") s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Control.Monad | |
| import Data.Maybe | |
| regexChars = "^$(|)[]{}.*" | |
| regexCharsLast = "$)]}.*" | |
| toPlainString' :: String -> String -> Maybe String | |
| toPlainString' s [] = Just s | |
| toPlainString' s (r:[]) = if r `elem` regexCharsLast | |
| then Nothing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <script TYPE="text/javascript" LANGUAGE="javascript"> | |
| window.resizeTo(100,200); | |
| </script> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- | |
| -- hmlgrep - Haskell Multi-Line Grep | |
| -- | |
| {- | |
| TODOs: | |
| * Show filenames with --count option for multiple file input | |
| * Implement match highlight | |
| * FIX: '-' and '--' handling in optparse-applicative | |
| * https://github.com/pcapriotti/optparse-applicative/pull/99 | |
| * Use Boyer-Moore for non-regex patterns using stringsearch library: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import System.Console.ANSI | |
| import qualified Data.ByteString.Lazy.Char8 as BS | |
| import Text.Regex.PCRE | |
| import Text.Regex.PCRE.ByteString | |
| import Data.Int | |
| hlCode = setSGRCode [SetColor Foreground Vivid Red] | |
| hlReset = setSGRCode [Reset] | |
| d = map BS.pack [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cat result | while read t p; do t1=${t%-*}; t2=${t#*-}; p1=${p%-*}; p2=${t#*-}; t+=(t1 $t2); if (( p1 > p2 )); then echo ${t1} win; echo ${t2} lose; else echo ${t2} win; echo ${t1} lose; fi; done | sort | uniq -c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| n=$(<"$1") | |
| nums=($n) | |
| i=$(sort -nr $1|head -1) | |
| while ((i--)) | |
| do | |
| for num in "${nums[@]}" | |
| do | |
| if [ $i -gt $num ]; then | |
| echo -n " " |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| curl http://ekikara.jp/newdata/line/1301351.htm | nkf -u | grep '<span class="l"><a href="../station/[0-9]*.htm">' | sed -e 's/<[^>]*>//g' | tr -d ' ' | cut -d '(' -f 1 |