Skip to content

Instantly share code, notes, and snippets.

View xjdrew's full-sized avatar
:octocat:

xjdrew xjdrew

:octocat:
View GitHub Profile
@xjdrew
xjdrew / time.lua
Last active November 13, 2017 02:19
pure lua version of os.date("!*t", time)
-- port from golang: https://golang.org/src/time/time.go
--
local secondsPerMinute = 60
local secondsPerHour = 60 * 60
local secondsPerDay = 24 * secondsPerHour
local secondsPerWeek = 7 * secondsPerDay
local daysPer400Years = 365*400 + 97
local daysPer100Years = 365*100 + 24
local daysPer4Years = 365*4 + 1
@xjdrew
xjdrew / lsyslog.c
Created August 24, 2017 08:50
lsyslog.c
#include <syslog.h>
#include <lua.h>
#include <lauxlib.h>
#define LSYSLOG_FCOUNT 8
static int facilitys[LSYSLOG_FCOUNT] = {
LOG_LOCAL0,
LOG_LOCAL1,
@xjdrew
xjdrew / stable_connection_protocol_2_0.md
Last active June 22, 2017 03:14
断线重连协议 2.0

断线重连协议 2.0

约定

  1. 定长协议: 每条协议的请求和响应应该是固定长度的。
  2. 小头编码:所有数字的字节都使用little-endian

协议

新建连接

@xjdrew
xjdrew / squid_https.md
Last active January 4, 2025 10:05
配置squid https代理

编译

通过ubuntuapt-get安装的squid没有启用ssl功能,需要手动编译。

编译squid步骤如下。

安装依赖及获取源代码

apt-get install openssl libssl-dev ssl-cert
apt-get source squid
@xjdrew
xjdrew / udprelay.go
Created February 23, 2017 10:19
udp relay example
package main
import (
"bytes"
"flag"
"log"
"net"
"sync"
"time"
)
@xjdrew
xjdrew / client.go
Last active February 9, 2025 16:52
golang tls client and server, require and verify certificate in double direction
package main
import (
"crypto/tls"
"crypto/x509"
"flag"
"io"
"io/ioutil"
"log"
"os"
@xjdrew
xjdrew / README.md
Last active November 19, 2018 02:43
多人战斗转发服务

功能

实现多个玩家联机战斗时的操作转发。

流程

玩家先通过组队服务,组好队伍。队长点击开始攻击后,玩家获得本次战斗的token,再连接战斗转发服务。

战斗转发服务为每个队伍创建一个房间,并仅允许该队伍的玩家加入该房间。房间内的每个玩家是完全平等的,所以每个玩家都不能发送指示性指令,比如开始战斗,结束战斗之类的。

每个玩家根据协议发送自己的状态信息,由服务决定当前应处的状态。

@xjdrew
xjdrew / README.md
Last active June 7, 2024 07:15
苹果支付流程

预先说明

目前游戏里面出售的道具,都属于consumable products(消耗性商品),下面的说明流程都是针对这类商品的。别的类型商品处理方法,不完全一样。

注册支付接口回调

app启动的时候即注册支付队列消息的回调者,这个回调者应该是一个单体类,保证在app整个生命周期都存在。ios会回调之前未处理完成的订单。

- (id)init {
    if((self = [super init])) {
        [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
 }
@xjdrew
xjdrew / inter_sort.py
Last active August 29, 2015 14:26
inter_sort
#!/user/bin/python
# -*- coding: utf-8 -*-
import sys, logging
def inter_sort(lines):
m = {}
for i, line in enumerate(lines):
l = line.strip()
try:
_,suffix = l.lower().split("@")
@xjdrew
xjdrew / set_iptables.sh
Last active August 29, 2015 14:13
Automatically loading iptables rules on Ubuntu
#!/bin/sh
PRIVATE_IP=8.8.8.8
/bin/cp -f /etc/iptables.rules /etc/iptables.rules.old-$(date +%Y-%m-%d-%H:%M:%S)
cat > /etc/iptables.rules <<EOF
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:ICMPALL - [0:0]