Skip to content

Instantly share code, notes, and snippets.

@acgetchell
acgetchell / F# Types.fs
Last active August 8, 2016 22:47
An F# union type representing the F# type system. From Jon Harrop's "Visual F# 2010 for Technical Computing"
type 'a ty =
| Abbrev of 'a list * string
| Function of 'a ty * 'a ty
| Record of string * (string * 'a) list
| Tuple of 'a ty list
| Union of string * (string * 'a list) list;;
@acgetchell
acgetchell / type_of.fs
Last active August 8, 2016 22:51
Uses reflection provided by F# in the FSharpType namespace to translate a given System.Type object into a value of the 'a ty union type defined by https://gist.github.com/926994. From Jon Harrop's "Visual F# 2010 for Technical Computing"
let rec type_of f = function
| ty when Reflection.FSharpType.IsFunction ty ->
let ty_arg, ty_ret = Reflection.FSharpType.GetFunctionElements ty
Function(type_of f ty_arg, type_of f ty_ret)
| ty when Reflection.FSharpType.IsTuple ty ->
Tuple
[ for ty in Reflection.FSharpType.GetTupleElements ty do
yield type_of f ty ]
| ty when Reflection.FSharpType.IsRecord ty ->
Record( ty.Name,
> List.fold.GetType()
|> type_of (fun (ty: System.Type) -> ty.Name);;
val it : string ty =
Function
(Function
(Abbrev ([],"System.Object"),
Function (Abbrev ([],"System.Object"),Abbrev ([],"System.Object"))),
Function
(Abbrev ([],"System.Object"),
Function
;; acgetchell's solution to A nil key
;; https://4clojure.com/problem/134
(fn f [key map] (and (#(contains? map key)) (#(nil?(val(find map key))))))
@acgetchell
acgetchell / gist:1416617
Created December 1, 2011 13:11
Getting the 10,001st Prime Number
;; From http://clojure-euler.wikispaces.com/Problem+007
;; Useful examples on how easy it is to do number processing in Clojure
;; achim_p's solution, understandable and REPLicable
(defn div? [n d]
(= 0 (rem n d)))
(defn smallest-prime-factor [number]
(loop [n number d 2]
(cond (> d (int (Math/sqrt number))) n
@acgetchell
acgetchell / feynmp-preamble.tex
Last active August 8, 2016 22:49
FeynMP preamble
\usepackage[final]{feynmp}
\DeclareGraphicsRule{*}{mps}{*}{}
\makeatletter
\def\endfmffile{%
\fmfcmd{\p@rcent\space the end.^^J%
end.^^J%
endinput;}%
\if@fmfio
\immediate\closeout\@outfmf
\fi
@acgetchell
acgetchell / compton.tex
Last active August 8, 2016 22:52
Compton scattering
\begin{figure}
\centering
\begin{fmffile}{compton}
\begin{fmfgraph*}(80,50)
\fmfleft{i1,i2}
\fmfright{o1,o2}
\fmflabel{$\gamma$}{i2}
\fmflabel{$e^-$}{i1}
\fmflabel{$\gamma$}{o1}
@acgetchell
acgetchell / Homebrew-dylibs
Created October 10, 2012 23:56
Results of brew doctor showing dylibs from OSXFUSE install, no other problems, ignore?
Hapkido:bin getchell$ brew doctor
Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected dylibs:
/usr/local/lib/libmacfuse_i32.2.dylib /usr/local/lib/libmacfuse_i64.2.dylib /usr/local/lib/libosxfuse_i32.2.dylib /usr/local/lib/libosxfuse_i64.2.dylib
Warning: Unbrewed .la files were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
@acgetchell
acgetchell / soloist.sh
Last active December 10, 2015 13:38
Config script for development
#!/bin/bash
# This shell script was created at solowizard.com
#
# Usage:
# Running the script remotely:
# bash < <(curl -s http://www.solowizard.com/soloist_scripts/dqhzj8.sh )
# Running the script if you have downloaded it:
# ./dqhzj8.sh
#
# http://github.com/tommyh/solo_wizard
@acgetchell
acgetchell / problem7.jl
Created May 30, 2013 22:00
problem7.jl for debugging jocco
# in problem7.jl
# find the 10,001st prime number
# isPrime(n) uses the sieve of Eratosthenes
# Test LaTeX
# Using [Pandoc] allows us to have math inline $x=y$ or in display mode
# $$
# \begin{aligned}