Skip to content

Instantly share code, notes, and snippets.

View gpiantoni's full-sized avatar

Gio Piantoni gpiantoni

View GitHub Profile
function New-GitTagFromExisting {
param (
[Parameter(Mandatory=$true)]
[string]$ExistingTag
)
try {
# Set the GIT_COMMITTER_DATE using the git log command
$GIT_COMMITTER_DATE = git log -1 --format=%aI $ExistingTag
if (-not $GIT_COMMITTER_DATE) { throw "Failed to retrieve committer date for tag $ExistingTag" }
@gpiantoni
gpiantoni / time_intervals.py
Created October 20, 2022 15:21
Flexible approach
"""Module to select time intervals from dataset.
MIT License
Copyright (c) 2022 Giovanni Piantoni
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@gpiantoni
gpiantoni / print_trc_events.py
Created September 10, 2021 12:59
Print events and notes in TRC
#!/usr/bin/env python3
"""
Print notes and events in TRC
Use as:
python3 print_trc_events.py /path/to/TRC.py
Requires wonambi (pip3 install wonambi)
"""
@gpiantoni
gpiantoni / ns2wav.py
Created March 25, 2021 08:57
Convert blackrock ns files to sound wav
#!/usr/bin/env python3
from argparse import ArgumentParser
from pathlib import Path
from wonambi import Dataset
from numpy import abs, nanmax
from scipy.io.wavfile import write
@gpiantoni
gpiantoni / upload_to_flywheel.py
Last active November 11, 2020 13:38
upload to flywheel
#!/usr/bin/env python3
from os import environ
from zipfile import ZipFile, ZIP_DEFLATED
from tempfile import mkstemp
from pathlib import Path
from argparse import ArgumentParser
from logging import getLogger, INFO, DEBUG, basicConfig
from flywheel import Client, ApiException
@gpiantoni
gpiantoni / parse_antsTransformInfo.py
Last active March 18, 2020 16:41
Convert ants (ITK) transformation matrix into affine matrix
#!/usr/bin/env python3
from argparse import ArgumentParser
from pathlib import Path
from subprocess import check_output
from textwrap import dedent
from numpy import (
array,
array2string,
@gpiantoni
gpiantoni / pinyin.tsv
Created February 18, 2020 18:46
pinyin + IPA (WIP)
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 75 columns, instead of 43 in line 4.
i a o e ai ei ao ou an en ang eng ong er i ia ie iao iu ian in ing iang iong u ua uo uai ui uan un uang ueng ü üe üan ün
∅ a [a] o [o] e [ɤ] ai [ai] ei [ei] ao [ao] ou [ou] an [an] en [en] ang [aŋ] eng [eŋ] er [aɚ̯] yi [i] ya [ja] ye [je] yao [jao̯] you [jou̯] yan [in] yin [jin] ying yang yong wu wa wo wai wei wan wen wang weng yu yue yuan yin
b ba [pa] bo [po] bai [pai] bei [pei] bao [pao] ban [pan] ben [pen] bang [paŋ] beng [peŋ] bi [bi] bie [pie] biao [piau̯] bian [pian] bin [pin] bing [piŋ] biang [piaŋ] bu [pu]
p pa [pʰa] po [pʰo] pai [pʰai] pei [pʰei] pao [pʰao] pou [pʰou̯] pan [pʰan] pen [pʰen] pang [pʰaŋ] peng [pʰeŋ] pi [pʰi] pie [pʰie] piao [pʰiau̯] pian [pʰian] pin [pʰin] ping [pʰiŋ] piang [pʰiaŋ] pu [pʰu]
m ma [ma] mo [mo] me [me] mai [mai] mei [mei] mao [mao] mou [mou] man [man] men [men] mang [maŋ] meng [meŋ] mi [mi] mie [mie] miao [miau̯] mian [mian] m
@gpiantoni
gpiantoni / open_with_default_application.md
Created February 6, 2020 12:25
Open new MIME type with custom application

Open with default application

Objective

You wrote a function to open some specific files and you want to be able to always open that file with your application. In this example, we want to open micromed TRC files with wonambi.

Desktop Entry

Create a desktop entry for your application if you don't have one already. The file should be in ~/.local/share/applications/ and call the file userapp-wonambi.desktop:

@gpiantoni
gpiantoni / conversion_script.py
Last active November 6, 2019 14:45
convert PAR/REC with nibabel and rename them based on protocol name
#!/usr/bin/env python3
"""nibabel is the only one that can handle PCA and MP2RAGE.
- dcm2niix cannot handle phase-contrast angiography
- r2agui creates a different sform and qform. This is a mess because every
software either uses one or the other, and they are not consistent
"""
from os.path import commonprefix
@gpiantoni
gpiantoni / img_to_video.py
Created May 3, 2019 13:32
convert images from psychtoolbox into a video
#!/usr/bin/env python3
from pathlib import Path
from pandas import DataFrame
from subprocess import run
from argparse import ArgumentParser
PWD = Path(__file__).parent
P_INPUT = PWD / 'input.txt'