Skip to content

Instantly share code, notes, and snippets.

View nakagami's full-sized avatar

Hajime Nakagami nakagami

View GitHub Profile
@nakagami
nakagami / pilview.py
Last active March 2, 2023 23:58
Image viewer by PIL and TK
#!/usr/bin/env python
##############################################################################
# Copyright (c) 2012 Hajime Nakagami<nakagami@gmail.com>
# All rights reserved.
# Licensed under the New BSD License
# (http://www.freebsd.org/copyright/freebsd-license.html)
#
# A image viewer. Require Pillow ( https://pypi.python.org/pypi/Pillow/ ).
##############################################################################
import PIL.Image
@nakagami
nakagami / detect_cmyk_jpeg.py
Created May 21, 2013 01:21
Walk and detect CMYK Jpeg, and print it's path name
#!/usr/bin/env python
"""
Detect CMYK Jpeg under current directory
use PIL (or Pillow)
"""
import os
from PIL import Image
START_PATH='.'
@nakagami
nakagami / simplest_mysql.go
Last active November 15, 2021 04:49
My first Go + mysql sample code. 1. go get github.com/go-sql-driver/mysql 2. mysql -e 'create database test_go;' 3. go run simplest_mysql.go
// Please crete database before go run this code
// ex) mysql -u root -e 'create database test_go;'
package main
import (
"os"
"fmt"
"database/sql"
_ "github.com/go-sql-driver/mysql"
)
@nakagami
nakagami / bytes_sample.go
Last active December 8, 2017 12:28
A sample code to use bytes package. Convert string and byte[], integer and bytes[]
package main
import (
"fmt"
"bytes"
"encoding/binary"
)
func int32_to_bytes(i32 int32) *bytes.Buffer {
bs := []byte {
@nakagami
nakagami / anytype_sample.go
Created September 11, 2013 02:04
A sample code, to use reflect and convert interface{} to original type.
package main
import (
"fmt"
"reflect"
)
type AnyType interface{}
func f(a AnyType) AnyType {
@nakagami
nakagami / list_sample.go
Created September 11, 2013 02:04
A sample code of "container/list".
// http://golang.org/pkg/container/list/
package main
import (
"fmt"
"container/list"
)
func main() {
l := list.New()
@nakagami
nakagami / time_parse.go
Created September 28, 2013 01:54
A sample code to parse time format string.
package main
import (
"fmt"
"time"
)
func main() {
var t time.Time
/*
sample.xml should be located in the default working directory
<foo>
<bar key="Key1" value="Value1" />
<bar key="Key2" value="Value2" />
</foo>
*/
package main
@nakagami
nakagami / test_aggregate_pg.py
Last active August 29, 2015 14:15
PostgreSQL 統計処理用の集約関数の python テストコード
# coding:utf-8
# PostgreSQL 統計処理用の集約関数 SQL:2006
# https://www.postgresql.jp/document/9.3/html/functions-aggregate.html
import unittest
import minipg
import decimal
values_with_null = [
(1, 1),
@nakagami
nakagami / test_stddev_fb.py
Created March 12, 2015 13:47
Test for STDDEV_POP(), STDDEV_SAMP(), VAR_POP() and VAR_SAMP() functions with Firebird3
# coding:utf-8
import unittest
import tempfile
import firebirdsql
class TestStdDev(unittest.TestCase):
host='localhost'
port=3050
user='sysdba'