Skip to content

Instantly share code, notes, and snippets.

@shinkou
shinkou / lcsv.py
Last active Jun 27, 2022
A snippet which crops from CSVs with a very small memory footprint
View lcsv.py
#!/usr/bin/env python3
# vim: fileencoding=utf-8 ff=unix hls lcs=tab\:>. list noet sw=4 ts=4 tw=76
#
# How to use:
#
# Scenario 1 - show only the first 16 entries
# $ lcsv.py --limit 16 my_data.csv
#
# Scenario 2 - convert CSV which uses pipe characters "|" back to commas
# $ lcsv.py --output-delimiter=, --delimiter='|' my_data.csv
@shinkou
shinkou / unescape.py
Created May 12, 2022
A snippet which does what the unescape function does in Javascript
View unescape.py
#!/usr/bin/env python3
# vim: fileencoding=utf-8 ff=unix lcs=tab\:>. list noet sw=4 ts=4 tw=0
#
# How to use:
# $ unescape.py 'Line 1\nLine 2\nLine 3\n' 'いち\nに\nさん\n'
#
import sys
def unescape(s):
return s.encode('raw_unicode_escape').decode('unicode_escape')
@shinkou
shinkou / McrouterTest.java
Last active Apr 22, 2021
Test connectivity of memcached clusters backed by Mcrouter
View McrouterTest.java
/*
* The MIT License (MIT)
*
* Copyright (c) 2021 Chun-Kwong Wong
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
@shinkou
shinkou / emoji_detector.py
Last active May 22, 2020
A Python 3 snippet which detects if input parameters have any emoji
View emoji_detector.py
#!/usr/bin/env python3
# vim: fenc=utf-8 ff=unix lcs=tab\:>. list noet ru sw=4 ts=4 tw=0
#
# How to use:
# $ emoji_detector.py 'sentence with emoji <INSERT EMOJI HERE>' ...
#
import re, sys
# [\u00a9\u00ae\u203c-\u2b55\u3030\u303d\u3297\u3299\U0001f004-\U0001fad6] # Emoji
# [\U0001f3fb-\U0001f3ff] # EMod
@shinkou
shinkou / EmojiDetector.java
Last active Apr 29, 2020
A Java snippet which detects if input parameters have any emoji
View EmojiDetector.java
/*
* The MIT License (MIT)
*
* Copyright (c) 2020 Chun-Kwong Wong
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is