Skip to content

Instantly share code, notes, and snippets.

View Mahdisadjadi's full-sized avatar

mahdi sadjadi Mahdisadjadi

View GitHub Profile
@Mahdisadjadi
Mahdisadjadi / unpersist_rdd.md
Created May 20, 2022 02:24
unpersist RDDs with lost variable reference

In Pyspark, you can use:

persisted_RDDs = spark.sparkContext._jsc.getPersistentRDDs()
for (i, rdd_) in persisted_RDDs.items():
    rdd_.unpersist()

spark is of type pyspark.sql.session.SparkSession.

@Mahdisadjadi
Mahdisadjadi / render_latex_readme.md
Last active February 22, 2022 03:36
render math equation in readme files on github

Github can render LaTeX equations in jupyter notebooks but directly embedding equations in markdown files don't work. Solution is to embed URL correspondingto LaTeX equation. The page below shows how to convert LaTeX to URL. All the credit goes to this gist and its comments.

How it works:

https://jsfiddle.net/8ndx694g/

Example:

@Mahdisadjadi
Mahdisadjadi / triangle.py
Created March 24, 2019 17:08
Create a triangle and show label of vertices
# Create a triangle + label of vertices
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
fig, ax = plt.subplots(1,1,figsize=(5,5))
ax.plot(*coordinates[bonds].T, '-o', lw=3);
for i, p in enumerate(coordinates):
@Mahdisadjadi
Mahdisadjadi / flipDetection.py
Created September 7, 2018 17:43
Python functions to detect whether a spring network realization is feasible in 2D
def isFlipped(sites1, sites2, bonds):
"""
Check if neighbors of a vertex
have changed the cyclic order.
"""
def sortClockwiseAroundVertex(coordinates, root, neighbors):
'''
Sort the neighbors of a vertex,
such that the one with lowest index
@Mahdisadjadi
Mahdisadjadi / energyBarrier.py
Last active September 25, 2018 01:54
A python function for create the energy landscape between two conformations using linear interpolation morphing
"""
Mahd Sadjadi (2018)
This is a set of functions to compute the
energy barrier between two spring networks.
The morphing is done using the linear interpolation.
Example:
-------
s1 = np.random.rand(10,2)
s2 = np.random.rand(10,2)
@Mahdisadjadi
Mahdisadjadi / PointsAlignment.py
Last active August 8, 2018 01:13
Alignment of two sets of points on the 2D plane
def pointAlignment(ref, move):
"""
Mahd Sadjadi (2017)
This is a function which takes two sets of
points each with N points (both inputs are assumd to be
numpy arrays of N*2 shape). The first input is
the reference grid and the second is the point set to
be aligned with the reference.
This function shifts and rotate points to
make the two sets aligned and returns the
@Mahdisadjadi
Mahdisadjadi / stack_python.py
Created February 24, 2018 21:08
A simple implementation of Stack data structure in python
# A simple implementation of Stack data structure in python
# LIFO: last (item) in, first (item) out
# Insert at the end, pop the front of the list
class Stack():
def __init__(self):
self.items = []
def isEmpty(self):
@Mahdisadjadi
Mahdisadjadi / queue_python.py
Last active February 24, 2018 21:13
A simple implementation of Queue data structure in python
# A simple implementation of Queue data structure in python
# FIFO: first (item) in, first (item) out
# Insert at the front, pop at the end of the list
class Queue():
def __init__(self):
self.items = []
def isEmpty(self):
@Mahdisadjadi
Mahdisadjadi / specific_heat_two_level_states.py
Created December 22, 2017 01:31
Generate picture of a specific heat two level states
'''
This code generates a picture of the specific
heat of a two-level system. It also shows
the limits in low- and high-temperatures
regions, in addition to the location of
the maximum specific heat.
Mahdi Sadjadi, 2017.
'''
import numpy as np
@Mahdisadjadi
Mahdisadjadi / double_well_pontential_picture.py
Created December 20, 2017 22:26
Generate a picture of a symmetric one-dimensional double-well pontetial
'''
This code generates a picture of a symmetric
one-dimensional double-well pontetial.
Mahdi Sadjadi, 2017.
'''
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter, MaxNLocator
for param in ['axes.labelsize','xtick.labelsize','ytick.labelsize']: