Skip to content

Instantly share code, notes, and snippets.

#include <vector>
#include <assert.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
typedef int32_t Score;
typedef int32_t UserId;
typedef int32_t Rank;
const Score kInvalidScore = -1;
@luoqeng
luoqeng / README.md
Created July 23, 2016 11:00 — forked from tnarihi/README.md
Emacs 24.4 installation on Ubuntu 14.04 without sudo

Installing Emacs 24.4 on Ubuntu 14.04 without sudo privilege

Just run:

sh ./ubuntu14.04-emacs-24.4-install.sh

This will install ncurses which is dependency of emacs24.4. It may requires another dependencies depending on your environment. Note that configure options in emacs installation are for disabling GUI features.

@luoqeng
luoqeng / wan_ssh
Created April 9, 2018 03:35 — forked from lynus/wan_ssh
openwrt:allow wan ssh into your wrt
by default,openwrt do not allow ssh access from wan, here are two method to change that:
1.login into your wrt from a lan host.issue the following command:
iptables -F
the command "flush away" all the firewall rules,including the one that rejects ssh request from wan.
now you can try ssh from anywhere.
aware that the firewall deactivation leads to highly security risk.and after the wrt restarts ,all default firewall configuration comes back.you hava to "flush" the rules once again.
@luoqeng
luoqeng / ERC20.sol
Last active May 31, 2018 12:40 — forked from anonymous/ERC20.sol
Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-v0.4.19+commit.c4cbbb05.js&optimize=false&gist=
pragma solidity ^0.4.10;
interface ERC20 {
function balanceOf(address who) public view returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
function allowance(address owner, address spender) public view returns (uint256);
function transferFrom(address from, address to, uint256 value) public returns (bool);
function approve(address spender, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
wget https://downloads.openwrt.org/releases/18.06.4/targets/x86/64/openwrt-18.06.4-x86-64-combined-ext4.img.gz
gzip -d openwrt-18.06.4-x86-64-combined-ext4.img.gz
dd if=openwrt-18.06.4-x86-64-combined-ext4.img.gz of=/dev/sda bs=4M; sync;
apt install parted
parted /dev/sda print
SPC f f 打开文件
SPC f t 打开当前文件所在的目录
SPC p t 打开当前文件所在的根目录
SPC p p 切换项目
SPC j = 自动对齐,相当于 beautify
SPC cl 增加删除注释
SPC / 搜索
SPC t n Toggleline numbers
SPC q q quit
SPC q R 重启 Emacs
# 本地开发,新建feature
arc feature feature_1
# 或 git checkout -b feature_1
# 修改本地文件,然后提交
git add
git commit
# 提交code review
arc diff
# 通过--reviewers name参数可以指定reviewer
Varint 中的每个 byte 的最高位 bit 有特殊的含义,如果该位为 1,表示后续的 byte 也是该数字的一部分,如果该位为 0,则结束。其他的 7 个 bit 都用来表示数字。
三次握手的过程中,当用户首次访问server时,发送syn包,server根据用户IP生成cookie,并与syn+ack一同发回client;client再次访问server时,在syn包携带TCP cookie;如果server校验合法,则在用户回复ack前就可以直接发送数据;否则按照正常三次握手进行。
无栈协成,不切换栈寄存器只切换this,生命周期取决于对象的生命周期。用类成员变量,传递参数。
一致性(Consistency) (所有节点访问同一份最新的数据副本)
可用性(Availability)(每次请求都能获取到非错的响应——但是不保证获取的数据为最新数据)
分区容错性(Partition tolerance)(如果不能在时限内达成数据一致性,则发生分区,必须就当前操作在 C 和 A 之间做出选择。)
@luoqeng
luoqeng / tcpproxy.go
Created November 18, 2019 08:52
proxy
package main
import (
"io"
"net"
)
func main() {
s, _ := net.Listen("tcp", ":8080")
for {
@luoqeng
luoqeng / client.c
Created January 8, 2020 04:07 — forked from Chion82/client.c
fake TCP test
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <string.h>
#include "trans_packet.h"
void on_packet_recv(char* from_ip, uint16_t from_port, char* payload, int size, unsigned int seq) {
printf("Packet received from=%s:%d, seq=%d\n", from_ip, from_port, seq);
char* message = (char*)malloc(size);
memcpy(message, payload, size);