Skip to content

Instantly share code, notes, and snippets.


Kenji Noguchi knoguchi

View GitHub Profile
knoguchi / clickhousedump
Last active Mar 18, 2022 — forked from inkrement/clickhousedump
dump all clickhouse databases and tables
View clickhousedump
IGNORE_DBS="system information_schema INFORMATION_SCHEMA default tmp"
# supply options here as needed
$CLIENT -q "SHOW DATABASES" | while read -r db ; do
$CLIENT -q "SHOW TABLES FROM $db" | while read -r table ; do
knoguchi / qt.txt
Last active Aug 20, 2019
Minimal Qt5 devenv setup in Linux
View qt.txt
# 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 / singleton.go
Created Aug 19, 2019
thread safe initialization of singleton. Better alternative of init()
View singleton.go
var sharedInstance *single
var once sync.Once
func GetInstance() *single {
once.Do(func() {
// init code here
sharedInstance = &single{} // instantiate
return sharedInstance
knoguchi /
Created Jun 17, 2019 — forked from aparrish/
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 --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
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 / ViewController.swift
Created Jan 1, 2019
Built-in webcam access in macOS
View ViewController.swift
/* 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 /
Created Dec 4, 2018
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 /
Last active Dec 6, 2018
dynamic protobuf parsing
#include <unistd.h>
#include <iostream>
#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 = ch
self.hexid = hexid
package com.fasterxml.jackson.dataformat.protobuf.schema;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.dataformat.protobuf.ProtobufMapper;
import com.fasterxml.jackson.dataformat.protobuf.ProtobufTestBase;
public class DeserializeTest extends ProtobufTestBase