Skip to content

Instantly share code, notes, and snippets.

View fomightez's full-sized avatar

Wayne's Bioinformatics Code Portal fomightez

View GitHub Profile
@bollwyvl
bollwyvl / widget-html-json.ipynb
Last active January 23, 2026 15:05
Using Jupyter Widgets with Arbitrary JavaScript and HTML
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@willmcgugan
willmcgugan / last_lines.py
Created March 2, 2024 16:10
Get the last lines from a file
import mmap
def get_last_lines(path: str, count: int) -> list[str]:
"""Get count last lines from a file."""
with open(path, "r+b") as text_file:
text_mmap = mmap.mmap(text_file.fileno(), 0, mmap.ACCESS_READ)
position = len(text_mmap)
while count and (position := text_mmap.rfind(b"\n", 0, position)) != -1:
count -= 1
@ma7dev
ma7dev / cool_script.sh
Last active May 27, 2025 18:27
takes requirements.txt file without module versions and annotates it with the latest set of module versions that won't result in build/runtime errors.
#!/bin/bash
# TODO: you will need to have conda installed
# create a python environment
conda create -n env_tmp python=3.8.13 -y
# activate environment
conda activate env_tmp
@bollwyvl
bollwyvl / nbconvert-in-jupyterlite.ipynb
Last active January 6, 2026 16:25
nbconvert in jupyterlite
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ptmcg
ptmcg / computer_thinking_spinners.py
Last active March 1, 2022 20:16
Rich spinners for "the computer is thinking"
import rich.progress
import rich.spinner
import time
import random
class RandomChars(rich.progress.ProgressColumn):
"""Simulation of computer 'thinking' by displaying random characters
Args:
chars (str): characters from which to choose for display. Defaults to 0-9A-F.
@parente
parente / README.md
Last active August 23, 2018 13:16
Jupyter Tidbit: %run your ipynb file

Summary

The %run magic provided by IPython not only supports the execution of regular Python scripts, it also runs Jupyter Notebook files (.ipynb).

Example

Binder

The run_demo.ipynb notebook below uses %run to execute all of the cells in reusable_stuff.ipynb. Once it does, both globals defined in reusable_stuff are available in run_demo for use.

@fomightez
fomightez / run_every_eight_mins.py
Created March 28, 2018 17:33
do something every eight minutes with Python
import time
def executeSomething():
#code here
print ('.')
time.sleep(480) #60 seconds times 8 minutes
while True:
executeSomething()
library(magick)
library(reshape2)
library(dplyr)
library(tidygraph)
library(particles)
library(animation)
plot_fun <- function(sim) {
df <- as_tibble(sim)
plot(df$x, df$y, col = df$color, pch = '.', axes = FALSE, xlim = c(-100, 317), ylim = c(-268, 100), xlab = NA, ylab = NA)
@fomightez
fomightez / useful_python_snippets.py
Last active November 4, 2025 19:09
Useful Python snippets
# These are meant to work in both Python 2 and 3, except where noted.
# See my useful_pandas_snippets.py for those related to dataframes (such as pickling/`df.to_pickle(save_as)`)
# https://gist.github.com/fomightez/ef57387b5d23106fabd4e02dab6819b4
# also see https://gist.github.com/fomightez/324b7446dc08e56c83fa2d7af2b89a33 for examples of my
# frequently used Python functions and slight variations for more expanded, modular structures.
#argparse
# good snippet collection at https://mkaz.tech/code/python-argparse-cookbook/
@astrojuanlu
astrojuanlu / Visualizing the SpaceX Tesla Roadster trip to Mars.ipynb
Created February 18, 2018 11:11
Visualizing the SpaceX Tesla Roadster trip to Mars
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.