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

Keybase proof

I hereby claim:

  • I am davidfeng on github.
  • I am davidfeng (https://keybase.io/davidfeng) on keybase.
  • I have a public key ASAVA-RbCz8YZU5tKQt1QuSu7y6cULUvX-fSutmFkKeI7Qo

To claim this, I am signing this object:

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 / print_table.lua
Created March 19, 2015 11:11
Lua's print table by cloudwu
local print = print
local tconcat = table.concat
local tinsert = table.insert
local srep = string.rep
local type = type
local pairs = pairs
local tostring = tostring
local next = next
@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

@davidxifeng
davidxifeng / custom_hashset.hs
Created July 25, 2014 12:29
data structure for fast merge-insert
import qualified Data.HashSet as HS
import Data.Hashable
-- 2014-07-25 20:27:29
-- TODO custom HashSet with special ``insert`` ``fromListWith`` ...
data Test = A Int | B Double | C Char | D
deriving (Show)
instance Eq Test where
@davidxifeng
davidxifeng / csv_test.hs
Created July 24, 2014 07:39
fail mzero and Parser
import Data.Csv
import Control.Monad
import Control.Applicative
-- 2014-07-24 15:26:22 fail and mzero
data Test = A | B | C
deriving (Show, Read)
instance FromField Test where
@davidxifeng
davidxifeng / ssh-copy-id.sh
Created June 17, 2014 08:54
the missing ssh-copy-id for Mac OS X
#!/bin/sh
# Shell script to install your public key on a remote machine
# Takes the remote machine name as an argument.
# Obviously, the remote machine must accept password authentication,
# or one of the other keys in your ssh-agent, for this to work.
ID_FILE="${HOME}/.ssh/id_rsa.pub"
if [ "-i" = "$1" ]; then
{-# 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)

测试使用gist

你好

I love Haskell.

@davidxifeng
davidxifeng / little_lisp.py
Created May 19, 2013 07:18
a small lisp in python
################ Lispy: Scheme Interpreter in Python
## (c) Peter Norvig, 2010; See http://norvig.com/lispy.html
################ Symbol, Procedure, Env classes
from __future__ import division
Symbol = str