Skip to content

Instantly share code, notes, and snippets.

View ssut's full-sized avatar

Suhun Han ssut

View GitHub Profile
@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 / 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 / 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 / raggedness.py
Last active August 29, 2015 14:04
very weird raggedness word-wrap implementation written in Python
# -*- coding: utf-8 -*-
from sys import argv, exit
cac = []
res = []
words = []
M = 0
for x in range(1000):
cac.append([-1 for j in range(1000)])
@ssut
ssut / Code.gs
Last active August 29, 2015 14:06
get exchange rate from wooribank
function getDate(decrease) {
var date = new Date();
if(decrease && decrease > 0) {
date = new Date(date);
date.setDate(date.getDate() - decrease);
}
var yyyy = date.getFullYear().toString(),
dd = date.getDate().toString(),
mm = (date.getMonth() + 1).toString();
#!/bin/bash
NAME=$1
FROM=$2
PIDFILE=".$1.pid"
DIR=$(pwd)
PERIOD=${3:-7}
PRIORITY=${4:-10}
FILENAME="$(date +%Y-%m-%d_%H%M).tar.gz"
BACKUPDIR="$DIR/backups/$NAME"
@ssut
ssut / skydrivedl.php
Last active December 16, 2015 05:09
SkyDrive direct download.. (Original: http://corpuscollectum.wordpress.com/2011/07/12/skydrive-direct-download-link-hotlink/, Procedure-Oriented)
<?php
ini_set('display_error', 1);
error_reporting(E_ALL & ~E_NOTICE);
class skyDriveDL {
// Location
private $loc;
// File
private $file;
@ssut
ssut / clien.css
Created December 16, 2015 17:13
clien transformer
/* layout
-------------------------------------*/
body {
margin: 0 3.5%;
padding: 0;
font-family: 'NanumGothic';
}
p, h2, tr, td, td a, select {
font-family: 'NanumGothic'!important;