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
#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 / test.json
Last active August 10, 2016 04:23
{
"name": "flare",
"children": [
{
"name": "analytics",
"children": [
{"name": "AgglomerativeCluster", "size": 3938},
{
"name": "cluster",
"children": [
@bxshi
bxshi / Hits_at_K_TensorFlow.py
Created January 12, 2017 21:34
Implement Hits@K evaluation metric for Knowledge Graph Completion tasks.
import tensorflow as tf
with tf.Session() as sess:
"""
idx (h,r) top_3
[ [
[0,1], [0,8,3],
[1,3], [7,2,1],
[2,4], [4,3,9],
] ]
@bxshi
bxshi / mr_hits.py
Created January 19, 2017 18:36
Calculate MeanRank and Hits@K using TensorFlow. From github.com/nddsg/ProjC (private repo right now)
def create_eval_ops(model_input, pred_y, all_triples, eval_triples, n_entity,
top_k, idx_1=0, idx_2=1, idx_3=2):
""" Evaluation operations for any model.
For given <h,r> predict t, idx_1 = 0, idx_2 = 1, idx_3 = 2
For given <t,r> predict h, idx_1 = 2, idx_2 = 1, idx_3 = 0
:param model_input: N by 3 matrix, each row is a h,r,t pair
:param pred_y: N by ENTITY_VOCAB matrix
:param all_triples: M by 3 matrix, contains all triples in the KG
@bxshi
bxshi / gpu_runner.py
Last active February 15, 2017 18:14
Select GPU and run command
#!/usr/bin/env python3
import argparse
import subprocess
def gpu_ok(gpu_usage, mem_usage, max_gpu_usage, max_mem_usage):
return gpu_usage <= max_gpu_usage and mem_usage < max_mem_usage
if __name__ == '__main__':
@bxshi
bxshi / tmux_local_install.sh
Last active December 3, 2021 15:17 — forked from smsharma/ tmux_local_install.sh
Install tmux locally without root access
#!/bin/bash
# Script for installing tmux on systems where you don't have root access.
# tmux will be installed in $INSTALL_DIR/local/bin.
# It's assumed that wget and a C/C++ compiler are installed.
# exit on error
set -e
TMUX_VERSION=2.3
@bxshi
bxshi / d-ibm3dx7008.txt
Created August 27, 2017 05:39
Cleaned up version of d-ibm3dx7008.txt, this can be read by `np.loadtxt` or `pd.read_csv`.
Date rtn vwretd ewretd sprtrn
19700102 0.000686 0.012137 0.033450 0.010211
19700105 0.009596 0.006375 0.018947 0.004946
19700106 0.000679 -0.007233 -0.005776 -0.006848
19700107 0.000678 -0.001272 0.003559 -0.002047
19700108 0.002034 0.000564 0.002890 0.000540
19700109 -0.001353 -0.002797 -0.002923 -0.003021
19700112 -0.003388 -0.007766 -0.009646 -0.007576
19700113 0.017335 0.000737 -0.001090 0.000981
19700114 -0.001002 -0.002005 -0.005280 -0.001525
@bxshi
bxshi / d-3stocks9908.txt
Created August 27, 2017 06:26
Cleaned up version of d-3stocks9908.txt.
date axp cat sbux
19990104 -0.009756 0.029891 -0.040089
19990105 -0.019089 -0.002639 -0.034803
19990106 0.043063 0.026455 -0.008413
19990107 0.012063 0.009021 0.003636
19990108 0.030393 0.042146 0.021739
19990111 -0.016773 0.039216 0.002364
19990112 -0.036471 -0.044811 0.003538
19990113 -0.03602 -0.050617 -0.008813
19990114 -0.027232 -0.027308 0.000593
@bxshi
bxshi / m-gm3dx7508.txt
Created August 27, 2017 21:12
Cleaned up version.
date gm vw ew sp
19750131 0.252033 0.141600 0.299260 0.122812
19750228 0.028571 0.058411 0.053918 0.059886
19750331 0.054487 0.030191 0.081497 0.021694
19750430 0.045593 0.046497 0.031093 0.047265
19750530 0.037209 0.055140 0.072876 0.044101
19750630 0.107955 0.051473 0.071792 0.044323
19750731 0.053846 -0.060385 -0.008960 -0.067654
19750829 -0.029684 -0.023557 -0.048118 -0.021070
19750930 0.015228 -0.038010 -0.038867 -0.034645
@bxshi
bxshi / q-gnp4791.txt
Created August 31, 2017 05:20
aka dgnp82.txt
0.00632
0.00366
0.01202
0.00627
0.01761
0.00918
0.00820
-0.01170
-0.00587
0.00757