Skip to content

Instantly share code, notes, and snippets.

@joshbc
joshbc / ReadBuffer.cpp
Created September 16, 2015 14:03
unsigned char array to long conversion
typedef int32_t LONG;
const unsigned char* pData[4];
int pReadIndex = 0;
//unsafe
LONG *p_long = reinterpret_cast< LONG (&)[4] >( pData[pReadIndex] );
//safe
LONG aLong = reinterpret_cast<LONG>(pData[pReadIndex++]) |
reinterpret_cast<LONG>(pData[pReadIndex++]) << 8 |
reinterpret_cast<LONG>(pData[pReadIndex++]) << 16 |
@joshbc
joshbc / gist:6bfc24166591e3075bad
Created November 6, 2014 11:06
Explode String Shell Script
string="abc@hotmail.com;xyz@gmail.com;uvw@yahoo.com"
str1=${string%%;*}
str3=${string##*;}
temp=${string#$str1;}
str2=${temp#;$str3}
@joshbc
joshbc / drawCCRect
Last active August 29, 2015 14:05
cocos2d-x, debug CCSprite boundingBox()
void CCDrawNode::drawRect(const CCRect &rect, float radius,const ccColor3B &color){
ccColor4F color4 = ccc4FFromccc3B(color);
CCPoint pA = rect.origin;
CCPoint pB = ccp(rect.origin.x+rect.size.width,rect.origin.y);
CCPoint pC = ccp(rect.origin.x+rect.size.width,rect.origin.y+rect.size.height);;
CCPoint pD = ccp(rect.origin.x,rect.origin.y+rect.size.height);
drawSegment(pA,pB,radius,color4);
drawSegment(pD,pC,radius,color4);
drawSegment(pA,pD,radius,color4);
drawSegment(pB,pC,radius,color4);