分类目录归档:其他

c语言扩展lua

c语言源代码:

#include <math.h>
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>

static int hello_sin(lua_State *L){
    double d = luaL_checknumber(L, 1);
    lua_pushnumber(L, sin(d));
    return 1;
}

static const struct luaL_Reg hello_lib[] = {
    {"hello_sin" , hello_sin},
    {NULL, NULL}
};


//luaopen_xxx 系列函数为lua的hook函数,会执行并注册我们自己的类库
int luaopen_hello_lib(lua_State *L){
	/*luaL_newlib(L, hello_lib);*/
	luaL_register(L, "hello_lib",hello_lib); // lua 5.1
	return 1;
}

编译脚本:

#!/bin/bash

gcc a.c -fPIC --shared -o hello_lib.so

使用部分:

[lua]
local N = require(“hello_lib”)
N.hello_sin(1)
[/lua]

ELK中kibana3 php授权方案的设计

kibana3 本身就是纯html,基于require.js 然后 结合 angular.js 实现的一个单页面应用。
所以,修改起来相对简单。

1. 部署本地的php环境,
2. 把index.html 修改成 index.php 在开头直接嵌入相关权限判断的php代码
3. 接口权限的判断,修改权限的本质是对公网屏蔽ES存储的细节。考虑到kibana的前端代码有一个url集中配置,直接修改config.js

32 elasticsearch: “http://”+window.location.hostname+”/proxy.php?q=”,

4. 编写proxy.php

<?php

define('TIMEOUT',10);
define('CONNECTTIMEOUT',5);

function _http($url, $data,$method) {
    $ch = curl_init($url);
    $options = array(
        CURLOPT_CONNECTTIMEOUT => CONNECTTIMEOUT, 
        CURLOPT_TIMEOUT => TIMEOUT, 
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_FRESH_CONNECT => true,
        CURLOPT_CUSTOMREQUEST => $method,
    );  

	if('POST' == $method || 'PUT' == $method) {
		$options[CURLOPT_POST] = true;
		$options[CURLOPT_POSTFIELDS] = $data;
	}
    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}


function post($url, $data) {
	return _http($url,$data,'POST');
}

function put($url, $data) {
	return _http($url,$data,'PUT');
}

function del($url) {
	return _http($url,'','DELETE');
}

$url = $_GET['q'];
$method = $_SERVER['REQUEST_METHOD'];
$host = 'http://localhost:9200/';
$get_url = $host . $url ;

if("GET" == $method) {
	$content = file_get_contents($get_url);
	echo $content;
} else if("POST" == $method){
	$data = $GLOBALS['HTTP_RAW_POST_DATA'];
	$content = post($get_url,$data);
	echo $content;
} else if("PUT" == $method) {
	$data = file_get_contents('php://input');
	$content = put($get_url,$data);
	echo $content;
} else if("DELETE" == $method) {
	$content = del($get_url);
	echo $content;
}

vim安装bundle管理插件

set nocompatible ” be improved
filetype off ” required!

set rtp+=/usr/share/vim/vim74/bundle/vundle

call vundle#rc()

“let vundle manage vundle
“” required!
Bundle ‘gmarik/vundle’
Bundle ‘AutoComplPop’
filetype plugin indent on ” required!