Skip to content

Instantly share code, notes, and snippets.

Constantine Kim elegantcoder

View GitHub Profile
View PojoFactoryWithDI.java
import org.springframework.stereotype.Component;
@Component
class AFactory {
private AComponent aComponent;
private BComponent bComponent;
View sidekiq.py
from redis import Redis
import simplejson
import os
class Sidekiq(object):
"""Dirt simple Sidekiq client in Python. Can be used to create jobs."""
def __init__(self):
host = os.environ['SIDEKIQ_REDIS_HOST']
port = os.environ['SIDEKIQ_REDIS_PORT']
db = os.environ['SIDEKIQ_REDIS_DB']
@elegantcoder
elegantcoder / korean_marker.rb
Last active Feb 16, 2019
한글 은/는, 이/가 (Powered by ActiveSupport::Multibyte::Chars)
View korean_marker.rb
# require 'active_support/all'
def korean_topic_marker(str)
k = str[-1] # last one char
return '는' if k.mb_chars.decompose.size < 3 # 종성이 없는 경우
return '은'
end
def korean_subject_marker(str)
k = str[-1] # last one char
@elegantcoder
elegantcoder / extract_korean_initials.rb
Last active Jul 22, 2018
한글 초성 분리기
View extract_korean_initials.rb
# 삼성전자 => ㅅㅅㅈㅈ, 유안타제3호스팩 => ㅇㅇㅌㅈ3ㅎㅅㅍ
def extract_korean_initials(keyword)
initials = ['ㄱ', 'ㄲ', 'ㄴ', 'ㄷ', 'ㄸ', 'ㄹ', 'ㅁ', 'ㅂ', 'ㅃ', 'ㅅ', 'ㅆ', 'ㅇ', 'ㅈ', 'ㅉ', 'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ']
# hangul_range = '가'..'힣'
hangul_first = 44032 # '가'.ord
size = 588 # '까'.ord - '가'.ord
keyword.split('').collect do |k|
View korean key bindings.sh
#!/bin/sh
mkdir -p ~/Library/KeyBindings
echo '{
"₩" = ("insertText:", "`");
}' > ~/Library/KeyBindings/DefaultkeyBinding.dict
@elegantcoder
elegantcoder / active_record_2_yaml.rb
Created Sep 16, 2016
for generating Rails test fixture
View active_record_2_yaml.rb
require 'yaml'
def active_record_2_yaml(active_record)
hash = Array.wrap(active_record).as_json.reduce({}) {|memo, item|
memo["id_#{item['id']}"] = item
memo
}
hash.to_yaml
end
View cordova-deviceready-angular-$q.js
/*cordova-deviceready-$q*/
'use strict';
angular.module('elcoCordova', [])
.factory('elcoCordova.onDeviceReady', [
'$q',
'$log',
function ($q, console) {
console.log('elcoCordova.onDeviceReady');
var deferred = $q.defer();
View gist:54ba041b31d9536a8364
event-tracking.com|4webmasters.org|trafficmonetize.org|semalt.semalt.com|social-buttons.com|best-seo-offer.com|buttons-for-website.com|free-share-buttons.com|buttons-for-your-website.com
View hashids.extension.coffee
# hashids (https://www.npmjs.org/package/hashids) make to support encrypt/decrypt string, json.
hashIds = new Hashids(secret);
hashIds.encryptString = (str) ->
hashIds.encrypt([].slice.call(new Buffer(str)));
hashIds.decryptString = (encrypted) ->
new Buffer(hashIds.decrypt(encrypted)).toString()
hashIds.encryptJSON = (obj) ->
hashIds.encrypt([].slice.call(new Buffer(JSON.stringify(obj))));
View sidebar-isActive.js
angular.module('sidebar', [])
.controller('SidebarCtrl', function ($scope, $route) {
$scope.isActive = function (url) {
return $route.current.$$route.controller === $route.routes[url].controller;
}
});
You can’t perform that action at this time.