Skip to content

Instantly share code, notes, and snippets.

@HaiyangXu
HaiyangXu / combination.cpp
Created December 27, 2014 10:57
combination for cpp
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
/*
combination for get m from num of numbers
*/
class combination
{
public:
@HaiyangXu
HaiyangXu / redirectstdio.h
Last active August 29, 2015 14:11
Redirect Standard Input
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
inline void redirect(void)
{
#ifdef DEBUG
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
@HaiyangXu
HaiyangXu / non_manifold.cpp
Created August 28, 2014 13:44
Remove non-manifold edges Use VCG Library
#include <iostream>
#include <vector>
#include <vcg/complex/complex.h>
#include <wrap/io_trimesh/import.h>
#include <wrap/io_trimesh/export.h>
using namespace std;
// Forward declarations needed for creating the used types
class CVertexO;
@HaiyangXu
HaiyangXu / Dijkstra.cpp
Created June 6, 2014 09:55
The stupid direct Dijkstra Algorithm
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <sstream>
#include <random>
#include <assert.h>
#include <algorithm>
#include <time.h>
#include <set>
@HaiyangXu
HaiyangXu / scc.cpp
Last active August 29, 2015 14:02
Kosaraju's algorithm for compute SCC
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <sstream>
#include <random>
#include <assert.h>
#include <algorithm>
#include <ctime>
#include <utility>
@HaiyangXu
HaiyangXu / RandomContraction.cpp
Last active August 29, 2015 14:01
Karger's Random Contraction Algorithm for Min Graph Cuts
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <sstream>
#include <random>
#include <assert.h>
#include <algorithm>
#include <time.h>
using namespace std;
@HaiyangXu
HaiyangXu / Pointer.cpp
Created May 28, 2014 08:54
Test pointer address
#include<cstdio>
int main()
{
int a[5]={1,2,3,4,5};
printf("sizeof(&a):%d\tsizeof(a)%d\n",sizeof(&a),sizeof(a));
int *ptr=(int *)(&a+1);
printf("a=%d,&a=%d,a+1=%d,&a+1=%d\n",a,&a,a+1,&a+1);
printf("%d,%d",*(a+1),*(ptr-1));
@HaiyangXu
HaiyangXu / QuickSort.cpp
Last active August 29, 2015 14:01
QuickSort with the first element as Piviot
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
void getFromtxt(char *name, vector<int>&nums)
{
ifstream input;
input.open(name);//read from a txt file
@HaiyangXu
HaiyangXu / os.asm
Last active August 29, 2015 14:01
A simple operating system or say, just a simple boot loader
;Code from http://mikeos.berlios.de/write-your-own-os.html
;See my cool solution to boot this 'OS‘,i think it's much cool.
; http://haiyangxu.github.io/posts/2014/2014-05-21-write_a_bootloader
BITS 16
start:
mov ax, 07C0h ; Set up 4K stack space after this bootloader
add ax, 288 ; (4096 + 512) / 16 bytes per paragraph
mov ss, ax
@HaiyangXu
HaiyangXu / Server.py
Created May 18, 2014 14:00
A simper python http server can handle mime type properly
# -*- coding: utf-8 -*-
#test on python 3.4 ,python of lower version has different module organization.
import http.server
from http.server import HTTPServer, BaseHTTPRequestHandler
import socketserver
PORT = 8080
Handler = http.server.SimpleHTTPRequestHandler