Skip to content

Instantly share code, notes, and snippets.

View gist:0604dc9920c09d603b9ec75aeca5a4e8
### 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 Jul 29, 2015
CVE-2015-5477 POC
View CVE-2015-5477.c
/* 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 <bojieli@gmail.com>
*
* 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
Exercise 2.2
View 2.2.cpp
using namespace std;
#include <iostream>
#include <cmath>
class Complex {
private:
double real;
double im;
public:
@bojieli
bojieli / 2.1.cpp
Created May 17, 2015
Exercise 2.1
View 2.1.cpp
// 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;
View getpower.cpp
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 Aug 29, 2015
Exercise 1-2
View complex.cpp
using namespace std;
#include <iostream>
class Complex {
private:
double real;
double im;
public:
Complex(double real, double im) {
@bojieli
bojieli / 2.c
Created Mar 28, 2015
最短前缀
View 2.c
#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 Aug 29, 2015
词典
View 3.c
#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;
View calendar.c
#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 Feb 13, 2015
A sample http server
View get-qq-num.py
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)