Skip to content

Instantly share code, notes, and snippets.

View jvkersch's full-sized avatar

Joris Vankerschaver jvkersch

View GitHub Profile
#!/Users/jvkersch/miniconda3/envs/google-photos/bin/python
# Script to upload folders of photos to Google Photos
# Written with ChatGPT.
#
# Requires a Python environment with Google API packages:
# pip install google-auth google-auth-oauthlib google-auth-httplib2 requests
import os
import requests
import os
import shutil
def parse_dirname(dirname):
_, raw_name, _ = dirname.split(" - ")
parts = raw_name.split()
parts = [parts[-1]] + parts[:-1]
return " ".join(parts)
@jvkersch
jvkersch / dedup.py
Created June 21, 2021 19:44
Deduplicate a FASTA file
import argparse
import sys
from Bio import SeqIO
def _parse_args():
p = argparse.ArgumentParser()
p.add_argument("input")
return p.parse_args().input
@jvkersch
jvkersch / du0.go
Created March 24, 2021 13:49
CSP example from chapter 8 in The Go Programming Language
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
)
@jvkersch
jvkersch / actors.py
Created March 21, 2021 14:05
Implementation of the actor model in Python
import abc
import asyncio
class MessageBox:
def __init__(self):
self._queue = asyncio.Queue()
async def send(self, message_type, *content):
await self._queue.put((message_type, content))
@jvkersch
jvkersch / aoc1.cbl
Created December 12, 2020 10:04
Advent of Code 2020, problem 1.1 in Cobol
IDENTIFICATION DIVISION.
PROGRAM-ID. AOC1.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INPUTFILE ASSIGN TO 'input'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
@jvkersch
jvkersch / edm.fish
Last active December 4, 2020 20:01
EDM prettified prompts and autocompletions for the Fish shell
# EDM prettified prompts and autocompletions for the Fish shell
# Copyright (C) 2020 Joris Vankerschaver
# SPDX-License-Identifier: BSD-3-Clause
#
# Based on the autocompletions for Conda, generated with 'conda init fish'
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
#
# USAGE INSTRUCTIONS
#
@jvkersch
jvkersch / brainapp.py
Created July 5, 2020 09:07
Adapting Mayavi's volume slicer to show a crosscut of my brain
import nibabel as ni
from mayavi import mlab
from tvtk.api import tvtk
from tvtk.pyface.scene import Scene
from mayavi.sources.api import VTKDataSource
# Standard imports.
from numpy import sqrt, sin, mgrid
@jvkersch
jvkersch / popen_example.py
Last active July 8, 2020 07:00
traits-futures implementation of a future tied to a running process
import functools
import os
import stat
import subprocess
import threading
from traits.api import (
Any, Bool, Button, Dict, Event, HasStrictTraits,
Instance, Int, List, Property, Str, Tuple, Union,
observe
@jvkersch
jvkersch / sieve.py
Created May 21, 2020 07:27
Prime sieve using generators (Python version of SICP 3.5.2)
""" Infinite sieve of Eratosthenes using generators.
Python version of the Scheme code in SICP, paragraph 3.5.2.
"""
def primes(integers):
first = next(integers)
yield first
yield from primes(i for i in integers if i % first != 0)