Skip to content

Instantly share code, notes, and snippets.

@grissiom
grissiom / calc.c
Last active August 29, 2015 14:00
Super simple calculator
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <limits.h>
enum RET {
RET_OK = 0,
RET_OVERFLOW = -1,
RET_NODIGIT = -2,
};
@grissiom
grissiom / gist:6445303
Last active December 22, 2015 08:29
dark art in GCC

Find First Set:从低位开始,获取第一个置位的位。如果所有位都是 0,返回 0。如果第一位置位,返回 1,等等:

int __builtin_ffs(int);

直接调用会被 inline。

获取函数的返回地址:

#include <stdio.h>
class A
{
public:
virtual float getz()
{
return 0.0;
}
};
@grissiom
grissiom / gist:2565746
Created May 1, 2012 06:53
python darkart
# get the source file path in a robust way
# from http://stackoverflow.com/a/6098238/297347
# with a little cleanup
import inspect
script_patch = os.path.abspath(os.path.dirname(inspect.getfile(inspect.currentframe())))
# convert a binary stream into hex format
# Note: hex will take integer as argument