Skip to content

Instantly share code, notes, and snippets.

@debidatta
debidatta / getpts3d.m
Created February 10, 2016 23:04
MATLAB script to select points from a 3D scatter plot by clicking on it
function [pts] = getpts3d(x, y, z, n)
%% getpts3d Select points from a 3D scatter plot by clicking on plot
% x - Vector of X coordinates
% y - Vector of Y coordinates
% z - Vector of Z coordinates
% n - Number of points needed to be selected
% pts - Returns a n x 3 matrix of selected points
h = figure;
scatter3(x,y,z);
# -*- coding: utf-8 -*-
import sys
import numpy as np
import argparse
from sklearn.metrics import confusion_matrix
import matplotlib.pyplot as plt
# Put in appropraite directory so that python can import caffe
import caffe
@debidatta
debidatta / k-closest-numbers.py
Created May 15, 2015 07:59
Recipe to find the k-closest numbers to some central value in Python
# From @raymondh on Twitter
heapq.nsmallest(k, iterable, key = lambda x: abs(x - center))
@debidatta
debidatta / git-checkout-ours-theirs
Last active July 4, 2019 14:35
Merging two branches with priority in conflict resolution
# If you want to keep changes of the current branch
grep -lr '<<<<<<<' . | xargs git checkout --ours
# If you want to keep the changes of the branch that is being merged
grep -lr '<<<<<<<' . | xargs git checkout --theirs
@debidatta
debidatta / filtering_mapping_pandas.py
Created May 6, 2015 09:52
Custom filtering and mapping in Pandas
# mapped_series = df['series'].map(lambda x: Value you want x to be mapped to]
mapped_series = df['series'].map(lambda x: x**2)
# filtered_df = df['series'].map(lambda x: True/False function]
filtered_df = df[df['series'].map(lambda x: len(x)>3]]
@debidatta
debidatta / ls-cut-grep-recipe
Created May 5, 2015 07:10
Grep for files in a directory in another file
ls directory | cut -d'.' -f1 | xargs -n 1 -i grep {} file_to_search_in
@debidatta
debidatta / reddit-subscribe-all.js
Last active January 16, 2016 16:21
Javascript for clicking on all subscribe buttons on a Reddit page. Display multiple sub-reddits using this format: http://www.reddit.com/r/4sentencemoviereviews+7films+<other sub-reddits>. Run this script to subscribe to all those sub-reddits at one go from console or from address bar using the prefix "javascript:".
e=document.getElementsByClassName('add');
var i = 0,n = e.length;
function f() {
if(e[i].className.indexOf('active')>=0) e[i].click();
i++;
if( i < n ){
setTimeout( f, 3000 ); //Time out required for registering subscribe on the servers
}
}