Skip to content

Instantly share code, notes, and snippets.

View dtxe's full-sized avatar

Simeon Wong dtxe

View GitHub Profile
@dtxe
dtxe / temperature anomalies.csv
Created November 27, 2023 05:22
MAT188H1-2023F-HW5 temperature anomalies data
Year Value
1880 -0.17
1881 -0.09
1882 -0.11
1883 -0.18
1884 -0.29
1885 -0.34
1886 -0.32
1887 -0.37
@dtxe
dtxe / eyetracker_visdeg_to_px.py
Last active July 6, 2023 03:25
Convert psychopy visual degrees to monitor pixels. Originally designed for iohub tobii eyetracker recordings.
import math
from typing import Tuple
def vdeg_to_px(
gaze_vdeg:Tuple[float, float],
screen_size_cm:Tuple[float, float],
screen_size_px:Tuple[int, int],
viewer_distance_cm:float,
) -> Tuple[float, float]:
'''
@dtxe
dtxe / mne_interpolate.py
Created March 28, 2023 14:23
MNE interpolate new scalp channels
import mne
mneraw = mne.read_raw_edf('file.edf')
electrodes = ['Fpz', 'Cz']
# if electrodes to plot are not available, try to interpolate them
electrodes_not_in_list = [e for e in electrodes if e not in mneraw.ch_names]
if len(electrodes_not_in_list) > 0:
try:
@dtxe
dtxe / dump_dicom_headers.py
Last active March 3, 2023 20:10
quick and dirty script to glob a directory of dicom files and extract the header information into a csv file
''' quick and dirty script to glob a directory of dicom files and extract the header information into a csv file '''
import pydicom
import glob
import pandas as pd
from tqdm import tqdm
import numpy as np
###########################
# Parameters
@dtxe
dtxe / installgfortran.sh
Last active November 9, 2022 17:43
backport install libgfortran3 and g++-6 on ubuntu 20.04 focal for simbio and fieldtrip
#!/bin/bash
cat - << EOF > /etc/apt/sources.d/bionic.list
deb http://ca.archive.ubuntu.com/ubuntu/ bionic main
deb http://ca.archive.ubuntu.com/ubuntu/ bionic universe
EOF
apt update
apt install -y g++-6
apt install -y libgfortran3
def list_mutator(inner_list):
inner_list.append(4)
def list_setter(inner_list):
inner_list = inner_list + [4]
def list_returner(inner_list):
inner_list = inner_list + [4]
return inner_list
@dtxe
dtxe / fixQpdf.sh
Created October 20, 2021 19:42
Use ghostscript to repair all PDFs within a ZIP file (of student submissions from UofT Quercus)
#!/bin/bash -x
# fixQpdf.sh [zip file] [output folder]
BASEDIR=$HOME
TEMPDIR=$(uuidgen)
mkdir $BASEDIR/$TEMPDIR
mkdir $BASEDIR/$2
@dtxe
dtxe / circ_buffer_speedtest.py
Created March 9, 2021 01:11
Test which implementation of circular buffers is fastest for receiving chunks of streaming data
import numpy as np
from collections import deque
import datetime
iters = 2000
values = np.random.rand(10000)
def nproll():
@dtxe
dtxe / scrape_bible_plan.sh
Last active December 11, 2023 17:32
Scrape BibleProject discussion posts from YouVersion bible plans
#!/bin/bash
PLANID=12345678
JWTTOKEN={{TOKEN}}
for DAY in {1..365}
do
curl 'https://plans.youversionapi.com/4.0/together/$PLANID/activities?day=$DAY&page=1&order=desc&talk_it_over=0' \
-H 'authority: plans.youversionapi.com' \
-H 'x-youversion-app-version: 4' \
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 5 11:40:07 2019
@author: simeonwong
"""
import pyedflib
import os.path