Skip to content

Instantly share code, notes, and snippets.

View fomightez's full-sized avatar

Wayne's Bioinformatics Code Portal fomightez

View GitHub Profile
@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 September 5, 2022 13:23
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
@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 September 15, 2023 09:59
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
anonymous
anonymous / download_kegg.sh
Created February 15, 2018 21:03
# Get a list of all organisms
curl -s "http://rest.kegg.jp/list/organism" > organisms-all.txt
# Get just a few of interest
cat organisms-all.txt | awk '$2~/^(hsa|mmu|rno|cfa|bta|gga|xla|xtr|dre|dme|cel|ath|ehi|tgo|eco|sau|mtu|mav|cje|ccol)$/' > organisms-of-interest.txt
# Get the accession codes for each
cut -f1 organisms-of-interest.txt > organisms-of-interest-codes.txt
# Make a directory to put all the kgml files downloaded
@evanmiltenburg
evanmiltenburg / legend_circles.py
Created February 13, 2018 15:02
Circles in legend
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib.lines import Line2D
my_palette = sns.color_palette("cubehelix", 3)
sns.set_palette(my_palette)
def legend_circles(labels, palette, loc=1, markersize=10, marker='o', padding=0):
"Make a legend where the color is indicated by a circle."