Skip to content

Instantly share code, notes, and snippets.

// Include javascript file in chrome console
var script= document.createElement('script');
script.type= 'text/javascript';
script.src= 'script.js';
document.head.appendChild(script);
@HaiyangXu
HaiyangXu / jupyter_download_csv.py
Created November 18, 2017 13:18
Download CSV file from data frame in jupyter
from IPython.display import HTML
import base64
import pandas as pd
def create_download_link( df, title = "Download CSV file", filename = "data.csv"):
csv = df.to_csv(index =False)
b64 = base64.b64encode(csv.encode())
payload = b64.decode()
html = '<a download="{filename}" href="data:text/csv;base64,{payload}" target="_blank">{title}</a>'
html = html.format(payload=payload,title=title,filename=filename)
@HaiyangXu
HaiyangXu / jupyter_download_csv.py
Created November 18, 2017 13:18
Download CSV file from data frame in jupyter
from IPython.display import HTML
import base64
import pandas as pd
def create_download_link( df, title = "Download CSV file", filename = "data.csv"):
csv = df.to_csv(index =False)
b64 = base64.b64encode(csv.encode())
payload = b64.decode()
html = '<a download="{filename}" href="data:text/csv;base64,{payload}" target="_blank">{title}</a>'
html = html.format(payload=payload,title=title,filename=filename)
@HaiyangXu
HaiyangXu / 2sat.cpp
Created May 9, 2015 15:38
2sat problem use SCC
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <sstream>
#include <random>
#include <assert.h>
#include <algorithm>
#include <ctime>
#include <utility>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
//compute the next arry for KMP
int nextp(string str,vector<int>&pi){
str.insert(0,1,'@');// convert to 1 based index
pi=vector<int>(str.size(),0);
pi[0]=-1;pi[1]=0;
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int key[10][11] = {
//numbers | avalible number increase sequence
{ 1, 0 }, //0
{ 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },//1
{ 7, 0, 2, 3, 5, 6, 8, 9 },//2
@HaiyangXu
HaiyangXu / character_elimination.cpp
Created March 23, 2015 06:40
#1039 : 字符消除
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int reduce(string &str){
if(str.empty())return 0;
int pos=0;
bool keep=true;
for(int i=0;i<str.size()-1;i++){
if(str[i]==str[i+1]){
@HaiyangXu
HaiyangXu / Shortest_Proper_Prefix.cpp
Created January 18, 2015 17:50
Shortest Proper Prefix
#include <iostream>
#include <memory.h>
#include <string>
#include <stdio.h>
#include <queue>
#include <stack>
using namespace std;
@HaiyangXu
HaiyangXu / Disk_Storage.cpp
Created January 5, 2015 14:50
题目2 : Disk Storage
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstring>
#define BITSPERWORD sizeof(int)*8
#define SHIFT 5
#define MASK 0x1f
#define N 10000000
int a[1+N/BITSPERWORD];
void set(int i){
a[i/BITSPERWORD]|=(1<<(i%BITSPERWORD));
}