Skip to content

Instantly share code, notes, and snippets.

View zjplab's full-sized avatar
🏠
Working from home

JP Zhang zjplab

🏠
Working from home
View GitHub Profile
@zjplab
zjplab / schema_diff.js
Last active May 9, 2024 08:23
JSON Schema Diff
function customDiff(obj1, obj2) {
const result = {};
// Helper function to check if a value is considered 'empty'
function isEmpty(val) {
return val === null || val === "";
}
// Recursive function to find differences
function findDifferences(lhs, rhs, path = '') {
'''
毫秒级录屏
按Backspace键停止录屏
'''
from PIL import ImageGrab
import numpy as np
import cv2
import datetime
from pynput import keyboard
import threading
@zjplab
zjplab / custom_priority_queue.py
Created June 12, 2020 15:33
Custom data type priority queue with maximum length(pop out automatically if exceeded)
from heapq import *
'''
Need to specify key function for custom data structures for comaprision in a min heap
'''
class _Wrapper:
def __init__(self, item, key):
self.item = item
self.key = key
@zjplab
zjplab / launch.json
Last active July 12, 2020 12:40
VS Code C++ GDB Debugging Launch.son
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Bash on Windows Launch",
"type": "cppdbg",
"request": "launch",
@zjplab
zjplab / sru.py
Last active January 11, 2020 22:51 — forked from calclavia/sru.py
Pure Pytorch Implementation of SRU
import torch.nn as nn
import torch
class SRU(nn.Module):
""" Simple Recurrent Unit https://arxiv.org/pdf/1709.02755.pdf """
def __init__(self, input_size, hidden_size, activation=F.tanh):
super().__init__()
self.input_size = input_size
self.hidden_size = hidden_size
@zjplab
zjplab / comparator_map.cpp
Created January 10, 2020 21:35
C++ Comparator(Custom comparison ops)
struct cmpByStringLength {
bool operator()(const std::string& a, const std::string& b) const {
return a.length() < b.length();
}
};
// ...
std::map<std::string, std::string, cmpByStringLength> myMap;
@zjplab
zjplab / redirect.sh
Created January 1, 2020 01:21
Output/Redirect shell output to some text file
CUDA_VISIBLE_DEVICES=2,5,6,7 ./language/labs/consistent_zero_shot_nmt/scripts/run_nmt_experiment.sh \
--data-dir=/dresden/users/jz704/data \
--dataset-name=iwslt17-star \
--model-name=agreement_multilingual_nmt \
--conf-name=ag_gnmt_luong_att \
--problem-name=translate_iwslt17 \
--gpu-num=4 \
--output-dir=/dresden/users/jz704/results 2>&1 | tee ~/exp_result/iwslt_orininal_agree
@zjplab
zjplab / setup.sh
Created December 17, 2019 17:05
Install Nvida Apex
pip uninstall apex -y
git clone https://github.com/NVIDIA/apex
pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./apex
@zjplab
zjplab / tensorboard4pytorch.ipynb
Created August 16, 2019 01:59
Tensorboard4PyTorch.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.