Skip to content

Instantly share code, notes, and snippets.

View js51's full-sized avatar

Joshua Stevenson js51

View GitHub Profile
@js51
js51 / basic_latex_diff.sh
Last active May 17, 2023 02:16
A basic BOLD type latex diff. The old project is called old and the new project is called new. Tex files are named main.tex
cp -R new diff
latexdiff -t BOLD old/main.tex new/main.tex > diff/main.tex
cd diff
latex -interaction nonstopmode main
bibtex main
latex -interaction nonstopmode main
pdflatex main
@js51
js51 / func_fact.py
Last active July 9, 2021 03:27
Python closure example
def function_factory(things):
funcs = []
for thing in things:
def do_something(x, _thing=thing):
return do_some_stuff(x, _thing)
funcs.append(do_something)
return funcs
@js51
js51 / flatten_dictionary.py
Created June 7, 2021 06:44
Flatten a dictionary (eg for plotting)
dictionary = { 'a': [1,3,8], 'b': [1,2,4,7], 'c': [5,6,8] }
flat_dictionary = [ (k,v) for k in dictionary.keys() for v in dictionary[k]]
x,y = zip(*flat_dictionary)
@js51
js51 / allocate_memory_for_GAP.sage
Created June 3, 2021 04:01
Allocate more memory to GAP in SAGE
gigs = 30
old_command = gap._Expect__command
s = old_command.index('-o ')
e = old_command.index(' -', s)
gap._Expect__command = gap._Expect__command.replace(gap._Expect__command[s:e], f'-o {gigs}G')
@js51
js51 / plot_latex.py
Last active August 25, 2021 01:26
Matplotlib figure, no colour with latex text
import matplotlib as mpl
import matplotlib.pyplot as plt
from cycler import cycler
import numpy as np
nice_fonts = {
# Use LaTeX to write all text
"text.usetex": True,
"font.family": "serif",
"axes.labelsize": 11,
@js51
js51 / int_base_b_to_string.py
Created February 22, 2020 00:50
Convert an integer to a string representation in base b
def string(i, b):
"""represent any integer i as a base b string where 2<=b<=10"""
import math
start = b**int(math.log(i,b))
def _string(i,b,val):
digit = int(i/val)
return str(digit) + (_string(i-digit*val, b, val/b) if i-digit != 0 else "")
return _string(i,b,start)
@js51
js51 / initWindowController.swift
Created July 15, 2019 01:43
macOS init Window Controller from Storyboard
lazy var myWindowController: MyWindowController = {
let storyboard = NSStoryboard.init(name: "MyStoryboard", bundle: nil)
let myWindowController = storyboard.instantiateController(withIdentifier: "MyWindowControllerID") as! NSWindowController
return myWindowController as! MyWindowController
}()