Skip to content

Instantly share code, notes, and snippets.

View shane5ul's full-sized avatar

Sachin Shanbhag shane5ul

View GitHub Profile
@shane5ul
shane5ul / svg2tiff.sh
Created April 17, 2024 12:11
Some journals require a table of contents or highlights graphic in TIFF format. If you use Inkscape to generate such images on a Linux box like I do, then the following script (thanks to Matsen https://gist.github.com/matsen/4263955) is quite helpful in generating unbloated TIFF files with 300dpi.
#!/bin/sh
# Convert all arguments (assumed SVG) to a TIFF acceptable to PLOS
# Requires Inkscape and ImageMagick 6.8 (doesn't work with 6.6.9)
for i in $(ls *.svg | cut -d. -f1); do
inkscape --without-gui --export-png="${i}.png" --export-dpi 300 --export-area-drawing ${i}.svg
convert -compress LZW -alpha remove -trim ${i}.png ${i}.tiff
mogrify -alpha off -geometry 1000x ${i}.tiff
rm ${i}.png
@shane5ul
shane5ul / compare_symbolic.md
Created February 23, 2024 11:29
Comparison python sympy and Matlab Symbolic Toolbox commands

Here is the cheatsheet in Markdown format:

Operation MATLAB Python/SymPy
Define symbolic variable syms x x = symbols('x')
ex: syms x y z ex: x, y, z = symbols('x y z')
Differentiation diff(f) f.diff()
ex: diff(sin(x)) ex: sin(x).diff()
Partial differentiation diff(f,n) f.diff(x,n)
ex: diff(f(x,y),2,1) ex: f(x,y).diff(x,2).diff(y)
@shane5ul
shane5ul / pdfsplit.sh
Created February 1, 2024 14:09
Shell script to split PDF using Ghostscript. [originally from http://www.cs.virginia.edu/~weimer/pdfsplit/pdfsplit]
#!/bin/sh
#
# pdfsplit [input.pdf] [first_page] [last_page] [output.pdf]
#
# Example: pdfsplit big_file.pdf 10 20 pages_ten_to_twenty.pdf
#
# written by: Westley Weimer, Wed Mar 19 17:58:09 EDT 2008
#
# The trick: ghostscript (gs) will do PDF splitting for you, it's just not
# obvious and the required defines are not listed in the manual page.
@shane5ul
shane5ul / Integrals_change_of_variables.ipynb
Last active November 20, 2023 19:21
Jupyter notebook demonstrating the "change of variables" functionality in sympy
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shane5ul
shane5ul / unpackPython.ipynb
Created September 29, 2023 12:48
A jupyter notebook demonstrating python's unpacking operators * and **.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@shane5ul
shane5ul / conda_cheatsheet.md
Created September 28, 2023 15:33
My Conda Cheatsheet

Conda Package Manager

conda is a package manager like pip. However, there are important differences: (i) it is not restricted to python (via PyPI), (ii) has better dependency resolution, and (iii) has excellent environment management capabilities.

This last difference allows us to create isolated environments that can contain different versions of Python and packages, making it easier to manage dependencies and avoid conflicts between packages.

Installing conda

There are two broad ways to get conda. The first involves installing Anaconda which comes with a large number of other packages (7500+) relevant for ML and scientific computing. If you want just the basics then you should get miniconda.

@shane5ul
shane5ul / myjournal.mplstyle
Last active November 10, 2024 12:55
My custom matplotlib style library [located at $HOME/.config/matplotlib/stylelib on Linux, and $HOME/.matplotlib/stylelib/ on OSX]
axes.titlesize : 30
axes.labelsize : 24
lines.linewidth : 3
xtick.labelsize : 16
ytick.labelsize : 16
legend.fontsize : 14
# use latex font for mathtext
mathtext.fontset : cm
@shane5ul
shane5ul / After2Before
Last active November 29, 2022 19:40
sed oneliner to move \cite *after* punctuation to before
sed 's/\([,.;:]\)\\cite{\([A-Za-z0-9, ]*\)}/ \\cite{\2}\1/g'
# use script below for Before2After
# sed 's/\\cite{\([A-Za-z0-9, ]*\)}\([,.;:]\)/\2\\cite{\1}/g'
@shane5ul
shane5ul / JoinPointsMPL.py
Created April 2, 2021 18:58
Matplotlib helpers to draw well-defined boxes on plots, and to sequentially connect a set of points with line segments.
def drawBox(xlim, ylim):
"""
provide xlim = [xmin, xmax] and ylim = [ymin, ymax]
returns vectors x, y, which when plotted draw a box connecting the endpoints
"""
pts = [[xlim[0], ylim[0]], [xlim[1], ylim[0]], [xlim[1], ylim[1]], [xlim[0], ylim[1]], [xlim[0], ylim[0]]]
x, y = zip(*pts)
return x, y
def connectPoints(pts):
@shane5ul
shane5ul / SmoothTransition.ipynb
Created December 7, 2020 18:14
Jupyter Notebook on Smooth Transitions between Two Functions
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.