Skip to content

Instantly share code, notes, and snippets.


DL groundf

View GitHub Profile
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 / Comment for Functional Python
Last active Aug 6, 2021
Comment for Functional Python Article
View Comment for Functional Python
# Functional composition with `>>` operator.
class Value:
def __init__(self, value) -> None:
self.value = value
def __rshift__(self, that):
return Value(that(self.value))
groundf / Python Virtual Environment
Last active Jul 31, 2021
How to create and activate and use Python virtual environment
View Python Virtual Environment


source .venv\bin\activate


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 /
Created Nov 7, 2020 — forked from ipudu/
Rename an academic article pdf with human readable format
import sys
import requests
import PyPDF2
import requests
import os
crossref = ''
def rename(pdf):
"""Rename an academic article pdf file with human readable format
View Python Assignment

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:

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

groundf /
Last active Feb 11, 2020
Example of State Machine with Switch Statement
Simple state machine example and switch emulation.
from enum import Enum
from typing import Iterable
class State(Enum):
groundf /
Created Mar 31, 2019 — forked from linuxluigi/
Python parser example
import argparse
# import data2tabshop
# from data2tabshop import __version__
__version__ = '0.1.0'
__author__ = u'Steffen Exler'
def get_parser():
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 / 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])