Skip to content

Instantly share code, notes, and snippets.

View knoguchi's full-sized avatar

Kenji Noguchi knoguchi

View GitHub Profile
@knoguchi
knoguchi / gist:87874fe905cbe3a2a5f01504b924159a
Last active May 13, 2023 00:55
users and roles using bitmap
DROP TABLE IF EXISTS bm_roles;
DROP TABLE IF EXISTS bm_users;
DROP TABLE IF EXISTS bm_data;
CREATE TABLE bm_roles (
name String,
roles AggregateFunction(groupBitmap, UInt64)
) ENGINE=Memory;
CREATE TABLE bm_users (
@knoguchi
knoguchi / clickhousedump
Last active March 18, 2022 22:02 — forked from inkrement/clickhousedump
dump all clickhouse databases and tables
#!/bin/bash
OUTDIR=.
IGNORE_DBS="system information_schema INFORMATION_SCHEMA default tmp"
# supply options here as needed
CLIENT="clickhouse-client"
$CLIENT -q "SHOW DATABASES" | while read -r db ; do
$CLIENT -q "SHOW TABLES FROM $db" | while read -r table ; do
@knoguchi
knoguchi / qt.txt
Last active August 20, 2019 22:30
Minimal Qt5 devenv setup in Linux
# TODO: find the minimal package.
apt install qt5-default qtcreator
# Steps to create Qt app.
# 1. create main.cpp
# 2. create .pro file
# 3. create Makefile from .pro file
# 4. run make
@knoguchi
knoguchi / singleton.go
Created August 19, 2019 15:35
thread safe initialization of singleton. Better alternative of init()
var sharedInstance *single
var once sync.Once
func GetInstance() *single {
once.Do(func() {
// init code here
sharedInstance = &single{} // instantiate
})
return sharedInstance
}
@knoguchi
knoguchi / fitbit_auth_example.py
Created June 17, 2019 02:07 — forked from aparrish/fitbit_auth_example.py
A simple Tornado application that implements OAuth login and authenticated requests for Fitbit.
# simple tornado app that implements fitbit oauth login.
# requires tornado 2.4-ish. run on the command line like so:
# $ python fitbit_auth_example.py --port=<your port> \
# --fitbit_consumer_key=<your consumer key> \
# --fitbit_consumer_secret=<your consumer secret>
#
# make sure to set your fitbit app's callback URL to
# http://your-app-url.example.com/login
import tornado.web
import functools
import operator
from sqlalchemy import func, column, select, text, between
from sqlalchemy.schema import *
from sqlalchemy.sql import sqltypes
from sqlalchemy.sql.functions import GenericFunction
class hyperunique(GenericFunction):
@knoguchi
knoguchi / ViewController.swift
Created January 1, 2019 03:12
Built-in webcam access in macOS
/* Tested in macOS Mojave (Dec 31, 2018) using Xcode 10.1
* 1. Create a new Xcode project
* 2. Select macOS
* 3. Pick Cocoa App, give it a name, create
* 4. Open the project setting, click "Capabilities", goto "App Sandbox" -> "Hardware" -> check "Camera"
* 5. Open Info.plist of the project, and add row "Privacy - Camera Usage Description", give it some description
* 6. Open ViewController, and paste the code below
* 7. Click Play icon, give Cam access permissson "OK"
* 8. Voila! Preview screen!
*/
@knoguchi
knoguchi / ex1.py
Created December 4, 2018 06:16
Food for thought: can we access MongoDB like LINQ?
from functional import seq
from pymongo import MongoClient
class dotdict(dict):
"""dot.notation access to dictionary attributes"""
__getattr__ = dict.get
__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__
client = MongoClient('mongodb://localhost:27017/')
@knoguchi
knoguchi / main.cc
Last active December 6, 2018 21:55
dynamic protobuf parsing
#include <unistd.h>
#include <iostream>
#define BOOST_FILESYSTEM_NO_DEPRECATED
#define BOOST_FILESYSTEM_VERSION 3
#include <boost/filesystem.hpp>
#include <google/protobuf/compiler/importer.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/dynamic_message.h>
import re
import argparse
from collections import namedtuple
class Record:
def __init__(self, crtime=0.00000, ch=1, hexid=0x000, dir="Rx", stat="d", data=None, length=0, bitcount=0, decid=0):
self.crtime = crtime
self.ch = ch
self.hexid = hexid