Skip to content

Instantly share code, notes, and snippets.

View tobin's full-sized avatar

Tobin Fricke tobin

View GitHub Profile
@tobin
tobin / nerd_snipe.py
Created September 22, 2023 18:56
Find radius of circle inscribed between y axis, unit circle, and y=sqrt(x).
# Solution to https://twitter.com/iwontoffendyou/status/1704935240907518367
# Tobin Fricke 2023-09-22
import numpy as np
import scipy.optimize
def dist_from_circle_center_to_curve(R):
# Center of circle of radius R that is tangent to the y axis and the unit circle.
x0 = R
@tobin
tobin / two_nots.py
Last active September 4, 2020 04:57
Solution to "invert three signals with two not gates" puzzle
# Solution to the following puzzle:
# Invert three boolean signals Using only two NOT gates,
# and as many AND or OR gates as needed,
#
# Tobin Fricke 2020-09-03
for x in [True, False]:
for y in [True, False]:
for z in [True, False]:
# If we assume that there is only one solution, then, when searching for the input
@tobin
tobin / static_const.c
Last active May 9, 2017 00:42
static const
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
const int baz = rand(); // ok!
baz = 99; // compile-time error.
static int goo = rand(); // compile-time error.
goo = 99; // ok.
@tobin
tobin / exact_sqrt.py
Created April 23, 2014 21:43
Integer square root
def exact_sqrt(x):
"""Calculate the square root of an arbitrarily large integer.
The result of exact_sqrt(x) is a tuple (a, r) such that a**2 + r = x, where
a is the largest integer such that a**2 <= x, and r is the "remainder". If
x is a perfect square, then r will be zero.
The algorithm used is the "long-hand square root" algorithm, as described at
http://mathforum.org/library/drmath/view/52656.html
@tobin
tobin / twinT.m
Created November 21, 2013 16:50
Plot the frequency response (Bode plot) of an ideal active twin-T notch
% Plot the frequency response of an ideal active twin-T notch, versus
% bootstrap feedback gain \alpha.
%
% Tobin Fricke <tobin.fricke@ligo.org>
% 2013-11-21
% Pick the color map (to make the plot pretty)
cm = jet();
% Choose the frequency axis
@tobin
tobin / 3867.txt
Created May 17, 2013 17:37
Notes on PDH waveform
A PDH error signal can be calibrated (into Hz per volt) simply by
observing the peak-to-peak amplitude of the PDH signal as the
cavity is swept through resonance. Here's the math:
An impedance-matched, lossless cavity has amplitude reflectivity of
r_c(f) = i f / (i f + pcav)
where pcav is the cavity pole, and f is the detuning frequency (i.e.
the difference between the frequency of the light and the resonant
@tobin
tobin / BNQ_W600+.edid
Last active December 17, 2015 10:09
BenQ W600+ Projector EDID/Modelines
@tobin
tobin / python.md
Last active December 16, 2015 23:59
Today I learned

This is valid:

M = [1,2,3]    
for M[0] in range(0,10):
    print M[0]

2013-05-14

The star operator opens tuples and other sequences:

@tobin
tobin / fu_puzzle.m
Last active December 16, 2015 00:18
Solve a magic square variant in Matlab
% Program to solve a sort of magic square, where only the rows and columns
% must sum to the magic constant, and not the diagonals. Some elements of
% the square are given in advance while others (indicated with 0) are
% unknown.
%
% TF Time-Wasting Project 04-2013
function result = fu_puzzle
puzzle = ...
[ 1 0 0 0 22
@tobin
tobin / pdh.gnuplot
Created February 28, 2013 16:52
Plot PDH error signal in Gnuplot
f_mod = 35.5e6
pcav = 300e3
i = {0, 1}
conj(z) = real(z) - i*imag(z)
r_c(f) = i*f / (i*f + pcav)
pdh(f) = imag(r_c(f)*conj(r_c(f+f_mod))-conj(r_c(f))*r_c(f-f_mod))
set samples 501