Skip to content

Instantly share code, notes, and snippets.

View whchi's full-sized avatar
:octocat:

whchi whchi

:octocat:
View GitHub Profile
@whchi
whchi / gist.html
Created December 29, 2018 10:30
hugo shortcodes gist
<script type="text/javascript" src="http://gist.github.com/{{ .Get 0 }}.js"></script>
{
"mappings": {
"properties": {
"field1": {
"analyzer": "ik_syno_max",
"search_analyzer": "ik_syno_smart",
"type": "text"
},
"field2": {
"analyzer": "ik_syno_max",
@whchi
whchi / gist:2c10a0cc8e20fcd3ac4b8cc210347239
Created April 30, 2020 15:59
synonym success example
// request
{
"text": "流行性感冒",
"analyzer": "ik_syno_max"
}
// response
{
"tokens": [
{
"token": "流感",
{
"mappings": {
"properties" : {
"completion_field" : {
"type" : "search_as_you_type",
"analyzer": "ik_max_word"
}
}
}
}
// request 1
{
"completion_field": "甲狀腺腫大"
}
// request 2
{
"completion_field": "甲狀腺凸眼症"
}
...
// request
{
"_source": ["completion_field"],
"query": {
"multi_match": {
"query": "甲狀",
"type": "best_fields", // 按照有對應到的順序計算
"fields": [
"completion_field"
]
@whchi
whchi / apache_beam.py
Last active June 12, 2020 06:22
avro to hbase via google cloud dataflow with apache beam
import os
import apache_beam as beam
from apache_beam.io.avroio import ReadFromAvro
from apache_beam.options.pipeline_options import (PipelineOptions,
GoogleCloudOptions,
StandardOptions, SetupOptions,
WorkerOptions)
from apache_beam.runners.runner import PipelineState
import happybase
from apache_beam.metrics import Metrics
<?php
if (!function_exists('jsonEncode')) {
function jsonEncode($payload, int $options = 0, int $depth = 512): string
{
$defaultOptions = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE;
$options = 0 !== $options ? $options : $defaultOptions;
$json = \json_encode($payload, $options, $depth);
@whchi
whchi / detect-getUserMedia.js
Created August 20, 2020 16:30
檢查瀏覽器是否支援 getUserMedia API
if (/rv:11|MSIE|Trident|firefox/i.test(navigator.userAgent)) {
notSupport = !navigator.mediaDevices || !navigator.getUserMedia
} else {
notSupport = !navigator.mediaDevices.getUserMedia
}
if (notSupport) {
alert('getUserMedia not support on your browser')
return
}
if (!navigator.mediaDevices.getUserMedia) {
@whchi
whchi / send_mail.py
Created November 4, 2020 08:26
多執行緒發送 email
# encoding=utf-8
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import threading
import codecs
import logging
import time
from email.header import Header
from email.utils import formataddr