Skip to content

Instantly share code, notes, and snippets.

View dtxe's full-sized avatar

Simeon Wong dtxe

View GitHub Profile
@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 / 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 / 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 / latex_to_pgml.cs
Last active December 20, 2023 16:10
Convert Latex mathematical notations to PGML for use in WebWork: Clipboard Fusion Macro
// This Clipboard Fusion macro makes it easy to copy Latex from the Learning Standards Project into WebWork compatible formats
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
// The 'text' parameter will contain the text from the:
// - Current Clipboard when run by HotKey
// - History Item when run from the History Menu
// The returned string will be:
@dtxe
dtxe / quickinstall_gcm.sh
Created January 4, 2024 18:36
Install and configure GCM using defaults for DSI course
#!/bin/bash
# download gcm
wget https://github.com/git-ecosystem/git-credential-manager/releases/download/v2.4.1/gcm-linux_amd64.2.4.1.deb
sudo apt install ./gcm-linux_amd64.2.4.1.deb
# configure
git-credential-manager configure
git config --global credential.credentialStore cache
git config --global credential.cacheOptions "--timeout 14400"
@dtxe
dtxe / Lesson3notes.md
Created January 19, 2024 14:01
DSI Session 2 - Unix lesson 3 notes

Notes from Shell Lesson 3

Doing things faster in bash

Keyboard shortcuts

  • A good (albeit comprehensive) cheatsheet is found here: https://gist.github.com/tuxfight3r/60051ac67c5f0445efee
  • You'll eventually find a subset of the shortcuts that you use most often.
  • My personal list is:
    • Ctrl + A / Home key: move to the beginning of the line
    • Ctrl + E / End key : move to the end of the line
  • Ctrl + K : delete from cursor to end of the line
@dtxe
dtxe / porkbun_ddns.py
Last active January 26, 2024 20:06
Dynamic DNS address updater for Porkbun
import os.path
import yaml
import requests
import logging
from typing import Tuple
logging.basicConfig(level=logging.INFO)
class Porkbun():
@dtxe
dtxe / google_to_porkbun.py
Created January 26, 2024 20:00
Transfer DNS records from Google Domains YAML format to Porkbun via the Porkbun API
import yaml
import requests
import json
# Load config file
with open('domain.YAML', 'r') as f:
data = list(yaml.safe_load_all(f))
with open('apikeys.yml', 'r') as f:
apikeys = yaml.safe_load(f)
@dtxe
dtxe / kt_pca.py
Created March 5, 2024 20:34
Kernel Trick PCA
from typing import Tuple
import numpy as np
def kt_pca(X:np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
"""
This is an implementation of the linear kernel PCA method ("kernel trick")
described in "Kernel PCA Pattern Reconstruction via Approximate Pre-Images"
by Schölkopf et al, ICANN, 1998, pp 147-15
Parameters
@dtxe
dtxe / fix_qt_errors.md
Last active August 15, 2024 18:49
Fixing QT errors for DSI studio / freeview on Ubuntu 20.04

Install packages

pip install aqtinstall
aqt install-qt linux desktop 6.5.0 -m qtcharts --outputdir /opt/qt6
sudo apt install libxcb-cursor-dev

Set environment variables

export QTDIR="/opt/qt6/6.5.0/gcc_64"