Skip to content

Instantly share code, notes, and snippets.

View nakagami's full-sized avatar

Hajime Nakagami nakagami

View GitHub Profile
@nakagami
nakagami / etree_example.py
Last active March 13, 2024 06:26
XML manipuration example
import xml.etree.ElementTree as ET
xml_data = '''<?xml version="1.0" encoding="utf-8"?>
<root>
<person id="1">
<name>John Doe</name>
<age>30</age>
<city>Tokyo</city>
</person>
<person id="2">
@nakagami
nakagami / create_and_extract_zip.py
Last active February 28, 2024 06:56
Create and Extract zip file example
import io
import zipfile
# Create and extract zip file example
# to file
with zipfile.ZipFile("test.zip", 'w') as z:
z.writestr('aaa/bbb/1.txt', b'aaa')
z.writestr('aaa/ccc/2.txt', b'ccc')
z.writestr('aaa/ccc/3.bin', b'\x00\x01\x02')
@nakagami
nakagami / tkcanvas.py
Last active November 4, 2023 01:48
Example tkinter event and draw canvas
import tkinter
root = tkinter.Tk()
root.geometry("600x400")
canvas = tkinter.Canvas(root, width=600, height=400, bg="white")
canvas.pack()
def event_handler(event):
print(event)
if event.type == tkinter.EventType.ButtonRelease:
@nakagami
nakagami / tktwisted.py
Last active November 17, 2023 09:27
Python3 version of twisted tkinter support example tkinterdemo.py https://github.com/racker/python-twisted-core/blob/master/doc/examples/tkinterdemo.py
#!/usr/bin/env python
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
An example of using Twisted with Tkinter.
Displays a frame with buttons that responds to mouse clicks.
@nakagami
nakagami / app.py
Last active October 9, 2023 03:40 — forked from terasakisatoshi/app.py
Data visualization tool using Streamlit
import pathlib
from typing import List
from PIL import Image
import streamlit as st
from tensorflow import keras
@st.cache_data
def download() -> str:
@nakagami
nakagami / PyHackCon2023.rst
Last active June 18, 2023 04:22
私とPython と Python mini Hack-a-thon の思い出

私とPython と Python mini Hack-a-thon の思い出

Python mini Hack-a-thon Conference 2023-06-17 https://pyhack.connpass.com/event/282942/

100回を記念して、3年3ヶ月前に開催予定だった Python mini Hack-a-thon Conference での発表のために、 自分と Python と Python mini Hack-a-thon に関連した年表を作成した。

@nakagami
nakagami / fixup_metayaml.py
Created July 6, 2022 07:12
Pelican plugin that adjusts markdown YAML front matter.
# Pelican https://pypi.org/project/pelican/ plugin that adjusts markdown
# YAML front matter created by Netlify CMS https://www.netlifycms.org/ et al.
# to be handled correctly as metadata in pelican.
# This plugin requires PyYAML https://pypi.org/project/PyYAML/ .
import io
import datetime
import yaml
from pelican import signals
from markdown import Markdown
@nakagami
nakagami / get_adult_score.py
Created June 2, 2022 02:33
get adult score by Microsoft Computer Vision API
import sys
import os
import json
import http.client
from urllib.parse import urlencode
# Computer Vision API
# https://azure.microsoft.com/en-us/services/cognitive-services/computer-vision/
@nakagami
nakagami / gitssh.py
Last active December 15, 2022 12:00
Use paramiko to connect to git repository over ssh.
#!/usr/bin/env python
################################################################################
# MIT License
#
# Copyright (c) 2021 Hajime Nakagami
#
# 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
@nakagami
nakagami / pyawabi.ipynb
Created December 3, 2021 04:33
Install mecab, mecab-ipadic on SageMaker StudioLab. Tokenize by pure-pyawabi.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.