Skip to content

Instantly share code, notes, and snippets.

View x5lcfd's full-sized avatar
:octocat:
coding.

x5lcfd x5lcfd

:octocat:
coding.
View GitHub Profile
@x5lcfd
x5lcfd / EnumParse.cs
Created February 13, 2017 07:38
StringToEnum
// Mono2.6 doesn't have Enum.TryParse
public static TEnum ToEnum<TEnum>(this string strEnumValue, TEnum defaultValue)
{
if (!Enum.IsDefined(typeof(TEnum), strEnumValue))
return defaultValue;
return (TEnum)Enum.Parse(typeof(TEnum), strEnumValue);
}
:: setvar varname cmd
:: Set VARNAME to the output of CMD
:: Triple escape pipes, eg:
:: setvar x dir c:\ ^^^| sort
:: -----------------------------
:: http://stackoverflow.com/a/25954264/6181205
@echo off
SETLOCAL
@x5lcfd
x5lcfd / tsinghua-brew.sh
Created February 17, 2017 17:25
homebrew from mirrors.tuna.tsinghua.edu.cn
# 替换现有上游
cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
brew update
# 使用homebrew-science或者homebrew-python
// http://stackoverflow.com/questions/874134/find-if-string-ends-with-another-string-in-c
bool has_suffix(const std::string &str, const std::string &suffix)
{
return str.size() >= suffix.size() &&
str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
}
@x5lcfd
x5lcfd / lua_string.lua
Created March 13, 2017 12:06
Lua string collections
-- split
string.split = function(s, p)
local rt= {}
string.gsub(s, '[^'..p..']+', function(w) table.insert(rt, w) end )
return rt
end
#!/usr/bin/env lua
--[[-------------------------------------------------------------------
ChunkSpy.lua
A Lua 5.1 binary chunk disassembler
ChunkSpy was inspired by Nick Trout's vmmerge5.lua
Copyright (c) 2004-2006 Kein-Hong Man <[email protected]>
The COPYRIGHT file describes the conditions under which this
software may be distributed (basically a Lua 5-style license.)
@x5lcfd
x5lcfd / ctags.cnf
Last active June 17, 2017 15:38
项目用, vim tags.
--exclude=.git
--exclude=.svn
--regex-LUA=/^def\.method\(.*\)\.[ \t]*([a-zA-Z0-9]*)\s*=\s*function.*$/\1/t,tfunctions/
--regex-LUA=/^def\.virtual\(.*\)\.[ \t]*([a-zA-Z0-9]*)\s*=\s*function.*$/\1/t,tfunctions/
--regex-LUA=/^def\.override\(.*\)\.[ \t]*([a-zA-Z0-9]*)\s*=\s*function.*$/\1/t,tfunctions/
--regex-LUA=/^def\.static\(.*\)\.[ \t]*([a-zA-Z0-9]*)\s*=\s*function.*$/\1/t,tfunctions/
--regex-LUA=/^def\.final\(.*\)\.[ \t]*([a-zA-Z0-9]*)\s*=\s*function.*$/\1/t,tfunctions/
--regex-LUA=/^.*\s*function[ \t]*([a-zA-Z0-9_]+)\s*\(.*$/\1/l,lfunction/
--regex-LUA=/^.*local\s*[ \t]*([a-zA-Z0-9_]+)\s*=\s*function.*$/\1/l,lfunction/
@x5lcfd
x5lcfd / vsvimrc.vim
Created July 23, 2017 02:43
rename to _vsvimrc for visual studio.
nnoremap h <NOP>
nnoremap j <NOP>
nnoremap k <NOP>
nnoremap l <NOP>
nmap <C-O> :vsc View.NavigateBackward<CR>
nmap <C-I> :vsc View.NavigateForward<CR>
@x5lcfd
x5lcfd / gist:97b9002cf3218cb6a0d242a44945582e
Created July 23, 2017 16:25 — forked from ChickenProp/gist:3194723
The Liang-Barsky algorithm for line-rectangle collisions

The Liang-Barsky algorithm is a cheap way to find the intersection points between a line segment and an axis-aligned rectangle. It's a simple algorithm, but the resources I was pointed to didn't have particularly good explanations, so I tried to write a better one.

Consider a rectangle defined by x_min ≤ x ≤ x_max and y_min ≤ y ≤ y_max, and a line segment from (x_0, y_0) to (x_0 + Δ_x, y_0 + Δ_y). We'll be assuming at least one of Δ_x and Δ_y is nonzero.

Image depicting the situation

(I'm working with Flash, so I'll be using the convention that y increases as you go down.)

We want to distinguish between the following cases:

@x5lcfd
x5lcfd / url_short.md
Last active October 5, 2018 09:11
url shortener