Skip to content

Instantly share code, notes, and snippets.

@tky
tky / consumer.py
Created September 27, 2019 04:38
consuming kinesis data stream
import boto3
from boto3.session import Session
import json
from datetime import datetime
import base64
import gzip
import io
import time
my_stream_name = 'kinesis-stream-name'
FROM centos:centos7.1.1503
MAINTAINER tky
RUN yum swap -y fakesystemd systemd
RUN rpm --rebuilddb; yum install -y httpd
RUN echo "Hello apache" > /var/www/html/index.html
RUN systemctl enable httpd
EXPOSE 80
@tky
tky / ltsv filter
Last active October 19, 2015 07:57
filter ltsv value with specified field.
awk -v inputs="$1" -F'\t' '
function join(array, start, end, sep, result, i)
{
if (sep == "")
sep = " "
else if (sep == SUBSEP) # magic value
sep = ""
result = array[start]
for (i = start + 1; i <= end; i++)
result = result sep array[i]
import System.Random
data Hand = Goo | Choki | Pa deriving (Show, Eq, Read)
data Result = Win | Lose | Draw deriving (Show, Eq)
data Record = Record { win :: Int, lose ::Int } deriving (Show)
record :: Record -> Result -> Record
record hs Win = Record { win = win hs + 1, lose = lose hs }
record hs Lose = Record { win = win hs , lose = lose hs + 1 }
@tky
tky / hoi
Last active August 29, 2015 14:08
use std::rand::Rng;
use std::rand;
use std::io;
#[deriving(PartialEq)]
enum Arrow {
RIGHT, LEFT, TOP, BOTTOM
}
impl Arrow {
!/bin/sh
#$ cat tmp.ltsv
#a:1 b:2
#a:2 b:3 c:4
#$ cat tmp.ltsv | ./filter.sh a
#1
#2
awk -v target="$1" -F'\t' '{
for (i = 1; i <= NF; i++) {
pos = index($i, ":")
@tky
tky / gist:8578331
Last active January 4, 2016 05:58
post ltsv.file to elasticsearch. This script read ltsv file and convert json, and post elasticsearch. use go run main.go filename.ltsv
package main
import (
"encoding/json"
"os"
"bufio"
"strings"
"container/list"
"fmt"
"net/http"
@tky
tky / ltsv_awk
Created January 22, 2014 12:42
shell which convert ltsv to json.
#!/bin/sh
FILE=$1
cat $FILE | awk -F"\t" '{
printf("{")
for (i = 1; i <= NF; i++) {
pos = index($i, ":")
key = substr($i, 0, pos - 1)
value = substr($i, pos + 1, length($i))
if (value ~ /[0-9]/) {
@tky
tky / ltsv
Last active January 4, 2016 02:49
LTSV to json parser. this script parse ltsv file to json string.
package main
// $cat tmp.ltsv
// a:1 b:2
// a:2 b:3 c:v
// $go run ltsv.go tmp.ltsv
// {"a":1,"b":2}
// {"a":2,"b":3, "c":"v"}
import (
"encoding/json"
@tky
tky / scala.snippets
Created November 8, 2012 09:46
snippets file for scala
############################
##playframework
#
#play controller
snippet playcon
package ${1:package}
import play.api._
import play.api.mvc._
import play.api.data._