Skip to content

Instantly share code, notes, and snippets.

@jkw552403
jkw552403 / calendar_toString
Created November 5, 2014 07:53
Android Calendar to String or String to Calendar
SimpleDateFormat calendarFormatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);
Calendar now = Calendar.getInstance();
String strFromCal = calendarFormatter.format(now);
Calendar calFromStr = Calendar.getInstance();
try {
calFromStr.setTime(calendarFormatter.parse(strFromCal));
} catch (ParseException e) {
e.printStackTrace();
}
import sys
import unicodedata
table = {c: ' ' for c in range(sys.maxunicode)
if unicodedata.category(chr(c)).startswith('P')}
def remove_puntuation(s):
return s.translate(table)
# -*- coding: utf-8 -*-
import sys
import unicodedata
table = {c: u' ' for c in range(sys.maxunicode)
if unicodedata.category(unichr(c)).startswith('P')}
def remove_punctuation(s):
return s.translate(table)
import re
sent = 'a b c b c c A B C B C C'
match = re.search('\w+', sent)
while match:
word = match.group()
sent, count = re.subn(word, '', sent, flags=re.I)
match = re.search('\w+', sent)
print(word, count)
@jkw552403
jkw552403 / main.py
Last active June 6, 2018 03:37
python main script with click
import click
@click.command()
def main():
pass
if __name__ == "__main__":
main()
@jkw552403
jkw552403 / subplot
Created August 17, 2018 03:02
subplot
fig, ax = plt.subplots(nrows, ncols, figsize=(8, 8))
@jkw552403
jkw552403 / wordcloud
Created August 17, 2018 03:03
wordcloud #Python #viz
wc = WordCloud(background_color="white", max_words=1000,
stopwords=STOPWORDS,width=1000,height=1000)
wc.generate(texts with space)
plt.imshow(wc)
plt.show()
@jkw552403
jkw552403 / figure
Last active August 17, 2018 03:03
Single plt plot #viz
plt.figure(figsize=(8, 8))
plt.show()
@jkw552403
jkw552403 / interactivity
Created November 7, 2018 05:41
[Notebook Interactivity] Show all outputs in a notebook cell #Python #Notebook
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all"
@jkw552403
jkw552403 / cli_share_options.py
Created March 25, 2019 08:33
click share options #python #click
def common_params(func):
@click.option('--foo')
@click.option('--bar')
@functools.wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
return wrapper
@click.command()