Skip to content

Instantly share code, notes, and snippets.

@thepurpleowl
thepurpleowl / markdown-comments.md
Last active September 11, 2018 17:52 — forked from jonikarppinen/markdown-comments.md
How to comment out stuff in Markdown on GitHub?

Comments in GitHub flavour of Markdown

As answers to this Stack Overflow question reveal, using <!--- and ---> works (view source by clicking "Raw"):

@thepurpleowl
thepurpleowl / file_tree.py
Created August 22, 2019 07:37
File structure tree
# Written by Doug Dahms
#
# Prints the tree structure for the path specified on the command line
from os import listdir, sep
from os.path import abspath, basename, isdir
from sys import argv
def tree(dir, padding, print_files=False):
print (padding[:-1] + '+-' + basename(abspath(dir)) + '/')
@thepurpleowl
thepurpleowl / stl_map.cpp
Last active July 2, 2020 19:22
STL hands-on
#include <iostream>
#include <map>
#include <utility>
using namespace std;
/*
Internally map and set are almost always stored as red-black trees. We do not need to worry about the internal structure,
the thing to remember is that the elements of map and set are always sorted in ascending order
while traversing these containers. And that’s why it’s strongly not recommended to change the key value while traversing map or set: If you make the modification that breaks the order, it will lead to improper functionality of container’s algorithms, at least.
*/
@thepurpleowl
thepurpleowl / ScalaBasic0.sc
Last active July 2, 2020 19:27
Scala Tutorials
val a = 4
var b = 3
// if-else
val greater_4: Boolean = a>b
if(!greater_4)
val asquared = a*a
asquared*2
else
val bsquared = b*b
@thepurpleowl
thepurpleowl / BST_struct.cpp
Last active July 2, 2020 19:25
C++ practice
#include <iostream>
using namespace std;
struct node{
int val;
struct node *right, *left;
};
struct node *createNode(int item){
struct node *temp = (struct node *)malloc(sizeof(struct node));
// #include <iostream>
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int,int> a, pair<int,int> b){
return a.second> b.second;
}
void find_w(map<int,int> m){
vector<pair<int,int>> arr;
@thepurpleowl
thepurpleowl / filter_files.py
Created April 17, 2021 02:25
Filter out files while retaining the directory structure: using Python
# Written by thepurpleowl
#
# Filter out files while retaining the directory structure
import os
import json
from shutil import copyfile
import pathlib
# dev__manifest contains path information of unfiltered files
@thepurpleowl
thepurpleowl / inspect_tf_checkpoint.py
Created May 7, 2021 17:05
To check tf.Variable shape, value, type etc in the saved checkpoint
import tensorflow as tf
from tensorflow.python.tools.inspect_checkpoint import print_tensors_in_checkpoint_file
import re
latest_ckp = tf.train.latest_checkpoint('./training_checkpoints')
print_tensors_in_checkpoint_file(latest_ckp, all_tensors=True, tensor_name='')
# to check specific variable in checkpoint
# [print(var.variables) for var in tf.train.list_variables(latest_ckp) if re.match(r'.*decoder/embedding/embeddings/.ATTRIBUTES/.*',var[0])]
@thepurpleowl
thepurpleowl / use_tb_projector.py
Last active July 17, 2022 15:11
Visualize embeddings in tensorboard: using Tensorboard projector
import numpy as np
import tensorboard as tb
from torch.utils.tensorboard import SummaryWriter
import tensorflow as tf
tf.io.gfile = tb.compat.tensorflow_stub.io.gfile
writer = SummaryWriter()
writer.add_embedding(<embeddings>, <labels>) # (doc_vector, Y_true[:TRAIN_SIZE_EVALS[-3]])
writer.close()
%load_ext tensorboard