Skip to content

Instantly share code, notes, and snippets.

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

Taeho Kim dittos

💥
뿌슝빠슝
View GitHub Profile
@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
@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 기반 프로토콜로 통신하도록 합니다. 즉, 일반적인 웹서버만 있으면 명령어 처리기를 제공할 수 있으며, 표준 프로토콜을 구현하면 봇 종류에 관계 없이 동일한 기능을 사용할 수 있게 됩니다.

프로토콜

interface X<T> {
// m(o: T): void; // is ok
(o: T): void;
}
class A {
f: X<this>;
}
class B extends A {
@dittos
dittos / JpaBugTest.java
Created September 3, 2018 05:52
Saving lazy-loaded entity with IdClass throws TypeMismatchException
package org.sapzil;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.ManyToOne;
@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 / Application.kt
Last active November 2, 2017 12:17
Kotlin data class + JPA
package org.sapzil
import org.springframework.boot.autoconfigure.SpringBootApplication
@SpringBootApplication
open class Application
@dittos
dittos / fbautoaccept.js
Last active May 18, 2017 15:20
Accept Facebook group join request automatically.
/**
* Install PhantomJS to run: http://phantomjs.org/
* Needs jQuery 2.0.3 in the same directory (Name it as: jquery-2.0.3.min.js)
*/
var webpage = require('webpage');
config = {
email: '',
pass: '',
@dittos
dittos / gist:0abf8b6dc79d08d6700e9c04b87dfc7f
Created April 5, 2017 09:13
Scala + Java serialization size
import java.io._
def sizeOf[T](x:T, y:T): (Long, Long) = {
val buf = new ByteArrayOutputStream
val oos = new ObjectOutputStream(buf)
oos.writeObject(x)
val initSize = buf.size
oos.writeObject(y)
val size = buf.size - initSize
oos.close
import sys
from ctypes import *
from math import isfinite
'''
1) 수식을 파이썬 바이트코드로 컴파일
수식이 바이트코드로 컴파일 될 때 constant folding이 돼서 너무 간단해져 버리지 않도록 함
lineno table에서 연속된 두 바이트코드의 실제 코드상 라인 번호가 255 이상 차이나면 최적화하지 않는 것을 이용
참고: https://github.com/python/cpython/blob/e4091c77026088cb0611b6e896b1579805253f5b/Python/peephole.c#L403
@dittos
dittos / env.py
Created January 26, 2014 15:20
Alembic with Flask-SQLAlchemy
from __future__ import with_statement
from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig
# ***
import sys
sys.path.insert(0, '.')
from app import app, db
# ***