Skip to content

Instantly share code, notes, and snippets.

View lotusnowshen's full-sized avatar

lotusnowshen lotusnowshen

  • zhihu
  • China
View GitHub Profile
@lotusnowshen
lotusnowshen / turtle.py
Last active April 11, 2016 05:40
python3 turtle.py
# coding: utf-8
import turtle
def draw_snake(rad, angle, length, neckrad):
for i in range(length):
# Draw a circle with given radius
turtle.circle(rad, angle)
turtle.circle(-rad, angle)
turtle.circle(rad, angle / 2)
//
// main.cpp
// timu
//
// Created by GuoChunyang on 16/2/26.
// Copyright © 2016年 GuoChunyang. All rights reserved.
//
#include <iostream>
#include <mutex>
@lotusnowshen
lotusnowshen / 1.c
Created January 12, 2016 10:13
cor
#include <stdio.h>
#include <ucontext.h>
#include <unistd.h>
int main(int argc, const char *argv[])
{
ucontext_t context;
getcontext(&context);
puts("hello world\n");
/**
* readn - 读取固定字节数
* @fd: 文件描述符
* @buf: 接收缓冲区
* @count: 要读取的字节数
* 成功返回count,失败返回-1,读到EOF返回<count
*/
ssize_t readn(int fd, void *buf, size_t count)
{
size_t nleft = count;
# coding: utf-8
import types
class Task(object):
taskid = 0
def __init__(self, target):
Task.taskid += 1
self.tid = Task.taskid
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <event2/event.h>
#include <event2/buffer.h>
#include <event2/bufferevent.h>
#define MAX_LINE 1024
#define ERR_EXIT(m) \
@lotusnowshen
lotusnowshen / echo_client.c
Last active August 29, 2015 14:25
client
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <event2/event.h>
#include <event2/buffer.h>
@lotusnowshen
lotusnowshen / gist:8ce6195a4d2280b2dfc9
Last active November 18, 2018 06:40
中文编辑距离
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
//计算UTF8编码所占的字节