Skip to content

Instantly share code, notes, and snippets.

View shimo164's full-sized avatar

shimo164

  • Osaka, Japan
View GitHub Profile
'''
Extract a file in a zip file, without opening the zip file
Parameters-------
file_to_get:
filename like 'test.txt' to get
zip_file:
target zip filename like 'zipfile.zip'
'''
Backup .py, .ipynb files to other dierctory (ex. USB device)
Parameters
---
dir_to_root: str
Directory path backup to, like '/media/user/USB_DISK/backup_here'
dir_from: str
All .py, .ipynb files in this directory are back-up(recursively).
@shimo164
shimo164 / elapsed_time.py
Last active September 7, 2018 13:57
Python snippet to get elapsed time
import time
start_time = time.time()
# write some code that you want to know time
elapsed_time = time.time() - start_time
print("elapsed time: {}".format(elapsed_time) + "[sec]")
@shimo164
shimo164 / devide_list_by_checking_items_manually.py
Created September 10, 2018 21:57
Python snippedt to devide list items checking manually one by one
'''
Manually see and evaluate Yes or No for each item in a list_test.
Checked results are devided to list_yes of list_no.
'''
# in ipython, to clear_output console
# from IPython.display import clear_output
def query_yes_no(question, default="yes"):
@shimo164
shimo164 / hello.py
Last active December 4, 2018 03:10
Simple web app
import os
import sqlite3
from flask import Blueprint, Flask, current_app, g, render_template, request
# manually set instance dir
app = Flask(__name__, instance_path='/home/../simple/instance')
app.config.from_mapping(
DATABASE=os.path.join(app.instance_path, 'simple.sqlite')
)
@shimo164
shimo164 / copy_swap_delete_form.html
Created January 8, 2019 20:56
copy, swap two forms, delete content of form
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
</head>
<body>
<script>
/*copy form id1 to id2*/
function copyForm(id1,id2){
var a=document.getElementById(id1);
@shimo164
shimo164 / add_form.html
Created January 11, 2019 13:27
By clicking button, a form is added
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<script>
function add()
@shimo164
shimo164 / simple_timer.py
Created March 18, 2019 10:17
Timer: wait until set_time
import datetime
import time
set_time = datetime.datetime(2019, 12, 31, 19, 0)
now_time = datetime.datetime.now()
delta = set_time - now_time
sec_in_day = (delta.total_seconds() - delta.days*24*60*60)
hours = int(sec_in_day // (60*60))
minutes = int((sec_in_day - hours*(60*60)) // 60)
seconds = int(sec_in_day - minutes*60 - hours*60*60)
@shimo164
shimo164 / resize_image_with_Python_PIL.py
Last active February 17, 2021 03:01
change file size, output size of image files
#!/usr/bin/python
"""Resize image simply with PIL
Usage:
$ python resize_image.py filename [mode]
Output:
"resize_ + filename" is created.
Parameters
import re
from io import StringIO
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from pdfminer.pdfinterp import PDFPageInterpreter, PDFResourceManager
from pdfminer.pdfpage import PDFPage
space = re.compile(r"[  ]+")