Skip to content

Instantly share code, notes, and snippets.

View bojieli's full-sized avatar

Bojie Li bojieli

View GitHub Profile
@bojieli
bojieli / msg_stat.sh
Created December 6, 2014 16:13
Get per hour/date QQ message count and length in a two-people conversation
#!/bin/bash
# Usage: the first parameter should be the exported QQ message file
echo -e "Hour\tMyCnt\tMyLen\tMyAvglen\tHerCnt\tHerLen\tHer Avglen"; cat $1 | awk '/2014-/ { if($3=="boj") { split($2,time,":"); hour=time[1]; getline; me_len[hour]+=length($0); me_num[hour]++ } else { split($2,time,":"); hour=time[1]; getline; her_len[hour]+=length($0); her_num[hour]++ } } END {for(key in me_num) printf("%s\t%d\t%d\t%lf\t%d\t%d\t%lf\t\n", key, me_num[key], me_len[key], me_len[key] * 1.0 / me_num[key], her_num[key], her_len[key], her_len[key] * 1.0 / her_num[key] ) }' | sort -n
echo -e "Date\tMyCnt\tMyLen\tMyAvglen\tHerCnt\tHerLen\tHer Avglen"; cat $1 | awk '/2014-/ { if($3=="boj") { split($2,time,":"); hour=time[1]; getline; me_len[hour]+=length($0); me_num[hour]++ } else { split($2,time,":"); hour=time[1]; getline; her_len[hour]+=length($0); her_num[hour]++ } } END {for(key in me_num) printf("%s\t%d\t%d\t%lf\t%d\t%d\t%lf\t\n", key, me_num[key], me_len[key], me_len[key] * 1.0 / me_num[key], her_num[key], her_len[k
@bojieli
bojieli / roundto100.c
Created December 15, 2014 14:18
input: amount of each receipt (yuan), output: max credit <= 100.0 yuan using some of the receipts
#include<stdio.h>
#include<math.h>
#define MAX 1000
#define MAX_ITEMS 100
int main() {
int i, j;
int n = 0, w[MAX_ITEMS+1] = {0};
int s[MAX_ITEMS+1][MAX+1] = {1};
float weight;
while (scanf("%f", &weight) != EOF) {
@bojieli
bojieli / roundto100-optimized.c
Created December 15, 2014 14:46
input: amount of each receipt (yuan), output: max credit <= 100.0 yuan using some of the receipts
#include<stdio.h>
#include<math.h>
#define MAX 1000
#define MAX_ITEMS 100
int main() {
int i, j;
int n = 0, w[MAX_ITEMS+1] = {0};
int s[MAX+1] = {1};
float weight;
while (scanf("%f", &weight) != EOF) {
@bojieli
bojieli / file2.c
Created December 17, 2014 16:01
Programming-in-C/141217
/* File format:
* Number of couples | record for couple 1 | record for couple 2...
* int | No. | boy name | girl name | next pointer | ...
* | int | string | string | pointer |
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@bojieli
bojieli / get-qq-num.py
Created February 13, 2015 06:26
A sample http server
import SimpleHTTPServer
import SocketServer
import urlparse
PORT = 80
class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
try:
query = urlparse.parse_qs(urlparse.urlparse(self.path).query)
#include<stdio.h>
struct cal {
int hour, minute, second, day, month, year;
};
struct cal convert(struct cal in) {
struct cal out;
in.year -= 2000;
int past_years = in.month >= 3 ? in.year + 1 : in.year;
int days = in.year * 365 + (past_years + 3) / 4 - (past_years + 99) / 100 + (past_years + 399) / 400;
@bojieli
bojieli / 3.c
Last active August 29, 2015 14:17
词典
#include<stdio.h>
#include<stdlib.h>
#define HASH_SIZE 300007
#define LINE_LEN 32
char dict[HASH_SIZE][LINE_LEN] = {0};
static unsigned int BKDRhash(char* key) {
unsigned int seed = 131; // 31 131 1313 13131 131313 etc..
unsigned int hash = 0;
@bojieli
bojieli / 2.c
Created March 28, 2015 07:08
最短前缀
#include<stdio.h>
#include<stdlib.h>
int main() {
int num = 0;
int i, j, k;
char a[1001][22] = {0};
int idx[1001], tmpidx;
char tmp[22] = {0};
while (scanf("%s", a[num++]) != EOF);
@bojieli
bojieli / complex.cpp
Last active August 29, 2015 14:20
Exercise 1-2
using namespace std;
#include <iostream>
class Complex {
private:
double real;
double im;
public:
Complex(double real, double im) {
@bojieli
bojieli / getpower.cpp
Created May 10, 2015 13:28
Exercise 1-1
using namespace std;
#include <iostream>
int getPower(int x, int n) {
if (x == 0)
return 0;
if (n == 0)
return 1;
else if (n > 0)
return getPower(x, n-1) * x;
else // n < 0