Skip to content

Instantly share code, notes, and snippets.

@shaybensasson
shaybensasson / MapContainer.m
Created June 4, 2015 13:45
matlab dictionary key value pair
newMap = containers.Map('KeyType','int32','ValueType','single');
val = 5;
if (~isKey(newMap, 31))
newMap(31)=val;
else
newMap(31)=newMap(31) + val;
end
newMap(31)
@shaybensasson
shaybensasson / gmail-permalink
Created July 14, 2015 18:57 — forked from superstrong/gmail-permalink
[Browser bookmarklet] To generate a permalink to a Gmail message: (1) Open the email (2) Click "Show original (3) Run bookmarklet. You can share the search query (useful for when either party is logged into more than one Gmail account) or share the browser URL. Source: http://stackoverflow.com/questions/16827485/using-gmail-message-source-genera…
@shaybensasson
shaybensasson / maximizeFigure.m
Created March 29, 2016 13:08
Maximize a figure in matlab
jf = get(handle(gcf),'JavaFrame');pause(1e-5);jf.setMaximized(true);
a = {'one' 'two' 'three'};
b = [1 2 3];
ab = cat(1, a, num2cell(b));
sprintf('%s = %d\n', ab{:})
%{
output:
one = 1
two = 2
function [ str ] = sprintf_vec( format, varargin )
%SPRINTF_VEC sprintf for vectors
%vectors can be row vectors of column vectors as long as the dimension are
% equal
if (nargin == 0) %DEMO
%{
format = '(%.2f,%.2f)=%.2f\n';
a = 1:10;
b = 11:20;
@shaybensasson
shaybensasson / insert_snippet.m
Created August 9, 2016 15:04
Matlab snippet add in
% INSERT-SNIPPET
% Insert a piece of code in the Matlab editor.
% User Manual:
% 1. Copy the code of this file.
% 2. Create a new shortcut in Matlab (right click on the Shortcut toolbar > New Shortcut).
% 3. Paste the code into 'Callback'.
% 4. Change the code in the 22th line.
% 5. Give a name to your shortcut in 'Label'.
% 6. Click 'Save'.
% 7. Click on the newly created shortcut to paste your code into the editor.
@shaybensasson
shaybensasson / translate.m
Created August 12, 2016 17:06
translates one range to another range
function [ret] = translate(value, leftMin, leftMax, rightMin, rightMax)
% Figure out how 'wide' each range is
leftSpan = leftMax - leftMin;
rightSpan = rightMax - rightMin;
% Convert the left range into a 0-1 range (float)
valueScaled = (value - leftMin) / (leftSpan);
% Convert the 0-1 range into a value in the right range.
ret = rightMin + (valueScaled * rightSpan);
@shaybensasson
shaybensasson / theano_keras_gpu_config.py
Last active October 30, 2016 04:10
Configure GPU for deep learning libs
import os,random
os.environ["KERAS_BACKEND"] = "theano"
os.environ["THEANO_FLAGS"] = "device=gpu,lib.cnmem=0.6"
#os.environ["THEANO_FLAGS"] = "device=cpu"
!nvidia-smi
@shaybensasson
shaybensasson / autotime_magic.py
Last active September 10, 2019 19:33
autotime magic - Simple way to measure cell execution time in ipython notebook
#OBSOLETE:
#http://stackoverflow.com/questions/32565829/simple-way-to-measure-cell-execution-time-in-ipython-notebook
#%install_ext https://raw.github.com/cpcloud/ipython-autotime/master/autotime.py
#use: pip install ipython-autotime
%load_ext autotime
@shaybensasson
shaybensasson / xor_donut_Shay.py
Created November 27, 2016 12:13
Pure Numpy implementation of Anns with 1 hidden layer solving Xor and Donut classification problems
# revisiting the XOR and donut problems to show how features
# can be learned automatically using neural networks.
#
# the notes for this class can be found at:
# https://www.udemy.com/data-science-deep-learning-in-python
import numpy as np
import matplotlib.pyplot as plt
# for binary classification! no softmax here