Skip to content

Instantly share code, notes, and snippets.

@pjc0247
pjc0247 / name_gen.rb
Last active December 21, 2015 13:49
name generator
def char_by_order(ord)
case ord
when 0..25 # lower case alphabet
offset = 'a'.ord
when 26..51 # upper case alphabet
offset = 'A'.ord
ord -= 26
else # number
offset = '0'.ord
ord -= 52
@pjc0247
pjc0247 / string.rb
Created September 27, 2013 06:05
Ruby String Extension
class String
def left(n)
return self if n > self.length
self.slice(0, n)
end
def right(n)
return self if n > self.length
self.slice(self.length-n, n)
end
end
import java.lang.reflect.*;
import java.util.Random;
class Test{
static {
try {
Field field = Math.class.getDeclaredField("randomNumberGenerator");
field.setAccessible(true);
field.set(null, new Random(){
@pjc0247
pjc0247 / CCAnimateWithBlending.cpp
Created February 18, 2014 08:23
CCAnimate with ccBlendFunc
#include "CCAnimateWithBlending.h"
using namespace cocos2d;
CCAnimateWithBlending *CCAnimateWithBlending::create(
CCAnimation *animation, ccBlendFunc blendFunc){
CCAnimateWithBlending *p = new CCAnimateWithBlending();
if( p != NULL && p->initWithAnimation(animation, blendFunc) ){
p->autorelease();
#ifndef _THREAD_SAFE_SINGLETON_H
#define _THREAD_SAFE_SINGLETON_H
#include <atomic>
#include <mutex>
template <typename T>
class ThreadSafeSingleton{
public:
ThreadSafeSingleton(void){
def to_binary_u(n, fit=8)
bin = ""
while n > 0
bin = (n % 2).to_s + bin
n /= 2
end
return bin.rjust(fit, '0')
end
@pjc0247
pjc0247 / c.cpp
Created December 7, 2014 14:14
루비 스타일 C++ getter/setter
#define attr_writer(name) \
void set_##name(const decltype(name) &v){ \
this->name = v; \
}
#define attr_reader(name) \
decltype(name) get_##name(){ \
return this->name; \
}
#define attr_accessor(name) \
attr_reader(name); \
@pjc0247
pjc0247 / aa.md
Last active August 29, 2015 14:12
  • 그래픽

    • 세이더 지원 (GLSL)(partial)
    • 스프라이트, 이미지, 텍스쳐의 분리
    • 스트리밍 텍스쳐 지원(partial)
    • 텍스쳐를 PNG로 저장 가능 (스크린샷 등)
    • Render-To-Texture 인터페이스 개선
  • 윈도우

    • 렌더러와 윈도우의 분리
  • 멀티 윈도우 지원(partial)

/* SELECT * FROM account */
auto rows = accounts.all();
for(auto &row : rows)
cout<<row.get("level").as_int();
/* SELECT * FROM account WHERE user_id='pjc0247' AND user_pw='asdf1234' */
auto rows = accounts
.begin()
.match("user_id", "pjc0247")
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
int main(int argc, char* argv[]){
FILE *fp = _popen("dir", "r");
std::string buffer;