Skip to content

Instantly share code, notes, and snippets.

@TAJD
TAJD / deploy-site.yml
Created October 8, 2023 14:09
GitHub Action to deploy updates to blog
name: Blog build and deploy
on:
push:
branches:
- "gh-actions"
pull_request:
branches:
- "master"
paths:
- ".github/workflows/deploy-site.yaml"
package org.tajd
package metaprogramming
import java.nio.file.{Files, Path, Paths}
import org.scalafmt.interfaces.Scalafmt
import scala.jdk.CollectionConverters._
import scala.meta.{Term, _}
import scala.util.Try
{% if page.mermaid %}
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
<script>mermaid.initialize({startOnLoad:true});</script>
{% endif %}

Create a terraform file

  1. Set the filename in the properties section.
  2. Write terraform code in code blocks with terraform as the language.
  3. Tangle the current file - shortcut is C-c C-v t.
@TAJD
TAJD / save_memory.py
Last active July 3, 2021 17:36
Useful snippets for working with pandas dataframes
import numpy as np
import pandas as pd
def check_if_integer(col: pd.Series) -> bool:
"""Check if changing the data type of a series to integer changes its values."""
return np.array_equal(col, col.astype(int))
def reduce_mem_usage(
@TAJD
TAJD / create_table_macro.sql
Created February 22, 2021 18:24
dbt macro to create table from dbt model
{% macro create_table(table_name) %}
{% set sql %}
BEGIN;
DROP TABLE IF EXISTS {{ table_name[:-4] }};
CREATE TABLE {{ table_name[:-4] }} AS SELECT * FROM {{ table_name }};
GRANT SELECT ON {{ table_name[:-4] }} TO webview;
COMMIT;
{% endset %}
import time
class Timer:
"""Class to assist with timing functions.
Start timing with
```my_timer = Timer()```
And then get the time with
@TAJD
TAJD / gbm.jl
Created February 6, 2018 15:26 — forked from jwmerrill/gbm.jl
Faster geometric brownian motion
function genS_jl(I)
s0 = 600.0
r = 0.02
sigma = 2.0
T = 1.0
M = 100
dt = T/M
a = (r - 0.5*sigma^2)*dt
b = sigma*sqrt(dt)
@TAJD
TAJD / latex_help.py
Created January 15, 2018 17:25
Assist latex file compilation and spell check.
"""Assist latex file editing.
Functions to assist with editing and compiling latex documents.
Thomas Dickson
26/12/2017
"""
import click
import subprocess
import click
@click.group()
def play_music():
pass
@play_music.command()
def hello():
click.echo('Here is our nokia composer! It accepts files containing music notes encoded in the microbit.music format.')