Skip to content

Instantly share code, notes, and snippets.

View qi7chen's full-sized avatar
🎯
Focusing

Johnnie qi7chen

🎯
Focusing
  • Ubisoft
  • China
View GitHub Profile
@qi7chen
qi7chen / brower_editor.html
Created February 21, 2013 10:43
browser editor
data:text/html,
<style type="text/css">
#e {
position:absolute;
top:0;
right:0;
bottom:0;
left:0;
font-size:16px;
}
# -*- coding: gb2312 -*-
import sys
import string
#统计
def satisics(numbers):
my_numbers = []
last_row = []
@qi7chen
qi7chen / socket_with_coroutine.lua
Last active June 19, 2024 13:20
socket with coroutine
local socket = require('socket')
local threads = {}
local function receive(conn)
conn:settimeout(0)
local s, status = conn:receive(1024)
if status == 'timeout' then
coroutine.yield(conn)
end
@qi7chen
qi7chen / zlib_example.cpp
Last active December 19, 2015 13:38
zlib api usage
// The maximum size needed for the compressed output.
int GetMaxCompressedLen(int souceLen)
{
// round up any fraction of a block
int n16kBlocks = (souceLen + 16383) / 16384;
return ( souceLen + 6 + (n16kBlocks * 5) );
}
int ZlibCompress(const BYTE* input, int inlen, BYTE* output, int outlen)
@qi7chen
qi7chen / zlib_usage.cpp
Last active January 18, 2022 01:19
zlib deflate and inflate
typedef std::vector<BYTE> ByteArray;
int CompressByteArray(const ByteArray& input, ByteArray* pOutput)
{
size_t inlen = input.size();
assert(inlen > 0 && pOutput);
/* allocate deflate state */
z_stream strm;
strm.zalloc = Z_NULL;
@qi7chen
qi7chen / rle.cpp
Created October 23, 2013 09:24
Run-length encoding and decoding
/**
* @file rle.cpp
* @date Oct 23, 2013
* @author ichenq@gmail.com
* @brief Run-length encoding and decoding
*
*/
#include <assert.h>
#include <vector>
@qi7chen
qi7chen / printf.c
Created January 25, 2014 05:20
printf routine
/*
Copyright 2001, 2002 Georges Menie (www.menie.org)
stdarg version contributed by Christian Ettinger
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
@qi7chen
qi7chen / getDaysOfThisMonth.c
Last active November 7, 2015 07:05
getDaysOfThisMonth(), getDaysOfYear(), getElapsedDay()
/* how many days this month have */
int getDaysOfThisMonth()
{
time_t now = time(NULL);
tm date = *localtime(&now);
/* first day of this month */
tm this_month = {};
this_month.tm_year = date.tm_year;
@qi7chen
qi7chen / bench_unordered.cpp
Last active August 29, 2015 14:03
benmark unordered
//
// compile:
// g++ -std=c++11 -lrt -luuid
//
#include "bench.h"
#include <iostream>
#include <set>
#include <unordered_set>
#include <string>
@qi7chen
qi7chen / bench.h
Last active August 29, 2015 14:03
#pragma once
#include <time.h>
#include <stdint.h>
#include <array>
typedef std::array<uint8_t, 16> UUID_T;