Skip to content

Instantly share code, notes, and snippets.

View seapy's full-sized avatar
๐Ÿ”ฅ

ChangHoon, Jung seapy

๐Ÿ”ฅ
View GitHub Profile

Rails Setting model

This is a semi-quick key/value store I put together for a quick way to store temporary data related to what's in my database, in a reliable way. For example, I'm using it to keep track of where a hourly and a daily crontask that processes statistics left off, so it can resume only processing and summarizing new data on the next run.

Code quality most likely is not great, but it works. And I will update this gist as I update my project.

How It Works

The settings table has two columns, a key and a value column. The value column is serialized, so you can technically store almost anything in there. Memcache is also used as a caching layer to minimize database calls.

@seapy
seapy / td-agent.conf
Last active August 29, 2015 14:00
/etc/td-agent/td-agent.conf ์˜ˆ์ œ(apache to elasticsearch)
###################################
## Input
<source>
type tail
format /^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<timestamp>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)" (?<response_time_micro_sec>[^ ]*))?$/
path /home/ubuntu/log_maker/tmp/log.access
pos_file /var/log/td-agent/apache.access.pos
tag apache.access
</source>
@seapy
seapy / .screenrc
Last active December 19, 2015 12:29
๋‚ด ์„œ๋ฒ„๋“ค์—์„œ ์‚ฌ์šฉํ•  screen ์„ค์ •. coursera ์˜ "Startup Engineering" ์— ๋‚˜์™”๋˜ ์˜ˆ์ œ๋ฅผ ์ˆ˜์ •. ์›๋ž˜ ์˜ˆ์ œ์—์„œ๋Š” emacs ์‚ฌ์šฉ์„ ์œ„ํ•ด ๋‹จ์ถ•ํ‚ค๋ฅผ ๋งŽ์ด ๋ฐ”๊ฟ”์น˜๊ธฐ ํ–ˆ์—ˆ์Œ ex 1) ์„œ๋ฒ„์— git์ด ์„ค์น˜๋˜์–ด ์žˆ์ง€ ์•Š์€๊ฒฝ์šฐ. https ๋Œ€์‹  http ์‚ฌ์šฉ curl -o .screenrc http://gist.github.com/seapy/xxxx/xxxx/.screenrc ex2) ์„œ๋ฒ„์— git์ด ์„ค์น˜๋˜์–ด ์žˆ๋Š” ๊ฒฝ์šฐ git clone https://gist.github.com/5955083.git dotfiles ln -s dotfiles/.screenrc .screenrc
# GNU Screen configuration file
# seapy <iamseapy@gmail.com>
#
# Notes
# -----
# 1. To change the colors of the hardstatus line, change this line:
# sorendition "+b +kG"
# Example: blue (+b) highlight with black text (k) on a green background (G)
# Example: sorendition "+r +kG" is red highlighting with black text on a green background
#
@seapy
seapy / jquery.ui.js
Last active December 18, 2015 00:49
jQuery UI ์—์„œ ์ œ๊ณตํ•˜๋Š” DatePicker ๋ฅผ ์‚ฌ์šฉํ• ๋•Œ ie 10 ๋ฏธ๋งŒ ๋ฒ„์ „์—์„œ๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ๋Š” ์ž˜ ์ž‘๋™ํ•˜์ง€๋งŒ ํŽ˜์ด์ง€๊ฐ€ ์Šคํฌ๋กค๋˜๋Š”๊ฒฝ์šฐ ์Šคํฌ๋กค๋œ ์ƒํƒœ์—์„œ DatePicker ๋ฅผ ํ‘œ์‹œํ• ๋•Œ ์ž˜๋ชป๋œ ์œ„์น˜๊ฐ€ ๋‚˜์˜ค๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค. ์ด๋Š” DatePicker ์˜ ๋ฌธ์ œ๋งŒ์€ ์•„๋‹ˆ๊ณ  jQuery UI ์ „์ฒด์ ์ธ ๋ฌธ์ œ์ธ๊ฒƒ ๊ฐ™๋‹ค. ์ด๊ฒŒ ์ผ๊ด„์ ์œผ๋กœ ์ ์šฉํ•˜๋ฉด ie10 ์—์„œ ์ž˜๋ชป๋œ ์œ„์น˜์— ๋‚˜์˜ค๊ธฐ ๋•Œ๋ฌธ์— ๋ธŒ๋ผ์šฐ์ € ๋ฒ„์ „ ์ฒดํฌ๊ฐ€ ํ•„์š”ํ•˜๋‹ค.
_showDatepicker: function(input) {
input = input.target || input;
if (input.nodeName.toLowerCase() !== "input") { // find from button/image trigger
input = $("input", input.parentNode)[0];
}
.......... ์ƒ๋žต
if (!$.datepicker._pos) { // position below input
$.datepicker._pos = $.datepicker._findPos(input);
$.datepicker._pos[1] += input.offsetHeight; // add the height
// patch start
@seapy
seapy / gist:5509333
Last active December 16, 2015 22:49
๋‚ด๊ฐ€ Mac ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ".profile" ์„ค์ •
# ํ„ฐ๋ฏธ๋„ ์ƒ‰ ์„ค์ •
export TERM="xterm-color"
export CLICOLOR=1
export LSCOLORS="gxfxcxdxbxegedabagacad"
# Alias ์„ค์ •
alias ll="ls -al"
# ๋งˆ์šฐ์Šค ์˜ค๋ฅธ์ชฝ์œผ๋กœ ๋‹ค๋ฅธํ”„๋กœ๊ทธ๋žจ ์—ด๊ธฐํ• ๋•Œ ์ค‘๋ณต์œผ๋กœ ์•ฑ์ด ๋‚˜์˜ค๋Š”๊ฑฐ ์ œ๊ฑฐํ•˜๋Š” ๋ฐฉ๋ฒ•
alias fixow='/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain user;killall Finder;echo "Open With has been rebuilt, Finder will relaunch"'
@seapy
seapy / post.rb
Created April 27, 2013 02:33
for Rails ActiveRecord Callbacks order check
class Post < ActiveRecord::Base
belongs_to :user
attr_accessible :body, :title
after_destroy :after_destroy
private
def after_destroy
puts "Post after_destroy"
end
@seapy
seapy / gist:2979190
Created June 23, 2012 17:40
Wordpress(MySQL) To Rails Blog(PostgreSQL) Migration Rake task edit
# encoding: UTF-8
require 'php_serialize'
# MySQL ์ ‘์† ์ •๋ณด๋ฅผ ๊ฐ€์ง€๋Š” ActiveRecord ํด๋ž˜์Šค ์ƒ์„ฑ
class SeapyBlog < ActiveRecord::Base
end
# ๊ธฐ์กด MySQL DB ์ ‘์† ์ •๋ณด ์„ค์ •
SeapyBlog.establish_connection(
:adapter => "mysql2",