Skip to content

Instantly share code, notes, and snippets.

View ssut's full-sized avatar

Suhun Han ssut

View GitHub Profile
@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 / 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 / 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 / sidekiq
Created December 17, 2013 01:15
Starts and stops "sidekiq" message processor for padrino application. Requirement: rbenv, padrino, sidekiq and https://gist.github.com/passcod/3754086 /etc/init.d/sidekiq
#!/bin/sh
### BEGIN INIT INFO
## END INIT INFO
# You will need to modify these..
APP="app_name"
APP_DIR="/var/www/${APP}"
CONFIG_FILE="${APP_DIR}/config/sidekiq.yml"
REQUIRE="${APP_DIR}/config/workers.rb"
PID_FILE="${APP_DIR}/tmp/sidekiq.pid"
@ssut
ssut / douhao.js
Created November 17, 2013 09:26 — forked from darkfe/douhao.js
'3423112'.replace(/\d(?=(?:\d{3})+$)/g,'$&,')
"3,423,112"
'3423112'.replace(/(?!^)(?=(?:\d{3})+$)/g,',')
"3,423,112"
@ssut
ssut / qs.js
Created November 16, 2013 16:13
Query string access in javascript
function setGetParam() {
var url = arguments[2] || location.href;
if (arguments[0] instanceof Object) { // hash object
for(var arg in arguments[0]) {
if (!arg || !arguments[0][arg]) continue;
url = setGetParam(arg, arguments[0][arg], url);
}
} else if (typeof arguments[0] === 'string' && arguments[1]) {
paramName = arguments[0];
@ssut
ssut / findrepl.rb
Last active December 25, 2015 08:48
Simple ruby script: find string in multiple files and replace.
#!/usr/bin/env ruby
#
# First: Filename (*.html, *.rb, *.py and etc)
# Second: Find
# Third: Replacement
$pwd = Dir.pwd
$args = []
ARGV.each { |arg| $args.push(arg) }
if $args.size < 3
@ssut
ssut / Custom.css
Last active December 23, 2015 04:19 — forked from netj/Custom.css
/*
* 정확히 AppleGothic만 다른 글꼴로 바꾸는 사용자 스타일 시트
*
* 애플고딕을 쓰도록 명시적으로 지정한 사이트에서도 원하는 글꼴로 바꿀 수 있게 해주는 방법이며,
* 영문 글꼴이나 다른 한글 글꼴까지 몽땅 하나로 통일해서 써야 했던 font-family를 강제로 지정하는 방식과는 달리
* 정확히 애플고딕만 다른 글꼴로 바꿔서 사용하는 매우 깔끔한 방법입니다. :)
*
* 사용 방법:
* Safari는 아무 곳에나 저장해두고 환경설정 > 고급 > 스타일 시트에서 파일 선택
* Google Chrome은 ~/Library/Application Support/Google/Chrome/Default/User StyleSheets/Custom.css
@ssut
ssut / folder_scan.php
Created September 10, 2013 12:37
PHP Folder scan function.
<?php
function find_entry($dir, $orign_dir='') {
if(!is_dir($dir)) return null;
$d = dir($dir);
$result = "";
while($entry = $d->read()) {
if($entry != "." && $entry != "..") {
if(is_dir($dir . "/" . $entry)) {
@ssut
ssut / django-minify-middleware.py
Created September 5, 2013 22:57
Django html minify middleware.
#-*- coding: utf-8 -*-
import re
class MinifyMiddleware(object):
spaces = re.compile(r'^\s+', re.MULTILINE)
comments = re.compile(r'(\<!--\s*.*?((--\>)|$))', re.MULTILINE)
blank_attrs = re.compile(r'(\s\w+\=[\'|"]{2})', re.MULTILINE)
tag_types = re.compile(r'(\stype\=[\'|"]text\/\w+[\'|"])', re.MULTILINE)
def process_response(self, request, response):