Skip to content

Instantly share code, notes, and snippets.

View bxshi's full-sized avatar

Dash Shi bxshi

  • University of Notre Dame
  • South Bend, Indiana
View GitHub Profile
@bxshi
bxshi / cp_rename
Created April 23, 2014 00:59
cp & rename files
#!/bin/bash
FILES="./*.txt"
DEST="/afs/dropbox"
SUFIX=".txt"
for f in $FILES
do
echo "${f:2}"
TMP=${f:2}
@bxshi
bxshi / SparkListenerBug.scala
Last active August 29, 2015 14:02
SPARK-2228 NoSuchElementError, key not found
import org.apache.spark.graphx._
import org.apache.spark.{SparkConf, SparkContext}
object StackOverFlow {
def main(args: Array[String]) {
val conf = new SparkConf().setAppName("HDTM")
.setMaster("local[4]")
val sc = new SparkContext(conf)
@bxshi
bxshi / dblp_parser.py
Created January 27, 2015 17:04
DBLP2CSV Parser
#!/usr/bin/python3
import csv
import os
import sys
from lxml import etree
if len(sys.argv) is not 5:
print("Usage simple_parser.py dblp.xml article.csv author.csv citation.csv")
exit(1)
#ifndef SOLUTION_UNIQUE_STR_CPP
#define SOLUTION_UNIQUE_STR_CPP
#include <string>
// Github Repository https://github.com/bxshi/interview-code/blob/master/src/CtCI5/1_1_unique_char.cpp
size_t _partition(std::string& str, size_t i, size_t j) {
size_t low = i;
size_t high = j;
#ifndef SOLUTION_REVERSE_CHAR_STRING
#define SOLUTION_REVERSE_CHAR_STRING
/**
* Reverse a \0 terminated char* string.
*
* Keep two pointers, one at the beginning and the other one
* at the end of this char* string. Swap the values that these
* two pointers points too, and then move them to the middle by 1.
*
@bxshi
bxshi / 1.1.c
Created April 16, 2012 01:38
CareerCup 150 1.1 @1point3acres
/*
* CareerCup 150 4/16-4/22 1.1
*
* slaink@1point3acres
*
*/
/*
* 首先想到的是排序,如果可以用其他数据结构的话,我倾向于使用一个二叉树,遇到重复节点时候,计算结束。
* 既然不能使用其他数据结构,那么还是使用排序呗。剩下的就是算法复杂度的问题了。
/*
* Reference
* [1] http://programminggeeks.com/c-code-for-quick-sort/
*
* just add some comments, ALL CODES WAS DONE BY reference[1].
* If that's not cool, just tell me and I'll delete this.
*/
#include "stdio.h"
int split ( int*, int, int ) ;
@bxshi
bxshi / 1.2.c
Created April 16, 2012 12:14
CareerCup 150 1.2 @1point3acres
/*
* CareerCup 150 4/16-4/22 1.2
*
* slaink@1point3acres
*
*/
/*
* 反转字符串的话最容易的就是从两端(用i,j)开始swap,最后到i,j重合或者i>j.
* 这样会有一个问题就是strlen是怎么算出来的?如果是遍历寻找\0的话,那么这就有了一个n了.
@bxshi
bxshi / 1.3.c
Created April 16, 2012 13:29
CareerCup 150 1.3 @1point3acres
/*
* CareerCup 150 4/16-4/22 1.3
*
* slaink@1point3acres
*
*/
/*
*感觉上和1.1类似,但是不需用任何其他的buffer,只能一两个变量。这样说来bitmap就肯定不行了。
*再考虑一下qsort的可能性,qsort的确可以nlogn时间找到dup,但是另一个问题是如何删除字符串。
@bxshi
bxshi / 1.4.c
Created April 17, 2012 02:28
CareerCup 150 1.4 @1point3acres
/*
* CareerCup 150 4/16-4/22 1.4
*
* slaink@1point3acres
*
*/
/*
* 两个字符串是回文的话,应该是类似abcde edcba 这样子吧?
* 如果真的如此,那么直接从字符串a开头开始于字符串b结尾开始比较,如果遇到不相同则输出