Skip to content

Instantly share code, notes, and snippets.

@sturgle
sturgle / sqlsplit.py
Created June 23, 2015 09:02
split large sql files into small ones
fin = open('Downloads/sub.sql', 'r')
cnt = 0
fcnt = 0;
fout = open('output/out_' + `fcnt` + '.sql', 'w');
with fin as ins:
for line in ins:
cnt = cnt + 1
fout.write(line)
if line.startswith("commit") and cnt > 50000:
fout.close()
@sturgle
sturgle / AssignmentGenerator.java
Created June 17, 2015 01:56
AssignmentGenerator
import java.io.InputStream;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
@sturgle
sturgle / Server.java
Created March 29, 2015 12:51
simple telnet chat server
package chatdemo.server;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.ServerSocket;
import java.net.URL;
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <sstream>
#include <utility>
#include <set>
using namespace std;
vector<int> cnt;
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <sstream>
#include <utility>
using namespace std;
void getNextPoint(pair<int, int> &point, int m , int n, int &dir) {
int x = point.first;
@sturgle
sturgle / surpasser.cpp
Created January 29, 2015 05:25
A[i] < A[j] && i < j, then A[i] has a surpasser A[j], calc the max surpasser inside an array
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <sstream>
using namespace std;
struct NumExt {
int val;
int index;
@sturgle
sturgle / largestKSum.cpp
Created December 15, 2014 15:54
find the k sub-sequence of the array to make the sum largest, the numbers are from 0-9
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
int kSum(vector<int> arr, int k) {
assert(k <= arr.size());
vector<int> count(10);
for (int i = 0; i < arr.size(); i++) {
count[arr[i]]++;
@sturgle
sturgle / NextInBST.cpp
Created December 15, 2014 05:01
find the node just larger than the specified node in BST
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int _val) : val(_val), left(NULL), right(NULL) {};
#include <iostream>
#include <string>
#include <cassert>
using namespace std;
bool equal(string& s, int i, string& t, int j) {
while (i < s.size() && j < t.size() && s[i] == t[j]) {
i++;
j++;
}
#include <iostream>
#include <bitset>
using namespace std;
int countOne(unsigned int n) {
int count = 0;
while (n) {
n = n & (n - 1);
count++;
}