Skip to content

Instantly share code, notes, and snippets.

Avatar

DL groundf

View GitHub Profile
View Cahn-Hilliard.py
@overrides
def solve(self): #-> np.ndarray:
"""
The sequential version of Cahn-Hilliard solver.
Update a conserved order parameter, in our case, the concetration field $c(r, t)$.
Calculate free energy derivative at domain nodes.
The eight neighbour nodes of the central node (C) are north (N), south (S),
@groundf
groundf / Comment for Functional Python Article.py
Last active Aug 6, 2021
Comment for Functional Python Article
View Comment for Functional Python Article.py
# Functional composition with `>>` operator.
class Value:
def __init__(self, value) -> None:
self.value = value
def __rshift__(self, that):
print(f"{that.__name__}({self.value})")
return Value(that(self.value))
@groundf
groundf / Python Virtual Environment Usage.md
Last active Jul 31, 2021
How to create and activate and use Python virtual environment
View Python Virtual Environment Usage.md

Unix

source .venv\bin\activate

Windows

.venv\Scripts\activate
View HeatSteadyState.py
def init(params: Parameters, T0: Temperature, q: HeatFlow, ts:float) -> np.array:
"""
The time independent solution to heat equation.
:param params: The model parameters.
:param T0: The surface temperature [°C].
:param q: The mantle heat flow density [mW/m^2].
:param ts: The time step in years.
:returns: The temperature field [°C].
"""
@groundf
groundf / rename_pdf.py
Created Nov 7, 2020 — forked from ipudu/rename_pdf.py
Rename an academic article pdf with human readable format
View rename_pdf.py
import sys
import requests
import PyPDF2
import requests
import os
crossref = 'http://api.crossref.org/'
def rename(pdf):
"""Rename an academic article pdf file with human readable format
View Python Assignment Exression.md

Python assignment expression :=

In Python 3.8 was introduced an assignment expression (walrus operator :=) which can be used as in the example below.

if x := 1:
  print(bool(x))

The assignment statement cannot be used as in the previous example.

@groundf
groundf / state_machine_switch.py
Last active Feb 11, 2020
Example of State Machine with Switch Statement
View state_machine_switch.py
"""
Simple state machine example and switch emulation.
"""
from enum import Enum
from typing import Iterable
class State(Enum):
@groundf
groundf / __main__.py
Created Mar 31, 2019 — forked from linuxluigi/__main__.py
Python __main__.py parser example
View __main__.py
import argparse
# import data2tabshop
# from data2tabshop import __version__
__version__ = '0.1.0'
__author__ = u'Steffen Exler'
def get_parser():
@groundf
groundf / openicon.c
Created Jan 9, 2019 — forked from armornick/openicon.c
Draw an Image with SDL2
View openicon.c
#include <stdio.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#define WIDTH 800
#define HEIGHT 600
#define IMG_PATH "exit.png"
int main (int argc, char *argv[]) {
@groundf
groundf / gist:70225b0ca8add2ad3c0fe940de2ed69f
Created Aug 21, 2018 — forked from why-not/gist:4582705
Pandas recipe. I find pandas indexing counter intuitive, perhaps my intuitions were shaped by many years in the imperative world. I am collecting some recipes to do things quickly in pandas & to jog my memory.
View gist:70225b0ca8add2ad3c0fe940de2ed69f
"""making a dataframe"""
df = pd.DataFrame([[1, 2], [3, 4]], columns=list('AB'))
"""quick way to create an interesting data frame to try things out"""
df = pd.DataFrame(np.random.randn(5, 4), columns=['a', 'b', 'c', 'd'])
"""convert a dictionary into a DataFrame"""
"""make the keys into columns"""
df = pd.DataFrame(dic, index=[0])