Skip to content

Instantly share code, notes, and snippets.

View ssut's full-sized avatar

Suhun Han ssut

View GitHub Profile
@ssut
ssut / line.thrift
Created February 22, 2014 08:24
Naver LINE protocol interface file, functions as used by the desktop client.
// Naver LINE protocol interface file, functions as used by the desktop client.
namespace cpp line
// :%s/.*"\([^"]*\)", \d\+, \(\d\+\).*/\1 = \2;/
enum TalkExceptionCode {
ILLEGAL_ARGUMENT = 0;
AUTHENTICATION_FAILED = 1;
DB_FAILED = 2;
@ssut
ssut / base64.rb
Created March 14, 2014 19:37
Base64 impl written Ruby.
class String
def map
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
end
def encode64
self.bytes.to_a.map {|a|a.ord.to_s(2).rjust(8, '0')}.join.scan(/.{6}/).map {|a|map[a.to_i(2)]}.join
end
def decode64
self.split('').map {|a|map.index(a)}.map {|a|a.to_s(2).rjust(6,'0')}.join.scan(/.{8}/).map{|a|a.to_i(2).chr}.join
end
@ssut
ssut / benchmark.rb
Last active August 29, 2015 13:59
Ruby String Concatenation Performance Test ('<<' operator vs '+' operator vs interpolation) http://ssut-dev.tumblr.com/post/82675129445/ruby-string-concatenation-ruby-2-1-1
require 'benchmark'
N = 10_000
LENGTH = 100
STR1, STR2, STR3 = "a", "b" * LENGTH, "c"
puts "LENGTH: " << (STR1.size + STR2.size + STR3.size).to_s
Benchmark.bm(10) do |x|
x.report('"" < STR1 << STR2 << STR3') do
@ssut
ssut / benchmark.rb
Created April 15, 2014 13:57
Ruby Object Serialization Performance Test (Native vs OJ Library)
require 'benchmark'
require 'oj'
require 'json'
require 'ostruct'
N_OJ = 500_000
ex_HASH = { 'one' => 1, 'array' => [ true, false ] }
ex_JSON = '{ "one": 1, "array": [ true, false ] }'
@ssut
ssut / puma.rb
Created April 22, 2014 16:07
puma on_worker_boot
on_worker_boot do
request_thread_count = Puma.cli_config.options[:max_threads]
Sidekiq.configure_client do |cfg|
cfg.redis = ConnectionPool.new(:size => 10, :timeout => 3) { Redis.connect }
end
cmdline = `cat /proc/#{$$}/cmdline`
# compress assets
# reference: app.rb - L:97
if Puma.cli_config.options[:environment] == 'production' and cmdline.include? 'worker 0'
@ssut
ssut / lib.rsa.php
Created May 7, 2014 02:30
RSA Encrypt & Decrypt library
<?php
/**
* RSA Encrypt & Decrypt library
*
* Original algorithm is orginated by Ron Rivest, Adi Shamir and Leonard Adleman.
* Produce PHP Code by Hx0A5F.
**/
class RSA {
private $publicKey = 0;
@ssut
ssut / benchmark.py
Last active August 24, 2019 08:54
Python decorator endpoint implementation (like Flask blueprint module) - O(1)
#-*- coding: utf-8 -*-
import time
from collections import namedtuple
from test import ep as app
BenchResult = namedtuple('BenchResult', ['str', 'time'])
def benchmark(str, times=100000):
t_start = time.time()
for i in range(times):
@ssut
ssut / river_status.py
Created June 5, 2014 14:43
Get South Korea river status from koreawqi.go.kr
#-*- coding: utf-8 -*-
import contextlib
import re
import urllib
from bs4 import BeautifulSoup
from datetime import datetime
from textwrap import dedent as trim
now = lambda: datetime.now().strftime("%Y%m%d%H")
@ssut
ssut / check_pep8.py
Last active August 29, 2015 14:02
python pep8 style guide checker -- http://legacy.python.org/dev/peps/pep-0008/
#!/usr/bin/env python
import os
import sys
import pep8
class Writer:
def __init__(self, exclude=[], stdout=None):
self.content = []
self.exclude = exclude
@ssut
ssut / attachment.php
Last active August 2, 2019 09:07 — forked from kijin/attachment.php
UTF-8 file download function, support remote file passing(proxy) with http range header
<?php
/**
* PHP File download function.
* Version 1.4
*
* Copyright (c) 2014 성기진 Kijin Sung
* Modified by ssut
*
* License: MIT License (a.k.a. X11 License)