Skip to content

Instantly share code, notes, and snippets.

View robertoostenveld's full-sized avatar

Robert Oostenveld robertoostenveld

View GitHub Profile
@robertoostenveld
robertoostenveld / handleNotFound.cpp
Last active January 8, 2017 10:12
ESP8266WebServer handler that serves static files from SPIFFS
// this serves all URLs that can be resolved to a file on the SPIFFS filesystem
// server.onNotFound(handleNotFound);
static String getContentType(const String& path) {
if (path.endsWith(".html")) return "text/html";
else if (path.endsWith(".htm")) return "text/html";
else if (path.endsWith(".css")) return "text/css";
else if (path.endsWith(".txt")) return "text/plain";
else if (path.endsWith(".js")) return "application/javascript";
else if (path.endsWith(".png")) return "image/png";
@robertoostenveld
robertoostenveld / handleDirList.cpp
Last active January 8, 2017 10:07
ESP8266WebServer handler that returns SPIFFS directory list
// server.on("/dir", HTTP_GET, handleDirList);
void handleDirList() {
SPIFFS.begin();
String str = "";
Dir dir = SPIFFS.openDir("/");
while (dir.next()) {
str += dir.fileName();
str += " ";
str += dir.fileSize();
// server.on("/debug", HTTP_GET, dirList);
// server.on("/debug", HTTP_PUT, dirList);
// server.on("/debug", HTTP_POST, dirList);
void handleDebug() {
String message = "HTTP Request\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET) ? "GET" : "POST";
@robertoostenveld
robertoostenveld / interface.c
Created September 3, 2017 20:17
snippet of code to be inserted in interface.c to replace gethostbyname
int sockfd;
struct addrinfo hints, *servinfo, *p;
int rv;
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC; // use AF_INET6 to force IPv6
hints.ai_socktype = SOCK_STREAM;
if ((rv = getaddrinfo(host, "http", &hints, &servinfo)) != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
@robertoostenveld
robertoostenveld / example_format.m
Last active January 30, 2018 16:17
This demonstrates the plugin format for the FieldTrip fileio module.
function [varargout] = example_format(varargin)
% EXAMPLE_FORMAT demonstrates the plugin format for the FieldTrip fileio module.
%
% Use as
% hdr = ft_read_data('test.mff', 'headerformat', 'example_format')
% dat = ft_read_data('test.mff', 'headerformat', 'example_format', 'dataformat', 'example_format')
st = dbstack;
if length(st)>1 && strcmp(st(2).name, 'ft_read_header')
@robertoostenveld
robertoostenveld / ft_read_header.m
Created March 2, 2018 08:36
logical flow in ft_read_xxx to support the plugin of new file formats
hdr = ft_read_header(filename, varargin)
filetype = ft_getopt(varargin, 'filetype');
if isempty(filetype)
filetype = ft_filetype(filename);
end
switch filetype
case 'aaa':
% do whatever it used to be doing
@robertoostenveld
robertoostenveld / rename_brainvision_files.m
Created September 25, 2018 14:17
MATLAB function to rename all three files of a BrainVision EEG dataset. It also updates the details inside the files.
function rename_brainvision_files(oldheaderfile, newheaderfile)
% RENAME_BRAINVISION_FILES renames a BrainVision EEG dataset, which consists of a vhdr header
% file, vmrk marker file and a data file that usually has the extension dat, eeg or seg.
%
% Use as
% rename_brainvision_files(oldname, newname)
% where both the old and the new filename should be strings corresponding to the
% header file, i.e. including the vhdr extension.
%
@robertoostenveld
robertoostenveld / truncate.m
Created November 21, 2018 09:25
MATLAB function to truncate the content of a file
function truncate(filename)
% TRUNCATE a file to 0 bytes, i.e. replace the file with an empty one
%
% Use as
% truncate(filename)
assert(exist(filename,'file'), 'file does not exists');
fid = fopen(filename, 'w');
fclose(fid);
@robertoostenveld
robertoostenveld / prefixscale.m
Created June 12, 2019 12:08
MATLAB code that determines the scaling factor to convert an SI unit from one to another prefix
function scale = prefixscale(old, new)
% PREFIXSCALE determines the scaling factor to convert an SI unit from one to another prefix
%
% For example
% prefixscale('kg', 'mg')
% returns 1000000.
% Copyright (C) 2019, Robert Oostenveld
@robertoostenveld
robertoostenveld / eegsynth_patch_example1.py
Created June 16, 2019 13:24
hypothetical example for a patch, assuming that modules are implemented as classes in an EEGsynth library
#!/usr/bin/env python
import sys
from EEGsynth import preprocessing, spectral, plotspectral, plotsignal, historycontrol, postprocessing
inipath = '/home/stephen/PycharmProjects/eegsynth/module/inputcontrol/'
patch = []
patch.append(preprocessing(inifile=inipath + 'preprocessing.ini'))
patch.append(spectral(inifile=inipath + 'spectral.ini'))