Skip to content

Instantly share code, notes, and snippets.

View ihincks's full-sized avatar

Ian Hincks ihincks

View GitHub Profile
@ihincks
ihincks / multi-bibtex
Created September 10, 2014 16:48
Call bibtex on all .aux files in directory with given base.
#!/usr/bin/python
'''
A call to this script
multi-bibtex [options] texfile[.aux]
will result in the commands
bibtex [options] file.aux
being called for every file in the folder of texfile which
starts with "texfile".
This is useful, for example, when you want to use bibtex
(as opposed to biber which does what we want automatically)
@ihincks
ihincks / tuple_encoder.py
Created June 17, 2016 03:09
For those times you need tuples of non-negative integers to be non-negative integers...
#!/usr/bin/python
from __future__ import division
import numpy as np
def tuple_encode(x):
"""
If x is a tuple of non-negative integers, outputs a single non-negative
integer which is unique for that tuple, based on Cantor's bijection
argument.
"""
@ihincks
ihincks / pp_syntax.md
Last active June 5, 2017 14:30
NV Command Center Documentation

NV Command Center Documentation

Pulse Program Syntax

Introduction

Pulse programs are text files that specify the pulse sequence for a single shot of an experiment. They conventionally use the file suffix .pp. These text files are run sequentially, line by line, starting from the top.

Comments

@ihincks
ihincks / tex_matrix.py
Last active August 3, 2017 11:53
TexMatrix
# This is working pretty nice for me, and has basically paid itself off.
# In retrospect, there are some better design layouts that would be more elegant,
# if this ever becomes more than a gist: headers and footers should be their own
# class, and there should be a generic class which sandwiches the matrix with
# such. LatexTabularX should be two of such sandwiches. Functionality for saving
# to disk and compiling the master tex file would be nice.
import warnings
class TexMatrix(object):
@ihincks
ihincks / lighten_color.py
Last active November 8, 2024 05:06
Function to lighten any color in matplotlib
def lighten_color(color, amount=0.5):
"""
Lightens the given color by multiplying (1-luminosity) by the given amount.
Input can be matplotlib color string, hex string, or RGB tuple.
Examples:
>> lighten_color('g', 0.3)
>> lighten_color('#F034A3', 0.6)
>> lighten_color((.3,.55,.1), 0.5)
"""
@ihincks
ihincks / bijection.py
Last active July 10, 2018 20:42
Implements a bijection between density matrices (unit trace positive operators) and real space R^(d^2-1)
from __future__ import division
import numpy as np
from scipy.special import expit, logit
def complex_contract(x, y):
"""
Shrinks z=x+iy to the unit disk using half-expit.
"""
r = np.sqrt(x**2 + y**2)
phi = np.arctan2(y, x)
@ihincks
ihincks / tacocat.py
Last active December 3, 2017 21:32
Tacocat
#!/bin/awesomethon
import adh as brother
from mad import skillz
import hopefully_not as too_hard
from dickens import major_work
message_ascii = skillz.ascii_array(message)
dickens_ascii = skillz.ascii_array(major_work.get_chapter(brother.get_age()))
@ihincks
ihincks / com-port.ipynb
Last active January 9, 2018 20:32
Quick code to talk to COM or TCPIP hardware devices
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ihincks
ihincks / init.coffee
Last active February 20, 2020 11:42
Some Latex shortcuts for Atom
# mimics the ctrl+shift+m behaviour in texmaker
atom.commands.add 'atom-text-editor',
'custom:insert-inline-latex-eqn': ->
return unless editor = atom.workspace.getActiveTextEditor()
selection = editor.getLastSelection()
selection.insertText("$#{selection.getText()}$")
if not editor.getSelectedText()
editor.moveLeft()
# puts selected text in a new align environment
@ihincks
ihincks / random_choice.py
Created June 12, 2018 20:00
Function that generalizes np.random.choice to n-D arrays
def random_choice(mat, n_samples=None, axis=0):
"""
Replaces the given axis with n_samples random choices (with replacement)
of values already along that axis.
A=np.arange(15).reshape(3,5)
print(A)
print(random_choice(A, n_samples=6, axis=1))
print(random_choice(A, axis=0))