Skip to content

Instantly share code, notes, and snippets.

# 由于公司VPN就是一坨💩
# http://superuser.com/questions/458730/keep-ssh-port-forwarding-connection-alive
while true; do
{ while true; do echo echo ping; sleep 10; done } | \
ssh -R 5555:localhost:22 user@remotehost -o ExitOnForwardFailure=yes -v
sleep 10
done
@patricksuo
patricksuo / vscode
Created October 5, 2016 06:42
my visual studio code config
// Place your settings in this file to overwrite the default settings
{
"files.exclude": {
"*.swap": true,
"*.o": true
}
}
@patricksuo
patricksuo / is_little_endian.c
Created October 5, 2016 12:32
c code snippet: is_little_endian
int is_little_endian() {
int a = 1;
return ((char *)(&a))[0]== 1;
}
@patricksuo
patricksuo / lua_proxy_demo.lua
Created October 6, 2016 13:27
lua proxy demo
proxy = {}
proxy.wrap = function(t)
return proxy.wraphelper(t, nil, nil)
end
proxy.wraphelper = function(t, pm, path2me)
-- print("wraphelper", t, pm, path2me)
local m = {}
m.__path = path2me
package power2
// 如果一个数是2的整数次方,那么 取模 可以有优化成一条 AND 指令
// http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
// 思想是把最高有效位塞给其余的地位,第一次塞1位,第二次塞2位,第三次塞4位 第四次塞8位 第五次塞16位
// 最多需要做 lg(N) 次 SHIFT + lg(N) 次 OR 既可, N是参数的位数
// run on go playground https://play.golang.org/p/-3O7xKuQ-D
func RoundUpPowerOf2(a uint32) uint32 {
if a <= 1 {
return 2
PWD=`pwd`
for file in `find $PWD`; do
echo $file
sed -i 's/XXX/YYY/g' $file
done
using System;
namespace threadpool_bench
{
class Program
{
static int totalRound;
static System.Threading.ManualResetEventSlim finishEvent;
static System.Threading.WaitCallback job = obj =>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<DefineConstants Condition="'$(OS)' == 'Windows_NT'">AAA;IS_WIN </DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(MSBuildRuntimeType)' == 'Core'">
<DefineConstants Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">AAA;IS_OSX</DefineConstants>
<DefineConstants Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">AAA;IS_LINUX</DefineConstants>
@patricksuo
patricksuo / Profile.ps1
Created August 16, 2017 02:31
powershell dot file
# https://blogs.technet.microsoft.com/heyscriptingguy/2012/05/21/understanding-the-six-powershell-profiles/
#Description
#Path
#Current User, Current Host - console
#$Home\[My ]Documents\WindowsPowerShell\Profile.ps1
#Current User, All Hosts
#$Home\[My ]Documents\Profile.ps1
#All Users, Current Host - console
#$PsHome\Microsoft.PowerShell_profile.ps1
#!/usr/bin/env bash
# alias godev="source /usr/local/bin/godev"
EchoHelp() {
echo "Hello"
}
NewGoProject() {