Skip to content

Instantly share code, notes, and snippets.

@prehistoricpenguin
prehistoricpenguin / heapInVivi.cpp
Created October 24, 2012 11:36
code snippet to manager the memory
/*
* vivi/lib/heap.c: simple dynamic memory allocation routine
*
* Based on bootldr/heap.c
*
*/
#include "config.h"
#include "machine.h"
#include "printk.h"
@prehistoricpenguin
prehistoricpenguin / bitscouting.c
Last active December 10, 2015 01:48
bit-couting (8bits integer)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>
int totalRec = 1e8;
const int tbl[] =
{
#define B2(n) n, n+1, n+1, n+2
#define B4(n) B2(n), B2(n+1), B2(n+1), B2(n+2)
@prehistoricpenguin
prehistoricpenguin / fishing.c
Last active December 10, 2015 01:49
day calculating.... 3 days fishing,2 days netting.....
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdbool.h>
const int STARTYEAR = 1990,
STARTMONTH = 1,
STARTDAY = 1,
ENDYEAR = 2100;
@prehistoricpenguin
prehistoricpenguin / bitmap.c
Last active December 10, 2015 02:58
a simple bit table program use an array of 8 chars as a bit map
/*
* @Copyright chm <prehistoricpenguin@qq.com>
*
* a simple bit table program
* use an array of 8 chars as a bit map,illuminated as below:
* 7 6 5 4 3 2 1 0
* <---------------
* 0 0 0 0 0 0 0 0 | 0
* 0 0 0 0 0 0 0 0 | 1
* 0 0 0 0 0 0 0 0 | 2
@prehistoricpenguin
prehistoricpenguin / parser.c
Created December 25, 2012 13:10
simple expression parser
/*
* simple expression parser
* example: 1+2-3 -> 12+3-
*/
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdbool.h>
int lookahead;
/*
* cdecl
*/
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#define MAXTOKEN 100
enum TokenType {NAME, PARENS, BRACKETS};
@prehistoricpenguin
prehistoricpenguin / xls.py
Created January 5, 2013 12:43
a script which joins two .xls files,then make statistic
import xlrd
nameBook = xlrd.open_workbook("/home/chm/Documents/namesheet.xls")
markBook = xlrd.open_workbook("/home/chm/Documents/mark.xls")
nameSheet = nameBook.sheet_by_index(0)
markSheet = markBook.sheet_by_index(0)
fullmark = 0
aboveninety = 0
/*
hdoj 1009
@author: chm
*/
#include <stdio.h>
#include <stdlib.h>
struct T
/*
uva 424
author chm
*/
#include <cctype>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <list>
/*
pat 1035
author chm
*/
#include <cctype>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>