Skip to content

Instantly share code, notes, and snippets.

View dittos's full-sized avatar
💥
뿌슝빠슝

Taeho Kim dittos

💥
뿌슝빠슝
View GitHub Profile
#77
for c in 5,5,4,3,2,0,2,3,4,5,5:s=(c*' 'or'*')+'* '[:6-c];print s+s[-2::-1]
@dittos
dittos / gist:6971124
Created October 14, 2013 05:19
IE <script> lazy loading bug

요즘 소셜 플러그인 등 외부 스크립트를 삽입할 때 많이 사용하는 기법이 <script> 태그를 비동기로 추가하는 겁니다.

<script>
(function() {
    var js = document.createElement('script');
    js.async = true; // ...
    
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(js, s);
})();
@dittos
dittos / gist:6912391
Last active December 25, 2015 03:49
Banks in Korea
# -*- coding: utf-8 -*-
import io
# codefilex.text: 금융결제원에서 다운로드
# http://www.kftc.or.kr/kftc/data/EgovBankListMove.do > 전체코드(txt)
banks = []
legacy_mapping = {
u'SC': u'SC(제일)'
@dittos
dittos / gist:6765329
Created September 30, 2013 15:18
IRCApps: RPC for IRC bots

IRCApps: RPC for IRC bots

개요

전통적인 IRC 봇은 명령어 처리 코드가 코어 코드와 같은 프로세스 안에서 같은 데이터를 공유하며 함께 작동하는 구조입니다. 플러그인 기능을 도입해서 봇을 끄지 않고도 기능을 추가, 제거, 업데이트할 수 있게 만들기도 하지만, 플러그인이 오작동하면 봇 자체가 불안정해질 수 있습니다. 또한 외부에서 제공된 플러그인을 검증 없이 사용하면 보안 문제가 발생할 수 있습니다. 무엇보다도, 서로 다른 종류의 봇끼리 동일한 플러그인 코드를 공유할 수 없어서 사람들의 노력이 낭비됩니다.

IRCApps는 이러한 문제를 해결하기 위해 IRC 봇과 명령어 처리기('IRCApps 서버')를 별도의 프로세스로 분리합니다. 그리고 봇이 명령어 처리기와 표준적인 HTTP 기반 프로토콜로 통신하도록 합니다. 즉, 일반적인 웹서버만 있으면 명령어 처리기를 제공할 수 있으며, 표준 프로토콜을 구현하면 봇 종류에 관계 없이 동일한 기능을 사용할 수 있게 됩니다.

프로토콜

def fix_orientation(img):
try:
orient = img.orientation
except IndexError:
return
if orient in ('left_top', 'right_top'):
img.rotate(90)
elif orient in ('bottom_right', 'bottom_left'):
@dittos
dittos / gist:6396622
Last active July 2, 2018 13:19
Two concurrent sessions in Flask-SQLAlchemy
# coding=utf-8
import flask
from flask.ext.sqlalchemy import SQLAlchemy
app = flask.Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
app.config['SQLALCHEMY_ECHO'] = True
db = SQLAlchemy(app)
log_db = SQLAlchemy(app, session_options={
@dittos
dittos / BitmapCache.java
Created August 26, 2013 04:47
LruCache-based BitmapCache for Volley
package com.gae9.android.util;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import com.android.volley.toolbox.ImageLoader.ImageCache;
public class BitmapCache implements ImageCache {
private LruCache<String, Bitmap> mMemoryCache;
@dittos
dittos / DiskBasedCache.java
Last active March 18, 2020 15:20
Improved Volley DiskBasedCache
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
private void resetBitrate()
{
if (this.mWifiConnected)
{
sCurrentBitrate.set(512);
return;
}
if (this.mEthernetConnected)
{
sCurrentBitrate.set(512);
@dittos
dittos / gist:5821349
Created June 20, 2013 09:08
push notification handling boilerplate
@interface AppDelegate () {
NSDictionary *pushUserInfo;
}
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// ...