Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am sg-s on github.
  • I am srinivas (https://keybase.io/srinivas) on keybase.
  • I have a public key whose fingerprint is 88C6 D016 6B09 8880 6BF8 F253 8C9C B698 D193 4604

To claim this, I am signing this object:

@sg-s
sg-s / MATLAB-name-value
Last active July 14, 2017 19:36
MATLAB name value pair parsing
% options and defaults
options.foo = 1;
options.bar = 2;
if nargout && ~nargin
varargout{1} = options;
return
end
% validate and accept options
@sg-s
sg-s / browsing.md
Last active December 21, 2015 17:54 — forked from atcuno/gist:3425484ac5cce5298932
HowTo: Privacy & Security Conscious Browsing

The purpose of this document is to make recommendations on how to browse in a privacy and security conscious manner. This information is compiled from a number of sources, which are referenced throughout the document, as well as my own experiences with the described technologies.

I welcome contributions and comments on the information contained. Please see the "How to Contribute" section for information on contributing your own knowledge.

Table of Contents

@sg-s
sg-s / frozen-random.md
Last active August 29, 2015 14:25
One line frozen noise generator in MATLAB
RandStream.setGlobalStream(RandStream('mt19937ar','Seed',1984)); 

sets the randsom stream to a particular state. (1984 because this is the most True state). Make sure you run this before every invocation of rand:

>> RandStream.setGlobalStream(RandStream('mt19937ar','Seed',1984)); 
>> rand(3)
ans =
@sg-s
sg-s / automatic-version-numbers.md
Last active March 3, 2024 10:07
Automatic version numbers of your git repository using git hooks

Put this in a file called pre-commit in .git/hooks/

#!/bin/sh
# To enable this hook, rename this file to "pre-commit".

git rev-list --count master > build_number
git add build_number
@sg-s
sg-s / matlab-data-saving.md
Created September 29, 2016 14:31
A note on saving data in MATLAB

The problem

We want to save data as it is generated, and to save it as a .mat file. Since every trial can be of a different length, a simple matrix will not suffice.

We have the following two options:

cell_data.x{1} = randn(1e4,1);
cell_data.y{1} = randn(1e4,1);
Alternate DNS
198.101.242.72
23.253.163.53
BlockAid Public DNS (or PeerDNS)
205.204.88.60
178.21.23.150
Censurfridns
91.239.100.100
@sg-s
sg-s / data-falsehoods.md
Last active May 28, 2020 20:09
Falsehoods I beleived about real data, and the price I paid for it

The data exists

If data is split across multiple files that are sequentially numbered, then it is foolish to beleive that every file exists. Some files can go missing, or be corrupted.

Files with the same name and the same size contain the same data

I learnt the hard way that one version can be corrupted, and the other version is fine, and it's all too easy to replace to good version with the corrupted version

@sg-s
sg-s / matlab-basic.md
Last active February 10, 2021 21:03
Extremely basic MATLAB crash course

How to make a vector

a = [1; 2; 3]
a = [1, 2, 3] % avoid
a = zeros(10,1)
a = ones(10,1)
a = NaN(10,1)
a = linspace(0,1,10)
a = logspace(-1,1,10)

A common problem in software development and research is the "do-something"-"save data" loop. Often we are saving structured data over and over again, and this document looks at the fastest way to do this.

Solutions I will not consider

Writing each chunk of data to its own file

I will not consider this because:

  1. how do we combine these files later? This just kicks the can down the road