Skip to content

Instantly share code, notes, and snippets.

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

Taeho Kim dittos

💥
뿌슝빠슝
View GitHub Profile
@dittos
dittos / ReactExample.java
Last active December 6, 2015 12:15
Possibility of React + GWT?
import static react.ReactDOM.*;
class TodoList extends ReactComponent {
public static final ReactProp<List<TodoItem>> ITEMS = ReactProp.create();
public static ReactElement.Builder<TodoList> builder() {
return ReactElement.builder(TodoList.class);
}
public ReactElement render() {
@dittos
dittos / gist:4723511
Created February 6, 2013 15:58
First take on Go.
package main
import (
"fmt"
"net/http"
"exp/html"
)
type MatchFunc func(*html.Node) bool
type Matcher []MatchFunc
# Brute-force
def solve(costs, mindays):
mincost = None
availdays = len(costs)
for days in xrange(mindays, availdays + 1):
for start in xrange(availdays - days + 1):
# costs = 0, 1, 2, 3 (availdays=4), days = 2
# => (0, 1), (1, 2), (2, 3)
# last start = 2 = availdays-days = 4 - 2
cost = sum(costs[start:start+days]) / float(days)
@dittos
dittos / gist:5282788
Created April 1, 2013 01:42
크킄... 흑.화.한다.
var darken = (function() {
var re = { sub: function(regex, subst, s) { return s.replace(new RegExp(regex, 'gi'), subst); } };
var random = {
random: function() { return Math.random(); },
randint: function randint(e) { return Math.floor(random.random() * e); },
randrange: function randrange(s, e) { return s + random.randint(e - s); },
choice: function(seq) { return seq[random.randint(seq.length)]; }
};
String.prototype.strip = function() { return this.replace(/^\s*(.*?)\s*$/, '$1'); };

Flask 프로젝트 구성하기

Flask를 처음 접하면 Django 등의 풀 스택 프레임워크와 달리 정해진 디렉토리 구조를 따를 필요가 없다는 점이 매력적이다. 하지만 연습 수준을 벗어나 실제로 프로젝트를 시작하게 되면 파일 한 개에 모든 코드를 다 넣을 수는 없으니, 어떻게든 모듈을 나눠보려 시도했다가 Flask의 특이한 구조때문에 '멘붕'했던 경험이 있다.

물론 Flask 문서에 좀 더 규모가 큰 애플리케이션을 구성하는 방법이 설명되어 있기는 하나, 애초에 Flask에서 커버하는 범위가 적기 때문에 DB 연동 등에 대한 내용은 없다. 그래서 실제 프로젝트에 바로 적용하기에는 뭔가 부족하다.

이 글에서는 내가 그동안 시행착오를 겪어오면서 어느 정도 체계를 잡은 프로젝트 구성 방식을 설명할 것이다. 당연한 이야기지만, 언제나 이 글에 나온대로 구성할 수 있는 것은 아니다. 프로젝트의 규모나 요구 사항에 따라서는 여기서 설명하는 방식이 부적절할 수도 있음을 미리 밝혀둔다. (실은 메모의 성격이 더 큰 글임을 감안해야 한다;;)

디렉토리 구성

@dittos
dittos / gist:5352785
Created April 10, 2013 08:16
Prefix matching for elements in Postgres array
area_filter = sql.text(
"EXISTS ("
"SELECT a FROM unnest(model.areas) AS a "
"WHERE a LIKE :prefix || '%'"
")", bindparams=[sql.bindparam('prefix', area_prefix)])
session.query(Model).filter(area_filter)
type Point = (Float, Float)
data Orbit = Orbit Point Float
data TestCase = TestCase Point Point [Orbit]
-- Input
readFloats :: IO [Float]
readFloats = do
line <- getLine
return (map read (words line))
@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 {
// ...
private void resetBitrate()
{
if (this.mWifiConnected)
{
sCurrentBitrate.set(512);
return;
}
if (this.mEthernetConnected)
{
sCurrentBitrate.set(512);
@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;