Skip to content

Instantly share code, notes, and snippets.

View nakagami's full-sized avatar

Hajime Nakagami nakagami

View GitHub Profile
@nakagami
nakagami / test_corr_fb.py
Created March 21, 2015 04:34
Test covar_samp(), covar_pip() and corr() functions with Firebird3
# coding:utf-8
import unittest
import tempfile
import firebirdsql
values_with_null = [
(1, 1),
(2, 2),
(3, 4),
@nakagami
nakagami / test_covar_samp_pg_and_fb.py
Created March 22, 2015 01:09
test COVAR_SAMP() by PostgreSQL and Firebird3
# coding:utf-8
import unittest
import tempfile
import minipg
import firebirdsql
class TestCovarSamp(unittest.TestCase):
def test_pg(self):
connection = minipg.connect(
@nakagami
nakagami / test_regr_fb.py
Created March 24, 2015 09:14
Test for REGR_XXXX() function with Firebird3
# coding:utf-8
import unittest
import tempfile
import firebirdsql
values_with_null = [
(1, 1),
(2, 2),
(3, 4),
/*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
@nakagami
nakagami / mqttpub.py
Created November 15, 2015 04:24
A sample of MQTT publisher (QoS=0)
#!/usr/bin/env python2.7
from __future__ import print_function
import datetime
import time
import paho.mqtt.client as mqtt # https://pypi.python.org/pypi/paho-mqtt/
topic = "foo/bar"
if __name__ == '__main__':
client = mqtt.Client(protocol=mqtt.MQTTv311)
@nakagami
nakagami / mqttsub.py
Created November 15, 2015 04:26
A sample of MQTT subscriber (QoS=0)
#!/usr/bin/env python2.7
from __future__ import print_function
import paho.mqtt.client as mqtt # https://pypi.python.org/pypi/paho-mqtt/
topic = "foo/bar"
def on_connect(client, userdata, flags, respons_code):
print('connect:status {0}'.format(respons_code))
client.subscribe(topic)
@nakagami
nakagami / test_rank.sql
Last active September 17, 2018 07:38
SQL functions RANK(), PERCENT_RANK(), CUME_DIST() and NTILE()
CREATE TABLE test_rank (
i integer,
s varchar(1)
);
INSERT INTO test_rank (i, s) VALUES (1, 'A');
INSERT INTO test_rank (i, s) VALUES (2, 'B');
INSERT INTO test_rank (i, s) VALUES (2, 'b');
INSERT INTO test_rank (i, s) VALUES (3, 'D');
INSERT INTO test_rank (i, s) VALUES (4, 'E');
@nakagami
nakagami / window_functions_example.sql
Last active July 2, 2016 07:45
SQL functions DENSE_RANK(), RANK(), PERCENT_RANK(), CUME_DIST(), NTILE(), ROW_NUMBER()
CREATE TABLE employee (
id integer,
department varchar(16),
salary decimal(4, 2)
);
INSERT INTO employee (id, department, salary) VALUES (1, 'R & D', 10.00);
INSERT INTO employee (id, department, salary) VALUES (2, 'SALES', 12.00);
INSERT INTO employee (id, department, salary) VALUES (3, 'SALES', 8.00);
INSERT INTO employee (id, department, salary) VALUES (4, 'R & D', 9.00);
@nakagami
nakagami / PyConJP2016.rst
Last active December 13, 2023 04:23
How to write python database driver (PyCon JP 2016 talk)
@nakagami
nakagami / ja_wikipedia_title_text.py
Last active December 29, 2016 12:27
Wikipedia の dump ファイルから、 page を切り出して title と text を抽出
!/usr/bin/env python3
"""
Wikipedia の dump ファイルから、 page を切り出して title と text を抽出
https://dumps.wikimedia.org/jawiki/ にある
https://dumps.wikimedia.org/jawiki/YYYYMMDD/jawiki-YYYYMMDD-pages-articles.xml.bz2 がデータソース
$ bzcat < jawiki-YYYYMMDD-pages-articles.xml.bz2 | ./ja_wikipedia_title_text.py
https://dumps.wikimedia.org/jawiki/latest/jawiki-latest-pages-articles.xml.bz2-rss.xml