Skip to content

Instantly share code, notes, and snippets.

View namoshizun's full-sized avatar
👋

Di Lu namoshizun

👋
View GitHub Profile
import time
import random
from elasticapm import Client, instrument
from elasticapm.base import get_client as get_apm_client
from elasticapm.contrib.celery import register_exception_tracking, register_instrumentation
from elasticapm.traces import execution_context
from celery import Celery
from celery.canvas import group
[
{
"database": "load_planner",
"index": "saas-base",
"nodes": {
"table": "saas_api_user",
"schema": "public",
"columns": [],
"transform": {
"rename": {
---
apiVersion: v1
kind: ConfigMap
metadata:
name: metricbeat-daemonset-modules
namespace: kube-system
labels:
k8s-app: metricbeat
data:
system.yml: |-
import React from 'react';
import { useState, useEffect } from 'react'
function App() {
const [count, setCount] = useState(0)
// Should print the latest count a render happens
console.log(count)
useEffect(() => {
console.log('In effect')
@namoshizun
namoshizun / heatmaply_click_workaround.R
Created September 26, 2018 06:38
Use plotly's default source name to capture click event on heatmaply
library(heatmaply)
library(shiny)
library(plotly)
ui <- fluidPage(
titlePanel("Old Faithful Geyser Data"),
mainPanel(
plotlyOutput(outputId = 'heatmap')
)
@namoshizun
namoshizun / test.py
Created June 11, 2018 10:56
[Python + FFMPEG] change video speed without affecting pitch and/or concatenate multiple clips
from vid_utils import Video, concatenate_videos
videos = [
Video(speed=1.0, path="C:/temp/my_video_1.mp4"),
Video(speed=2.0, path="C:/temp/my_video_2.mp4"),
Video(speed=0.5, path="C:/temp/my_video_3.mp4"),
]
concatenate_videos(videos=videos, output_file=f"C:/temp/output_video.mp4")
@namoshizun
namoshizun / print_progress.py
Last active May 30, 2018 04:26
Python decorator for printing function progresses
import functools
import inspect
from tqdm import tqdm
def print_progress(total=None, enabled=True):
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
if not enabled or total is None:
# Install GPFlow
!git clone https://github.com/namoshizun/GPflow.git
!mv ./GPflow/gpflow ./
!rm -rf GPflow
!pip install multipledispatch
!pip install pytest
# Install Other libraries
!pip install edward
@namoshizun
namoshizun / regret_matching.py
Created July 14, 2017 01:03
Use regret matching to play rock-paper-scissors
from __future__ import division
from random import random
import numpy as np
import pandas as pd
'''
Use regret-matching algorithm to play Scissors-Rock-Paper.
'''
class RPS:
@namoshizun
namoshizun / naive_gp.py
Created July 8, 2017 00:16
simple gaussian process
"""
Implement a very simple gaussian process for regression task.
Credit : http://katbailey.github.io/post/gaussian-processes-for-dummies/
"""
import numpy as np
import matplotlib.pyplot as pl
def prepare_data(n, fn):