Skip to content

Instantly share code, notes, and snippets.

View xunkai55's full-sized avatar

Xunkai xunkai55

  • Beijing, China
View GitHub Profile
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf8"/>
<title>
CHOP YOUR HANDS!!
</title>
<link rel="stylesheet" type="text/css" href="settings.css"/>
<script type="text/javascript" src="settings.js">
</script>
</head>
@xunkai55
xunkai55 / Shakespeare_converge.py
Last active August 29, 2015 14:00
test Shakespeare's converge
from __future__ import division
import random
def generate_by_shuffle(words_len_lst):
rst = words_len_lst[:]
random.shuffle(rst)
return rst
def calc_a(wll, sel_ratio):
m = len(wll)
@xunkai55
xunkai55 / build_graph.py
Created August 11, 2014 07:28
Build a Titan graph for testing the behavior of "CONTAINS" in Gremlin.
__author__ = "zxk"
from bulbs.titan import Graph, Config, TITAN_URI
from bulbs.model import Node, Relationship
from bulbs.property import String, Integer
from bulbs.config import DEBUG
import math
import random
from termcolor import colored
@xunkai55
xunkai55 / unique_ptr_usage.cpp
Last active October 21, 2015 03:40
unique_ptr usage
#include <iostream>
#include <vector>
#include <memory>
using namespace std;
class Base {
public:
Base(int x): flag(x) {}
int flag;
void say() { cout << "I'm " << flag << endl; }
@xunkai55
xunkai55 / default_copy_constructor.cpp
Last active October 21, 2015 03:39
default copy constructor
#include <iostream>
using namespace std;
struct B {
int a, b;
B(): a(0), b(0) {}
B(const B &other) = default;
};
int main() {
@xunkai55
xunkai55 / pointer_to_mapped.cpp
Created October 21, 2015 05:10
Use a pointer to directly manipulate elements in an STL map
#include <iostream>
#include <map>
using namespace std;
struct S{
int data;
float f;
S(int d, float x): data(d), f(x) {}
S(): data(0), f(0) {}
};
@xunkai55
xunkai55 / move_vec_to_vec.cpp
Created October 23, 2015 06:18
move a vector from a vector2D to another one
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
void PrintVec2D(vector<vector<int>> &d) {
for (int i = 0; i < d.size(); i++) {
cout << "subvec " << i << ": ";
for (int j = 0; j < d[i].size(); j++)
cout << d[i][j] << " ";
#include <iostream>
#include <vector>
using namespace std;
struct S {
vector<int> a;
S() { a.clear(); }
S(const S& toher) = default;
};
@xunkai55
xunkai55 / static_assert_is_base_of.cpp
Last active January 18, 2016 10:10
use static assert to check if the template parameter is a class derived of another one.
#include <iostream>
struct A {} ;
struct B: public A {};
template<class T>
struct C {
static_assert(std::is_base_of<A, T>::value, "Wrong class parameter");
};
@xunkai55
xunkai55 / raw_pointer_on_unique_ptr.cpp
Created January 18, 2016 11:46
Use raw pointers to access an object owned by a unique_ptr
#include <memory>
#include <iostream>
struct A {
int x;
};
typedef std::unique_ptr<A> APtr;
int main() {