Skip to content

Instantly share code, notes, and snippets.

View davidxifeng's full-sized avatar
🥛
Go/Linux/Vim/React/Flutter/Astro/Kubernetes

David Nishikaze davidxifeng

🥛
Go/Linux/Vim/React/Flutter/Astro/Kubernetes
View GitHub Profile
@cloudwu
cloudwu / luavector.c
Created February 21, 2017 03:46
Direct access vector in lua from C
#include <lua.h>
#include <lauxlib.h>
#include <ltable.h>
#include <lstate.h>
#include <lobject.h>
#include <stdio.h>
#include <string.h>
#define MAGIC_VECTOR 1.23456789
@davidxifeng
davidxifeng / tips.md
Last active August 29, 2015 14:15
questions

系统开发

  1. 什么是自旋锁 spin lock? 什么是互斥锁? 各有什么特点,应用在何种场景?
  2. compare and swap (cas)是什么? 原子操作, 编译器(gcc) 固有指令
  3. 读写锁 (锁定读, 锁定写, 未加锁 3种状态) 共享-独占锁

图形学

  1. 仿射变换 齐次坐标空间
  2. 贝塞儿曲线 二次/三次 特点 应用 true type, 矢量图, 曲面

Lua

@tylerneylon
tylerneylon / copy.lua
Last active May 18, 2024 16:41
How to deep copy Lua values.
-- copy.lua
--
-- Lua functions of varying complexity to deep copy tables.
--
-- 1. The Problem.
--
-- Here's an example to see why deep copies are useful. Let's
-- say function f receives a table parameter t, and it wants to
@snoyberg
snoyberg / WaiWS.hs
Created May 26, 2014 13:18
Initial WAI 3.0/websockets implementation
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
import Network.Wai
import Control.Exception (Exception, throwIO, assert)
import Control.Applicative ((<$>))
import Control.Monad (when, forever, unless)
import Data.Typeable (Typeable)
import Network.HTTP.Types (status200, status404)
import Network.Wai.Handler.Warp (run)
diff --git a/src/lapi.c b/src/lapi.c
index d011431..a4fce7f 100644
--- a/src/lapi.c
+++ b/src/lapi.c
@@ -993,6 +993,63 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,
return status;
}
+static Proto *
+cloneproto (lua_State *L, const Proto *src) {

Exploiting Lua 5.1 on 32-bit Windows

The following Lua program generates a Lua bytecode program called ignore-unsigned-sga.fnt, which in turn loads a DLL from within an extremely locked down Lua 5.1 sandbox in a program called RelicCOH2.exe. The remainder of this document attempts to explain how this program works by a whirlwind tour of relevent bits of the Lua 5.1 virtual machine.

if string.dump(function()end):sub(1, 12) ~= "\27Lua\81\0\1\4\4\4\8\0" then
  error("This generator requires a 32-bit version of Lua 5.1")
end

local function outer()
  local magic -- In bytecode, the stack slot corresponding to this local is changed
@davidxifeng
davidxifeng / my_vim_script.vim
Created January 10, 2012 06:21
A hashset of my vim scripts
"also my gist test
"get words count of current line
echo "current line words count : ".len(split(getline(".")))
"Double Pinyin Schema
let s:yunmu={ "iu": "q", "ia": "w", "ua": "w", "e": "e", "uan": "r", "er": "r", "ue": "t",
\ "uai": "y", "v": "y", "u": "u", "i": "i", "uo": "o","o":"o", "un": "p",
\ "a":"a","ong":"s","iong":"s","uang":"d","iang":"d","en": "f","eng":"g",
\ "ang": "h", "an": "j", "ao": "k", "ai":"l", "ing":";",