Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am bojieli on github.
* I am boj (https://keybase.io/boj) on keybase.
* I have a public key ASBJWJNZ_y1nUZxwz_dbJj6-lTwHscbg-FgiF5pu-XA_0Ao
To claim this, I am signing this object:
@bojieli
bojieli / CVE-2015-5477.c
Created July 29, 2015 16:36
CVE-2015-5477 POC
/* CVE-2015-5477 POC
* An error in handling TKEY queries can cause named to exit with a REQUIRE assertion failure
* Affected software: ISC named (bind) 9.1.0 -> 9.8.x, 9.9.0->9.9.7-P1, 9.10.0->9.10.2-P2
*
* Copyleft Bojie Li <[email protected]>
*
* Free to modify and redistribute this program.
* Use at your own risk and you are responsible for what you are doing.
*/
#include<stdio.h>
@bojieli
bojieli / 2.2.cpp
Created May 17, 2015 18:34
Exercise 2.2
using namespace std;
#include <iostream>
#include <cmath>
class Complex {
private:
double real;
double im;
public:
@bojieli
bojieli / 2.1.cpp
Created May 17, 2015 18:33
Exercise 2.1
// compile with "g++ -std=c++11"
// to_string in C++11 is used
using namespace std;
#include <iostream>
#include <string>
#include <stdexcept>
class Date {
private:
int year;
@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
@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 / 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 / 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;
#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 / 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)