``` {.py file=hello2.py}
if __name__ == "__main__":
<<main-body>>
```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy.integrate import quad | |
class Cosmology: | |
"""This object stores all relevant information wrt the background | |
cosmology, parametrized by OmegaM, OmegaL and H0.""" | |
def __init__(self, H0, OmegaM, OmegaL): | |
self.H0 = H0 | |
self.OmegaM = OmegaM | |
self.OmegaL = OmegaL | |
self.OmegaK = 1 - OmegaM - OmegaL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
push!(LOAD_PATH,"../src/") | |
using Documenter, ... | |
function noweb_label_pass(src, target_path) | |
mkpath(joinpath(target_path, dirname(src))) | |
script = joinpath(@__DIR__, "noweb_label_pass.awk") | |
run(pipeline(src, `awk -f $script`, joinpath(target_path, basename(src)))) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import typing | |
from dataclasses import is_dataclass | |
def isgeneric(annot): | |
return hasattr(annot, "__origin__") \ | |
and hasattr(annot, "__args__") | |
def construct(annot, json): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Create Blender materials from Python: | |
from material_dsl import (BsdfPrincipled, OutputMaterial, Value, VertexColor, make_material) | |
color_input = VertexColor(location=(-400, 300), layer_name="my colormap") | |
shader = BsdfPrincipled(location=(0, 300), base_color=color_input.color) | |
output_material = OutputMaterial(location=(400, 300), surface=shader.BSDF) | |
make_material("colored mesh", output_material) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import numpy as np | |
from numpy import (sin, cos, pi) | |
def remove_from(data, name): | |
if name in data: | |
data.remove(data[name]) | |
class BObjectMeta(type): | |
def __new__(cls, name, bases, dct): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# requirements: python3, numba, dask | |
import random | |
import numba | |
import dask | |
@dask.delayed | |
@numba.jit(nopython=True, nogil=True) | |
def calc_pi(N): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import (wraps) | |
from itertools import (chain) | |
class Failure: | |
"""Signifies a failure in a computation that was wrapped by a `@maybe` | |
decorator.""" | |
def __init__(self, func, fails=None, exception=None): | |
self.name = func.__name__ | |
self.fails = fails |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create nice flower patterns in Gnuplot | |
set term svg | |
set output "flower.svg" | |
unset border | |
unset raxis | |
unset tics | |
unset key | |
set parametric |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
int main() { | |
int i; | |
for (i = 0; i <= 0; ++i) {} | |
printf("i = %u\n", i); | |
return EXIT_SUCCESS; | |
} |
NewerOlder