Skip to content

Instantly share code, notes, and snippets.

@xiaom
xiaom / install eclipse.sh
Created Jan 29, 2014
install eclipse from tarball
View install eclipse.sh
#!/bin/sh
tar -xzvf eclipse*.tar.gz -C /opt
chmod -R +r /opt/eclipse
# use the technique "HERE document"
# http://tldp.org/LDP/abs/html/here-docs.html
(cat <<'EOF'
#!/bin/sh
export ECLIPSE_HOME="/opt/eclipse"
$ECLIPSE_HOME/eclipse $*
@xiaom
xiaom / hive
Created Jan 13, 2014
mirror https://github.com/apache/hive/blob/trunk/bin/hive a great example of writing bash in practice
View hive
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@xiaom
xiaom / install_mosh_locally.sh
Last active Aug 12, 2021
install mosh locally
View install_mosh_locally.sh
#!/bin/sh
# this script does absolutely ZERO error checking. however, it worked
# for me on a RHEL 6.3 machine on 2012-08-08. clearly, the version numbers
# and/or URLs should be made variables. cheers, zmil...@cs.wisc.edu
mkdir mosh
cd mosh
@xiaom
xiaom / cmp.py
Last active Dec 19, 2015
incorporating with cmp.sql
View cmp.py
import shlex, subprocess
raw_args = "sqlcmd -S cypress.csil.sfu.ca -d cmpt354_bank -i %s.sql"%(test)
args = shlex.split(raw_args)
output = subprocess.check_output(args)
print output
@xiaom
xiaom / cmp.sql
Last active Dec 19, 2015
compare two sql statement
View cmp.sql
DECLARE @Query1Checksum bigint
DECLARE @Query2Checksum bigint
Use Northwind354 
-- Get checksum from source query
Select @Query1Checksum = CHECKSUM_AGG(BINARY_CHECKSUM(*))
FROM
(
-- [Start Source Query]
SELECT O.OrderID, O.OrderDate,
View inheritance.cpp
#include <iostream>
using namespace std;
class Base{
public:
virtual ~Base() {
cout << "Base Destruct" << endl;
}
virtual void print(){
cout << "Base" << endl;
@xiaom
xiaom / difftime
Created Jun 15, 2013
difference in time
View difftime
clock_t start, end;
start = clock();
//
// YOUR CODE
//
end = clock();
cerr << "Inverted Index is built in "
@xiaom
xiaom / hostname.sh
Last active Dec 18, 2015
set hostname #OneLineCommand
View hostname.sh
#change your Mac hostname with the command line and make it permanent:
sudo scutil –-set HostName new_hostname
@xiaom
xiaom / gencomb.py
Created Feb 15, 2013
generate combinations
View gencomb.py
# generate combinations
#
# http://docs.python.org/2/library/itertools.html#itertools.combinations
#
# combinations(iterable, r) --> combinations object
# Return successive r-length combinations of elements in the iterable.
combinations(range(4), 3) --> (0,1,2), (0,1,3), (0,2,3), (1,2,3)
@xiaom
xiaom / pq.cpp
Created Jul 16, 2012
use priority queue
View pq.cpp
// top k denest regions: the k-th region is on the top
class RegionCmp {
public:
bool operator()(const Region& lhs, const Region& rhs) const {
return lhs.d > rhs.d;
}
};
typedef priority_queue<Region, vector<Region>, RegionCmp> RegionPQ;