Skip to content

Instantly share code, notes, and snippets.

@gab50000
gab50000 / test.jsonnet
Created December 3, 2023 21:32
Jsonnet example
local setup_x() = {
before_script: ['echo hi'],
};
local build(build_args) =
{
script: [
'docker build ' + std.join(' ', ['--build-arg ' + b for b in build_args]),
],
};
class A(Base, TableRepr):
__tablename__ = "a"
__mapper_args__ = dict(
polymorphic_on="type",
polymorphic_identity="a",
)
id = Column(Integer, primary_key=True)
x = Column(String)
class Config(Base, TableRepr):
__tablename__ = "config"
id = Column(Integer, primary_key=True, index=True)
sub_config_id = Column(Integer, ForeignKey("subconfig.id"))
sub_config = relationship(
"SubConfig", cascade="all, delete-orphan", single_parent=True
)
class SubConfig(Base, TableRepr):
class M:
def __init_subclass__(cls):
base_configs = {}
for base in cls.__bases__:
if hasattr(base, "_config"):
base_configs |= base._config
_cls_config = cls.__dict__.get("_config", {})
cls._config = base_configs | _cls_config
insert_val <- function(x) {
x_ser <- serialize(x, NULL, ascii = TRUE) %>%
cat() %>%
capture.output()
tempfile_name <- paste0(tempfile(), ".R")
print(tempfile_name)
file <- file(tempfile_name)
writeLines(
c(
library(magrittr)
# call R in a separate process and yield the serialized result
# to the outer R process
return_val <- function() {
result <- system2(
"R",
c(
"-q", "-s",
"-e", "'library(magrittr)'",
import numba
import numpy as np
import timeit
def pot1(dist, charge):
return charge / dist
@numba.njit
import numpy as np
import timeit
def pot1(dist, charge):
return charge / dist
def broadcast_old(grid, coord, charge):
dist = (
@gab50000
gab50000 / example.service
Created March 26, 2018 17:07
Systemd user script example
[Unit]
Description=Blabla
After=network.target
[Service]
Type=simple
WorkingDirectory=/home/user/dir
ExecStart=/home/user/bin/python bla.py
Restart=on-failure
@gab50000
gab50000 / filter.py
Created November 25, 2017 21:43
Filter tagged cells in Jupyter notebook
#!/usr/bin/env python3
import os
import sys
import argparse
import json
def contained_tags(list_of_tags, cell):
if "tags" not in cell["metadata"]:
return []