Skip to content

Instantly share code, notes, and snippets.

@shinkou
shinkou / EmojiDetector.java
Last active April 29, 2020 01:58
A Java snippet which detects if input parameters have any emoji
/*
* 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
@shinkou
shinkou / emoji_detector.py
Last active May 22, 2020 01:56
A Python 3 snippet which detects if input parameters have any emoji
#!/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 / McrouterTest.java
Last active April 22, 2021 14:36
Test connectivity of memcached clusters backed by Mcrouter
/*
* 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 / unescape.py
Created May 12, 2022 18:22
A snippet which does what the unescape function does in Javascript
#!/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 / lcsv.py
Last active September 2, 2023 02:14
A snippet which crops from CSVs with a very small memory footprint
#!/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 / dst.sh
Created December 6, 2023 14:46
A snippet which finds out whether a given date is DST (Daylight Saving Time) or not
#!/bin/bash
# Reference Source
# https://www.nist.gov/pml/time-and-frequency-division/popular-links/daylight-saving-time-dst
function is_dst()
{
epoch_secs=$(date --date="$1" +%s)
src_yr=$(date --date="$1" +%Y)
mar1wday=$(date --date="$src_yr-03-01" +%w)
@shinkou
shinkou / imv.py
Created February 19, 2024 21:18
Randomized File Renamer
#!/usr/bin/env python3
# vim: fileencoding=utf-8 ff=unix
from math import log
from random import randint
import argparse
import logging
import os
import re
import sys
@shinkou
shinkou / mstposter.py
Last active February 27, 2024 02:10
MS Teams Poster
#!/usr/bin/env python3
# vim: fileencoding=utf-8 ff=unix
import argparse, json, requests, sys
def message(
webhook, msg
, links=None, facts=None, subtitle=None, title=None, themecolor=None
):
payload = {
@shinkou
shinkou / jmesqry.py
Created March 15, 2024 05:40
JMESPath Evaluator
#!/usr/bin/env python3
# vim: fileencoding=utf-8
import argparse, jmespath, json, sys
def get_args():
parser = argparse.ArgumentParser(description='JMESPath Evaluator')
parser.add_argument('-i', '--indent', type=int, help='indent')
parser.add_argument(
'--ensure-ascii'
@shinkou
shinkou / timeconv.py
Last active March 21, 2024 02:19
Local/Remote Time Converter
#!/usr/bin/env python3
# vim: fileencoding=utf-8 ff=unix
from datetime import datetime
from zoneinfo import ZoneInfo
import argparse, os, time
def get_args():
parser = argparse.ArgumentParser(
description='Local/Remote Time Converter'