Skip to content

Instantly share code, notes, and snippets.

View xunkai55's full-sized avatar

Xunkai xunkai55

  • Beijing, China
View GitHub Profile
@xunkai55
xunkai55 / setup_bpy.sh
Last active March 16, 2022 00:39
Setup bpy (Blender as a python module) on Mac OS X
# Do not excute the script directly. It is just for demonstration.
# If you followed the documentation and got the errors below, please take a look at this guide.
# Color management: using fallback mode for management
# bpy: couldnt find 'scripts/modules', blender probably wont start.
# Freestyle: couldn't find 'scripts/freestyle/modules', Freestyle won't work properly.
# ImportError: No module named 'bpy_types'
# ImportError: No module named 'bpy_types'
# pyrna_srna_ExternalType: failed to find 'bpy_types' module
# ImportError: No module named 'bpy_types'
@xunkai55
xunkai55 / ingress_map_revision.js
Created March 29, 2016 16:09
revise ingress map
document.createElement('script');script.src='https://secure.jonatkins.com/iitc/release/total-conversion-build.user.js';document.body.appendChild(script);script1=document.createElement('script');script1.src='https://secure.jonatkins.com/iitc/release/plugins/player-tracker.user.js';document.body.appendChild(script1);script2=document.createElement('script');script2.src='https://secure.jonatkins.com/iitc/release/plugins/portal-highlighter-high-level.user.js';document.body.appendChild(script2);script3=document.createElement('script');script3.src='https://secure.jonatkins.com/iitc/release/plugins/fly-links.user.js';document.body.appendChild(script3);script4=document.createElement('script');script4.src='https://secure.jonatkins.com/iitc/release/plugins/portal-names.user.js';document.body.appendChild(script4);script5=document.createElement('script');script5.src='https://secure.jonatkins.com/iitc/release/plugins/draw-tools.user.js';document.body.appendChild(script5);
@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() {
@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");
};
#include <iostream>
#include <vector>
using namespace std;
struct S {
vector<int> a;
S() { a.clear(); }
S(const S& toher) = default;
};
@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] << " ";
@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 / 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 / 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 / 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