Skip to content

Instantly share code, notes, and snippets.

View ishidama's full-sized avatar

ishidama ishidama

View GitHub Profile
@ishidama
ishidama / gist:e417198a19e6c318d84a7d7f4ed23ee0
Created May 20, 2025 07:57
CoreMLモデルに変換したRealESRGANを読みこんで画像変換が成功したコード
import Foundation
import CoreML
import AppKit
//let kCVPixelFormatType_32Float: OSType = 0x0000001E // kCVPixelFormatType_32BGRA
let modelInputKey = "input_image"
var modelOutputKey = "output_image" // デフォルト。printで自動検出
guard CommandLine.arguments.count >= 3 else {
print("Usage: RealESRGANApp input.png output.png")
@ishidama
ishidama / gist:425a7e5bb0f2ccca51d4b108dba8c8a7
Created June 20, 2024 00:57
カレントにあるmkvファイルと同名のフォルダを作成し、そこにファイルを移動する。Plexの動画ライブラリ用
#!/bin/bash
# カレントディレクトリのすべての .mkv ファイルをループ
for file in *.mkv; do
# 拡張子を除いたファイル名を取得
# ${file%.*} は、ファイル名から最後のドット以降を削除します(例:example.mkv -> example)
dirname="${file%.*}"
# ファイル名と同じ名前のディレクトリを作成
# -p オプションは、すでにディレクトリが存在する場合にエラーを抑制します
@ishidama
ishidama / gist:6462c255fe20cef0f2860846d89aca8c
Last active June 23, 2021 01:32
与えられたListを、要素がn個ずつ格納されたListに変換する
def split_list(list, n):
if not list:
return []
return [list[:n]] + split_list(list[n:], n)
@ishidama
ishidama / gist:8329a36f98de7a0be8676a017b275c07
Created May 22, 2017 08:22
Python による 木構造の再帰定義による実装
#https://sites.google.com/site/hoseifujii/news/pythonniyorumugouzaonozaiguidingyiniyorushizhuang
import random as r
namelist=['apple','grape','orange','lemon','banana']
class node:
def __init__(self, name, children):
self.name = name # String
self.children = children # List of Class node
MyClass = type(
'MyClass',
(object),
{
'__init__': lambda self, val: setattr(self, '_val', val),
'say': lambda self: self._val,
},
)
@ishidama
ishidama / gist:16401625e4630b0ae65defd20347d376
Created September 7, 2016 08:45
Python】Pythonでシングルトンを実装する方法
#http://a-zumi.net/python-singleton/
class Singleton(object):
__instance = None
# __new__は__init__の前に実行されるのでここでインスタンスが生成されているか確認する
def __new__(cls, *args, **kwargs):
if cls.__instance is None:
cls.__instance = object.__new__(cls)
return cls.__instance
'http://qiita.com/ktyubeshi/items/74228f18498224c7427d
Option Explicit
Public Function REGEXP(文字列 As String, 正規表現文字列 As String, Optional SubMatchIndex As Integer = -1)
'Dim RE As VBScript_RegExp_55.REGEXP
'Dim ReMatch As MatchCollection
'Dim M As Match
# http://kimihiro-n.appspot.com/show/5814395191951360
import csv
import json
result = []
with open('hoge.csv') as f:
for line in csv.DictReader(f):
line_json = json.dumps(line)
result.append(line_json)
# coding: utf-8
# http://kimihiro-n.appspot.com/show/5814395191951360
import csv, json
print([json.dumps(l) for l in csv.DictReader(open('hoge.csv'))])
@ishidama
ishidama / csv_dict_sample.py
Created July 1, 2014 06:42
csvファイル読取でヘッダ名でデータアクセスする場合
# coding=utf-8
import csv
template = 'Person(name=u"%(姓名)s", birthday="%(生年月日)s", sex=u"%(性別)s").save()'
data = csv.reader(open('data.csv'))
# ヘッダー行を飛ばす
header = data.next()