Skip to content

Instantly share code, notes, and snippets.

Avatar

Kenji Noguchi knoguchi

View GitHub Profile
@knoguchi
knoguchi / clickhousedump
Last active Mar 18, 2022 — forked from inkrement/clickhousedump
dump all clickhouse databases and tables
View clickhousedump
#!/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 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
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
knoguchi / fitbit_auth_example.py
Created Jun 17, 2019 — forked from aparrish/fitbit_auth_example.py
A simple Tornado application that implements OAuth login and authenticated requests for Fitbit.
View fitbit_auth_example.py
# 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
View sql.py
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 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
knoguchi / ex1.py
Created Dec 4, 2018
Food for thought: can we access MongoDB like LINQ?
View ex1.py
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 Dec 6, 2018
dynamic protobuf parsing
View main.cc
#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>
View canlogfilter.py
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
View DeserializeTest.java
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;
import java.io.IOException;
import java.io.InputStream;
public class DeserializeTest extends ProtobufTestBase