Skip to content

Instantly share code, notes, and snippets.

View trevordixon's full-sized avatar

Trevor Dixon trevordixon

View GitHub Profile
@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 / 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 / git-reset-to-date
Created August 2, 2013 21:39
Resets multiple git repositories to the commit each would have been at at a given time.
#!/bin/bash
# Usage: git-reset-to-date date repo1 repo2 ...
# Example: git-reset-to-date "7/14/2013 14:00" repo1 repo2 repo3
require_clean_work_tree () {
# Update the index
git update-index -q --ignore-submodules --refresh
err=0
@trevordixon
trevordixon / FlyControls.js
Last active November 16, 2016 14:45
Three.js FlyControls. Controls yaw, pitch, and roll. Modified http://threejs.org/examples/js/controls/FlyControls.js to obey gamepad controls and control rotation only.
/**
* @author James Baicoianu / http://www.baicoianu.com/
* Originally from http://threejs.org/examples/js/controls/FlyControls.js
* Simplified to only obey gamepad
*/
THREE.FlyControls = function(object) {
this.object = object;
// API
@trevordixon
trevordixon / faster.js
Created June 10, 2013 07:05
Speeding up browserify with a huge lib. Using https://github.com/ForbesLindesay/browserify-middleware with Express.
// Each of these takes just a few milliseconds
app.get('/js/main.js', browserify('./public/js/main.js', {
external: ['three'],
detectGlobals: false
}));
app.get('/js/three.js', browserify(['three'], {
noParse: ['three'], // doesn't parse to look for global vars OR calls to require; just includes as-is
cache: true, // instructs browser to cache, even in dev, because this won't be changing
@trevordixon
trevordixon / static.php
Last active December 14, 2015 08:59
PHP Script to find non-static methods being called as if they were static. Uses https://github.com/nikic/PHP-Parser.
<?php
require 'PHP-Parser/lib/bootstrap.php';
ini_set('memory_limit', '512M');
// Feeds the given file to the PHP parser to be parsed and analyzed
function analyze_file($path, $parser, $traverser, $visitor) {
$code = file_get_contents($path);
$visitor->setFile($path);
$stmts = $parser->parse($code);
$stmts = $traverser->traverse($stmts);
@trevordixon
trevordixon / httplog.sublime-macro
Last active December 14, 2015 06:39
Macro to parse that web server log.
[
{
"args":
{
"characters": "\""
},
"command": "insert"
},
{
"args": null,
doc.addPage
size: 'legal'
layout: 'landscape'
@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 / 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; }