Skip to content

Instantly share code, notes, and snippets.

View trevordixon's full-sized avatar

Trevor Dixon trevordixon

  • Google
  • Zürich, Switzerland
View GitHub Profile
@trevordixon
trevordixon / simplex.cs
Last active February 10, 2024 22:54
Simplex maximization algorithm in C#
using System;
using System.Diagnostics;
using System.Collections.Generic;
namespace Simplex {
class Simplex {
private double[] c;
private double[,] A;
private double[] b;
private HashSet<int> N = new HashSet<int>();
@trevordixon
trevordixon / extendedEu.hs
Created October 9, 2013 03:34
Extended euclidean algorithm in Haskell
extendedEu :: Integer -> Integer -> (Integer, Integer)
extendedEu a 0 = (1, 0)
extendedEu a b = (t, s - q * t)
where (q, r) = quotRem a b
(s, t) = extendedEu b r
@trevordixon
trevordixon / modExp.hs
Created October 2, 2013 03:00
Modular Exponentiation in Haskell
import Data.Bits
modExp :: Integer -> Integer -> Integer -> Integer
modExp b 0 m = 1
modExp b e m = t * modExp ((b * b) `mod` m) (shiftR e 1) m `mod` m
where t = if testBit e 0 then b `mod` m else 1
@trevordixon
trevordixon / pq.cs
Created April 10, 2014 16:51
C# Priority Queue
using System;
using System.Collections.Generic;
// From http://visualstudiomagazine.com/articles/2012/11/01/priority-queues-with-c.aspx
public class PriorityQueue<T> where T : IComparable<T> {
private List<T> data;
public PriorityQueue() {
this.data = new List<T>();
}

Keybase proof

I hereby claim:

  • I am trevordixon on github.
  • I am trevordixon (https://keybase.io/trevordixon) on keybase.
  • I have a public key ASCzdZDbIbkDh3klIM2pGAU-qx33WJaLpN0kgGvIjQVr-go

To claim this, I am signing this object:

@trevordixon
trevordixon / ReconnectingWebSocket.js
Last active April 24, 2021 12:54
ReconnectingWebSocket that exposes its constructor on module.exports.
// MIT License:
//
// Copyright (c) 2010-2012, Joe Walnes
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@trevordixon
trevordixon / renderElement.js
Created July 25, 2012 14:37
Function to render only a particular element in PhantomJS
function renderElement(page, selector) {
var prevClipRect = page.clipRect;
page.clipRect = page.evaluate(function(selector) {
return document.querySelector(selector).getBoundingClientRect();
}, selector);
var pic = page.renderBase64('png');
page.clipRect = prevClipRect;
@trevordixon
trevordixon / csv.pegjs
Created August 15, 2012 19:28
Javascript CSV Parser generated by PEG.js
{
var separator = ',';
}
start
= comma
comma
= & { return separator = ','; } sv:sv { return sv; }
@trevordixon
trevordixon / xlsxParser.js
Created August 17, 2012 04:10
Parse an Excel xlsx file with javascript, jquery, and zip.js
/*
Relies on jQuery, underscore.js, Async.js (https://github.com/caolan/async), and zip.js (http://gildas-lormeau.github.com/zip.js).
Tested only in Chrome on OS X.
Call xlsxParser.parse(file) where file is an instance of File. For example (untested):
document.ondrop = function(e) {
var file = e.dataTransfer.files[0];
excelParser.parse(file).then(function(data) {
console.log(data);
@trevordixon
trevordixon / aes.hs
Created April 15, 2016 06:13
CS 465 code
-- AES encryption in Haskell using Simple AES (http://hackage.haskell.org/package/SimpleAES-0.4.2)
-- Example encryption and decryption:
import Codec.Crypto.SimpleAES
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy.Char8 as BL
import Data.Hex
key = B.pack "Thisismykey....."