Skip to content

Instantly share code, notes, and snippets.

@zodiac1111
zodiac1111 / ajax.js
Created August 22, 2014 05:26
jquery ajax
$.ajax({
cache : false,
type : "post",
url : "cgi-bin/xxx.cgi",
contentType : "application/x-www-form-urlencoded; charset=utf-8",
dataType : "json",
data : "act=xxx",
success : function(result, textStatus) {
// 成功
},
@zodiac1111
zodiac1111 / Makefile.makefile
Created August 22, 2014 05:16
make根据代码依赖头文件
%.o:%.d
%.d:%.c
@set -e; rm -f $@; \
$(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
@zodiac1111
zodiac1111 / tar.sh
Created August 22, 2014 05:14
tar 压缩,排除文件,目录,符号连接,指定用户
# --numeric-owner:指定解压出来的文件所有者为root,因为目标为root(0)用于
tar --exclude="$(DIST_PAGKE)" --exclude=".svn" --exclude=".git" \
--exclude="etc" \
--exclude="data/config" \
--exclude="*.log" \
--exclude="scss" \
--exclude=".project" --exclude=".gitignore" --exclude=".cproject" \
-hczf $(DIST_PAGKE) -C $(DIST_DIR) . \
--numeric-owner --owner=0 --group=0
@zodiac1111
zodiac1111 / kargs.c
Created August 22, 2014 03:52
c语言关键字参数(keyword argment) 命名参数(Named parament)
/* filename kargs.c
* 来自:
* http://www.darkcoding.net/software/keyword-arguments-in-c/
* http://en.wikipedia.org/wiki/Named_parameter
*/
#include <stdio.h>
/* 使用宏定义将关键字参数转换成为一个(匿名)结构体 */
/* 可以指定初始值:使用形如.x=101 */
#define draw_circle(...) draw_circle_func( \
@zodiac1111
zodiac1111 / clog.c
Last active August 29, 2015 14:05
打印日志到终端,颜色,线程号等信息
// clog.h
#define DC_LOG_FD stderr ///<日志输出文件描述符,简单的输出到标准错误输出
#define CL_RED "\033[31m"
#define GREEN "\033[32m"
#define YELLOW "\033[33m"
#define BLUE "\033[34m"
#define PURPLE "\033[35m"
#define CL_ATTR_REV "\033[7m"
#define CL_ATTR_UNDERLINE "\033[4m"
#define _COLOR "\033[0m"
@zodiac1111
zodiac1111 / 0_reuse_code.js
Created August 22, 2014 03:19
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@zodiac1111
zodiac1111 / swap.c
Last active August 29, 2015 14:05
swap两个数,一种类型无关.宏, 来自 kernel.h
#define swap(a, b) \
do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
/// 临时变量名字,
/// from http://stackoverflow.com/questions/3982348/implement-generic-swap-macro-in-c
#define swap(x, y) \
do { typeof(x) temp##x##y = x; x = y; y = temp##x##y; } while (0)
@zodiac1111
zodiac1111 / array_size.c
Last active August 29, 2015 13:56
求数组元素个数
#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
int a[10];
int *n =a;
ARRAY_SIZE(a);
ARRAY_SIZE(n); // compile error :)
@zodiac1111
zodiac1111 / print_msg.c
Last active January 3, 2016 10:19
知道长度打印字符串(不是以\0结尾的),如httpmsg,
printf("%*.s",len,str);
@zodiac1111
zodiac1111 / gist:7464999
Last active December 28, 2015 07:29
试题
n*n矩阵逆时针题目
给定一个小于10的正数,从(0,0)点开始逆时针输出这个矩阵;
如:
1
01
5 //输入5,输出下面的矩阵
01 16 15 14 13
02 17 24 23 12
03 18 25 22 11