Skip to content

Instantly share code, notes, and snippets.

View chizhang529's full-sized avatar
🎯
Focusing

Chi Zhang chizhang529

🎯
Focusing
  • Pinterest Inc
  • Santa Clara, CA
View GitHub Profile
@chizhang529
chizhang529 / common-cpp-headers.cpp
Last active October 24, 2018 17:03
Common C++ STL Headers
// I/O
#include <iostream>
#include <fstream>
#include <sstream>
// Containers
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
@chizhang529
chizhang529 / tensorflow.md
Last active August 17, 2018 03:51
Useful Snippets for Tensorflow

Check GPU Works with Tensorflow

You may want to verify GPU is working with Tensorflow in runtime. Here are some useful python code snippets:

## show all devices available ##
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())

To make sure GPU works in computation:

import tensorflow as tf
@chizhang529
chizhang529 / cuda_setup.md
Last active December 9, 2018 01:57
CUDA cuDNN Setup

Choose Versions of cuDNN, CUDA and Tensorflow

Tensorflow Version

Installation (CUDA8.0 + cuDNN 6.0 + Tensorflow 1.4.0)

Nvidia 384 Driver

CUDA 8.0 and higher versions require at least nvidia-384 driver:

sudo apt-get purge nvidia*
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update &amp;&amp; sudo apt-get install nvidia-384 nvidia-settings
@chizhang529
chizhang529 / vim_tmux_config.sh
Created April 20, 2018 18:08
Shell script for setting up vim and tmux quickly
# init .vim folder
cd ~
mkdir .vim
cd .vim
touch vimrc
git init .
# soft link
ln -s ~/.vim/vimrc ~/.vimrc
@chizhang529
chizhang529 / binary_search.md
Last active April 7, 2018 22:00
Binary Search Basics

1. Classical Binary Search

  • Binary search only works on sorted arrays. For unsorted arrays, the fastest way to find an element is linear scan O(n).
  • It can be implemented either by iteration or recursion. Since recursion has higher space complexity but no gains in time complexity, we prefer iteration implementation.
  • The physical interpretation of left and right is that the element to find must reside in the range [left, right].
  • The worst case of time complexity happens when the element to find does not exist in the array.
/* iteration version: T[O(logn)], S[O(1)] */
int binarySearch(vector<int> &arr, int target)
@chizhang529
chizhang529 / sorting.cpp
Last active October 22, 2021 11:28
Selection Sort + Merge Sort + Quick Sort + Rainbow Sort + Stack Sort
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
template<typename T>
void printVector(vector<T> &vec) {
cout << "[";
const size_t sz = vec.size();
for (size_t i = 0; i < sz; ++i) {
@chizhang529
chizhang529 / vector_cpp_stl.md
Last active September 24, 2023 14:57
Essentials of Vectors in C++ STL

1. Initialization

  • Declaring an empty vector and then pushing values
// creates an empty vector
std::vector<int> vec;
// push values into vector
vec.push_back(10);
vec.push_back(20);
vec.push_back(30);
@chizhang529
chizhang529 / linked_list.cpp
Last active May 3, 2018 04:12
Linked List Basics
class ListNode {
public:
int val;
ListNode *next;
ListNode(int val) {
this->val = val;
this->next = nullptr;
}
};