Skip to content

Instantly share code, notes, and snippets.

@sg-s
sg-s / bash history autocomplete
Last active August 1, 2023 04:04
Autocomplete commands in bash by using arrow keys
# supports history search using up and down arrows
# add this to your ~/.bashrc
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
bind '"\eOA": history-search-backward'
bind '"\eOB": history-search-forward'
@sg-s
sg-s / MATLAB publish tweaks.md
Last active August 29, 2015 14:05
This contains some workarounds for annoying bugs in MATLAB's publish function

Some workaround to common problems with MATLAB's publish()

Slow scatter

Problem: Horrible slowdowns when using scatter() in a script that you want to publish Solution: Don't use scatter. Use plot(x,y,'.') instead.

Combinatorial Figure mess

Problem: Horrible slowdown when publishing a document that has many figures in it. Symptom: You will see MATLAB cycling through all open figures. This means that it does something like this:

Verifying that +srinivas is my Bitcoin username. You can send me #bitcoin here: https://onename.io/srinivas
@sg-s
sg-s / share.md
Last active August 29, 2015 14:05
How to make your own file sharing service

How to make your own file sharing service

What you want to do

Create a small utility that takes a folder you want to share, and creates a not-obvious URL that you can send to other humans.

What you need:

  • A server you can SSH into
  • a *nix machine
@sg-s
sg-s / parent_func.md
Last active August 29, 2015 14:05
Determine if this MATLAB function is being called by another function, and if so, what is it? The power of dbstack

How to find out if your MATLAB function is being called by another function or not

calling_func = dbstack;

if calling_func is non-empty, it is being called by some other function (as opposed to being called directly by the user from the command prompt)

How to find out the name of the function calling the current function

@sg-s
sg-s / publish_version_control.md
Last active August 29, 2015 14:05
Handy hashing for PDFs made by MATLAB code

Automatic Version control for publish()

MATLAB's publish takes a script and makes a PDF from it. Here, we want to add some basic info about the file that created the PDF to the PDF, programatically.

Add the name of the file that created the PDF to the PDF

add this snippet of code to the bottom of the script that you will publish with MATLAB's publish() function (or my MakePDF.m wrapper)

@sg-s
sg-s / function inverse.md
Created September 8, 2014 21:51
How to find the inverse of an arbitrary function in MATLAB

Assume you have a custom function, say, hill.m, that looks like this:

function r = hill(x,xdata)
A = x(1);
k = x(2);
n  =x(3);
r = A*xdata.^n;
r = r./(xdata.^n + k^n);
% when xdata is negative, return 0
@sg-s
sg-s / the-bash-guide.md
Last active December 21, 2015 17:54
A collection of various bash tips and tricks collected from various sources.

The Bash Guide

A collection of various bash tips and tricks collected from various sources. I'm writing this as I learn new stuff, so this is in no way authoritative or even corrent. In fact, you shouldn't read this.

Basics

Version, updates and installation

Check your version:

@sg-s
sg-s / gist:c36ce3e8063a155b7732
Last active August 29, 2015 14:09
Quickly check if you have internet access
ping -t 1 -q google.com | grep "0.0% packet loss" | wc -l

returns 1 for internet, 0 for no internet

@sg-s
sg-s / cron-see-path
Created December 11, 2014 00:35
How to get cron to see the $PATH you see
echo PATH=$PATH > tmp.cron
echo >> tmp.cron
crontab -l >> tmp.cron
crontab tmp.cron