Skip to content

Instantly share code, notes, and snippets.

View finsberg's full-sized avatar
🐛
Squashing bugs

Henrik Finsberg finsberg

🐛
Squashing bugs
View GitHub Profile

Install FEniCSx

This was tested on MacOSX Monterey with Intel processor inside a conda environement

  1. Create a new conda environment and activate it
conda create --name fenicsx
conda activate fenicsx

Install FEniCS from source inside a conda environement

In this gist I will explain how to install the developmenent version of FEniCS from source inside a conda environement This installation was tested on MacOSX with Intel processor.

  1. Create an activate environement
conda create --name fenics-dev
conda activate fenics-dev
  1. Set some environement variables
@finsberg
finsberg / myrange.py
Last active October 3, 2021 09:26
Possible implementation of the built in range function in python.
from typing import List
def myrange(*args, **kwargs) -> List[float]:
"""Possible implementation of the built in range
function in python.
The range function in python takes various types of
inputs and produces a sequenctial list of increasing
or decreasing values. This is an alternative implementation,
@finsberg
finsberg / environment.yml
Last active May 24, 2022 10:11
environment.yml for IN1910
name: in1910
channels:
- default
- conda-forge
dependencies:
- python
- sphinx
- pip
- matplotlib
- numpy
@finsberg
finsberg / monitor_size.py
Created January 21, 2021 21:14
Script that can be run to delete oldest files in a folder if size of folder is above a certain limit. Useful to set up in a cron job if you have a folder that regularly increases in size.
import datetime
from pathlib import Path
import os
from collections import namedtuple
import argparse
File = namedtuple("File", ["path", "size", "mtime"])
def get_parser():
@finsberg
finsberg / copy_and_deepcopy.py
Created December 17, 2020 11:41
Example of how to implement copy and deepcopy methods in python
import copy
class A:
def __init__(self, x):
self.x = x
def __repr__(self):
return f"{self.x}"
@finsberg
finsberg / gmsh2dolfin.py
Created November 26, 2020 13:44
Convert .msh file generated with Gmsh to FEniCS format
import meshio
import numpy as np
import dolfin as df
def gmsh2dolfin(msh_file, mesh_file, line_file=None):
msh = meshio.gmsh.read(msh_file)
line_cells = []
@finsberg
finsberg / Makefile.latex
Last active May 14, 2020 18:51
Standard makefile for latex report
PAPER = paper.tex # Change this to the name of the latex document
PAPER.pdf = $(PAPER:%.tex=%.pdf)
PAPER.aux = $(PAPER:%.tex=%.aux)
# PDFLATEX = pdflatex -interaction scrollmode -file-line-error -halt-on-error -synctex=1 -shell-escape
PDFLATEX = pdflatex
BIBTEX = bibtex
all: clean pdf
pdf: $(PAPER)
@finsberg
finsberg / decorator_with_arguments.py
Created April 21, 2020 18:59
Decorator with arguments
def dec_with_kwargs(**params):
def decorator(f):
print(f"Calling decorator using params {params}")
def wrap(*args, **kwargs):
print(f"Calling wrap with args {args}, and kwargs {kwargs}")
return f(*args, **kwargs)
return wrap
#!/usr/bin/env python
"""
Extract text from pdf
Install these dependencies first with e.g conda
conda install pytesseract tesseract pdf2image
"""
import argparse