Skip to content

Instantly share code, notes, and snippets.

@robince
robince / gist:de88832a931808f38d137bc1903c81c4
Created September 20, 2023 07:51
Bias correction permutation
Ntrl_class = 720;
% can change effect strength here
effect_mean = 0.2;
% effect_mean = 0.1;
r = rng(999);
% stimulus values (ie 0: standard, 1: deviant)
y = [zeros(Ntrl_class,1); ones(Ntrl_class,1)];
% class 0 data: standard norml
x0 = randn(Ntrl_class,1);
% class 1 data: a small difference in mena
@robince
robince / set_folder_date_modified.py
Created February 22, 2022 21:22
Fix loss of folder "date modified" on mac (e.g. from iCloud): cd ~/Documents; set_folder_date_modified.py ./
#!/usr/bin/env python
import os
import sys
import time
from datetime import datetime
def set_folder_dates(root):
for x in os.walk(root, topdown=False):
@robince
robince / make-arXiv-package.sh
Last active October 25, 2016 20:25 — forked from holgerdell/make-arXiv-package.sh
Script to prepare arXiv package of a document that depends on texlive2015's version of biblatex (using pdflatex)
#!/bin/bash
#
# This script is useful if:
# - you have a manuscript that you want to upload to the arXiv,
# - you are using biblatex, and
# - you are using texlive2015 while arXiv is still on texlive2011
#
# Put this file in a directory containing the manuscript you want to
# upload to arXiv.org, and adapt the paths below.
module class_ExtendArray
implicit none
private
type, public :: ExtendArray
integer(8) :: capacity
integer(8) :: length
real(8), pointer :: data(:)
real(8), pointer :: buffer(:)
@robince
robince / isfoldernfs
Created March 13, 2015 12:49
isfoldernfs: script to check a destination directory is a nfs mount
#!/bin/bash
# check given path is an NFS mount
FSTYPE="$(df -P -T $1 | tail -n +2 | awk '{print $2}')"
# first three characters
FSTYPE=${FSTYPE:0:3}
if [ "$FSTYPE" = "nfs" ]
then
RC=0
@robince
robince / rebin.m
Created September 12, 2013 14:25
rebin.m - Rebin an already discretised sequence (eg of intger values) into m levels
function x = rebin(x_in,m)
% rebin(x, m) - rebin an integer sequence
%
% Rebin an already discretised sequence (eg of intger values) into m levels
%
x_flat = x_in(:);
% test for positive integer input
if any(mod(x_flat,1)) || (min(x_flat) < 0)
@robince
robince / fbin.f
Created September 12, 2013 10:21
fbin.f : Fast equally-populated bins using the quickselect algorithm
module fbin
use iso_c_binding
implicit none
contains
subroutine eqpop_bin(X, Nb, Ntrl, Xout)
! ARG
integer, intent(in) :: Nb, Ntrl
real(c_double), intent(in) :: X(Ntrl)
integer(c_int8_t), intent(out) :: Xout(Ntrl)
! LOC
@robince
robince / numbase2dec.m
Created August 11, 2013 09:08
numbase2dec.m : Optimised numerical base2dec
function d = numbase2dec(x,b)
%NUMBASE2DEC Convert base B numerical multivariate array to decimal integer.
% NUMBASE2DEC(x,B) converts the multivarate array of base B into its
% univariate decimal (base 10) equivalent.
%
% X should be M x Nt representing Nt different length-M base B words.
%
% Example
% numbase2dec([2; 1; 2],3) returns 23
%
@robince
robince / numdec2base.m
Created August 11, 2013 09:07
numdec2base.m: optimized numerical dec2base
function x = numdec2base(d,b,m)
%NUMDEC2BASE Convert decimal univariate integer to base B multivariate vector.
% NUMDEC2BASE(D,B,M) returns the representation of D as a length-M base-B
% word.
%
% Examples
% numdec2base(23,3) returns [2;1;2]
% numdec2base(23,3,5) returns [0;0;2;1;2]
%
% See also NUMBASE2DEC
@robince
robince / savefaststruct.m
Created July 11, 2013 09:59
savefaststruct.m : savefast a structure (works inside parfor)
function savefaststruct(filename, savestruct)
% savefaststruct: fast saves of large arrays to .mat files
%
% Matlab's 'save' command can be very slow when saving large arrays,
% because by default Matlab attempts to use compression. This function
% provides a much faster alternative, at the cost of larger files.
%
% 'savefaststruct' version saves variables from a structure
% this avoids the need for evalin which does not work inside
% parfor etc.