Skip to content

Instantly share code, notes, and snippets.

View dtaniwaki's full-sized avatar

Daisuke Taniwaki dtaniwaki

View GitHub Profile
import collections
import functools
import logging
from typing import Any, Callable, Iterable, Union
from google.protobuf.message import Message
from grpc import HandlerCallDetails, RpcMethodHandler, ServerInterceptor, ServicerContext, StatusCode
from grpc.experimental import wrap_server_method_handler
from validator import ValidationFailed, validate
package main
import (
"context"
"testing"
"time"
"github.com/ghodss/yaml"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
# Example workflow to demonstrate parameter aggregation.
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
name: parameter-aggregation-template
spec:
templates:
# odd-or-even accepts a number and returns whether or not that number is odd or even
- name: odd-or-even
inputs:
@dtaniwaki
dtaniwaki / jupyterhub_config.py
Last active February 12, 2018 09:25
Resources page for UCRSpawner
c = get_config()
from jupyterhub import handlers
handlers.default_handlers.extend([
(r"/resources", ResourcesHandler),
])
module ConfidenceSearch
class << self
def search(start_num, end_num, &block)
(start_num..end_num).to_a.reverse.find { |n| block.call(n) }
end
def bin_ex_search(start_num, end_num, try_num: 1, last_num: nil, window: 1, &block)
return nil unless block.call(start_num)
num = try_num.times.find { |n| block.call(end_num - n + 1) }
@dtaniwaki
dtaniwaki / slice.c
Last active February 29, 2016 09:36
A slice function at codility
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <time.h>
#define ARRAY_SIZE 10000
#define MAX 100
int solution1(int A[], int N) {
int total = 0;
@dtaniwaki
dtaniwaki / 20160225213213_logical_delete_users.rb
Created February 25, 2016 22:12
Unique constraint with logical delete
class LogicalDeleteUsers < ActiveRecord::Migration
def up
add_column :users, :logical_uniqueness, :boolean, default: true
remove_index :users, :name
add_index :users, [:name, :logical_uniqueness], unique: true
execute <<-SQL
CREATE TRIGGER `set_logical_uniqueness_on_users` BEFORE UPDATE ON `users`
FOR EACH ROW
BEGIN
IF NEW.`deleted_at` IS NULL THEN
@dtaniwaki
dtaniwaki / main.rb
Last active February 8, 2016 09:51
ActiveRecordでSlowQueryを通知する方法 ref: http://qiita.com/dtaniwaki/items/2acf9e7f54eec05d48f3
# Detect slow query slower than 1000 msec
Ext::ActiveRecord::SlowQuerySubscriber.load!(1000)
@dtaniwaki
dtaniwaki / main.js
Last active February 8, 2016 03:30
Get result of functions run in window context
import * as windowContextRunner from './windowContextRunner.js'
windowContextRunner.run(function() {
// Do something and return the result
var result = 1;
return result;
}).then(function(result) {
// Use the result of the function above
result == 1
});
@dtaniwaki
dtaniwaki / file0.scala
Created December 12, 2015 10:59
Akkaによるbatch request作り方 ref: http://qiita.com/dtaniwaki/items/fc11b503ce0e27e52516
case class BatchTriggerTick()