Skip to content

Instantly share code, notes, and snippets.

View xiaom's full-sized avatar
:octocat:

Xiao Meng xiaom

:octocat:
  • Goldsky
  • Canada
  • 21:56 (UTC -07:00)
View GitHub Profile
@xiaom
xiaom / install_mosh_locally.sh
Last active April 2, 2024 16:48
install mosh locally
#!/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 / tmux_fabric.py
Created April 30, 2017 23:00 — forked from nopper/tmux_fabric.py
Tmux helper for fabric
from fabric.api import *
class Tmux(object):
"""Tmux helper for fabric"""
def __init__(self, session_name, run_cmd=run):
self.session_name = session_name
self.run_cmd = run_cmd
self.create_session()
@xiaom
xiaom / sort_dict.py
Last active February 11, 2020 09:39
sort dictionary by value
# http://stackoverflow.com/questions/613183/python-sort-a-dictionary-by-value
# http://wiki.python.org/moin/HowTo/Sorting/
import operator
x = {1: 2, 3: 4, 4:3, 2:1, 0:0}
sorted_x = sorted(x.iteritems(), key=operator.itemgetter(1),reverse=True)
y = [ ('john', 'A', 15), ('jane', 'B', 12), ('dave', 'B', 10),]
@xiaom
xiaom / Zenodo-Metadata-Extraction.md
Last active October 13, 2017 12:58
Research Data Metadata Extraction - GSoc 2017
@xiaom
xiaom / tei_to_fulltext.py
Created August 17, 2017 06:52
tei_to_fulltext.py
NS = {'tei': 'http://www.tei-c.org/ns/1.0'}
def tei_to_fulltext(tei):
from lxml import etree
from six import text_type
parser = etree.XMLParser(encoding='UTF-8', recover=True)
tei = tei if not isinstance(tei, text_type) else tei.encode('utf-8')
root = etree.fromstring(tei, parser)
return get_fulltext(root)
@xiaom
xiaom / hive
Created January 13, 2014 01:51
mirror https://github.com/apache/hive/blob/trunk/bin/hive a great example of writing bash in practice
#!/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 / cmp.py
Last active December 19, 2015 11:09
incorporating with cmp.sql
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 December 19, 2015 11:09
compare two sql statement
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,
@xiaom
xiaom / inheritance.cpp
Last active December 18, 2015 22:09
inheritance
#include <iostream>
using namespace std;
class Base{
public:
virtual ~Base() {
cout << "Base Destruct" << endl;
}
virtual void print(){
cout << "Base" << endl;
@xiaom
xiaom / difftime
Created June 15, 2013 07:11
difference in time
clock_t start, end;
start = clock();
//
// YOUR CODE
//
end = clock();
cerr << "Inverted Index is built in "