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 / USAGE
Last active December 23, 2015 10:09
SHA-1 collision finder
Use like:
sha1_attack --bytes 2 --type preimage
sha1_attack --bytes 4 --type collision
sha1_attack --bytes 3 --type both
--bytes is the number of bytes to consider (i.e. the number of bytes to which the SHA-1 digest will be truncated)
--type can be preimage, collision, or both
@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 / rndPrime.hs
Created October 2, 2013 03:01
Find a Large Random Prime Number in Haskell
import System.Random
import Math.NumberTheory.Primes.Testing
rndPrime :: Int -> IO Integer
rndPrime bits = do
x <- fmap (.|. 1) $ randomRIO (2^(bits - 1), 2^bits - 1)
if isPrime x then return x else rndPrime bits
@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 / 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 / cloud-init.sh
Last active January 3, 2016 04:59
Bootstrap EC2 server
#!/bin/bash
wget "https://gist.github.com/trevordixon/8413132/raw/index.html" -O /var/www/index.html
@trevordixon
trevordixon / hello.krl
Last active August 29, 2015 13:56
Hello World KRL
ruleset HelloWorldApp {
rule Excercise1 is active {
select when pageview ".*"
{
notify("Hello World", "This is a sample rule.") with sticky = true;
notify("Another One", "Notification 2.") with sticky = true;
}
}
rule Exercise4 is active {
'use strict';
var angular = require('angular');
module.exports = function LoginFormDirective ($compile) {
return {
restrict: 'E',
template: require('./loginFormTemplate.html'),
link: function (scope, element) {
// Already compiled!
@trevordixon
trevordixon / a2294x1.krl
Last active August 29, 2015 13:56
Lab 3
ruleset a2294x1 {
rule show_form is active {
select when pageview "ktest\.heroku\.com"
pre {
firstName = ent:firstName;
lastName = ent:lastName;
form = <<
<form id="simple_form">
<input placeholder="First Name" name="first_name"><br>
ruleset a2294x2 {
rule first_rule is active {
select when pageview ".*" setting ()
pre {
results = <<
<dl id="results" style="display:none">
<dt></dt>
<dd><img id="thumbnail" src=""></dd>
<dt>Title</dt>