Skip to content

Instantly share code, notes, and snippets.

View ihincks's full-sized avatar

Ian Hincks ihincks

View GitHub Profile
@ihincks
ihincks / savediff.sh
Created December 11, 2018 13:56
Saves a diff of the current working changes to a git repo into Dropbox (so that you can continue working on something somewhere else)
#!/bin/bash
timestamp() {
date +"%Y-%m-%d_%H:%M:%S"
}
pushd "$PWD" > /dev/null
SHA="$(git rev-parse --short HEAD)"
FILENAME="$HOME/Dropbox/diff/${PWD##*/}_$(timestamp)_$SHA.diff"
git diff > $FILENAME
@ihincks
ihincks / query.py
Last active October 24, 2018 19:44
Some functions to query users at the command prompt.
def general_query(question, validator, default=None):
"""
Asks the given question, returning the (possibly modified) result if validator
allows it, and keeps asking until a valid answer is given.
:param str question: The question to ask.
:param validator: A function that acts on user response strings, and returns
`(success, modified_response, message)`. The loop ends if `success` is `True`,
in which case `modified_response` is returned. `message` is printed in
any case.
@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))
@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 / 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 / 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 / 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 / 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 / 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 / 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