Skip to content

Instantly share code, notes, and snippets.

View freeeve's full-sized avatar

Eve Freeman freeeve

  • Fairfax, VA
View GitHub Profile
@freeeve
freeeve / nodelog.js
Created July 22, 2011 07:01
nodejs script for piped virtualhost logging in apache
/* Copyright 2011 Wes Freeman
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@freeeve
freeeve / TestLDAP.java
Created August 20, 2011 00:04
A pedagogical LDAP authentication test in Java.
/* Copyright 2011 Wes Freeman
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@freeeve
freeeve / colortest.html
Created August 20, 2011 00:38
A random color generator in javascript/jQuery. Just playing around.
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
var colortest = $("#colortest");
for (i = 1; i <= 300; i++) {
var c = genColor();
var newhtml = "<span style='font-family:\"Courier\",monospace;width:50px;height:30px;background-color:#" + c + "'>#" + c + "</span>";
colortest.html(colortest.html() + newhtml);
@freeeve
freeeve / force_download.php
Created August 23, 2011 19:30
Code to force download a file in PHP using header Content-Disposition: attachment
<?php
$file = 'filename.pdf';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
@freeeve
freeeve / gist:1260739
Created October 4, 2011 01:57
JavaMail simple text sample
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
// Send a simple, single part, text/plain e-mail
public class TestEmail {
public static void main(String[] args) {
String to = "sendToMailAddress";
@freeeve
freeeve / ldapError.java
Created October 12, 2011 15:34
LDAP error map quick reference (maps data error codes to failure reasons)
525 ERROR_NO_SUCH_USER (The specified account does not exist.)
NOTE: Returns when username is invalid.
52e ERROR_LOGON_FAILURE (Logon failure: unknown user name or bad password.)
NOTE: Returns when username is valid but password/credential is invalid.
Will prevent most other errors from being displayed as noted.
530 ERROR_INVALID_LOGON_HOURS (Logon failure: account logon time restriction violation.)
NOTE: Returns only when presented with valid username and password/credential.
@freeeve
freeeve / bench.js
Created January 28, 2012 22:38
mongodb count benchmark index
var filters = ['abcd', 'efgh', 'ijkl', 'mnop', 'qrst', 'uvwx', 'yz'];
var flen = filters.length;
var n = 1000000;
var max = -1;
function printInterestingStats(explain) {
print(" cursor: " + explain.cursor);
print(" nscanned: " + explain.nscanned);
print(" scanAndOrder: " + explain.scanAndOrder);
print(" millis: " + explain.millis);
@freeeve
freeeve / orderedCollectionBench.js
Created January 29, 2012 19:30
ordered collection with arbitrary moves; method comparison
var populateMulti = function(colSize) {
db.test10.drop();
for(var i=0;i<colSize;i++) {
db.test10.save({name:""+i, order:i});
}
db.test10.ensureIndex({order:1});
}
var moveMulti = function(oldPos,newPos) {
if(oldPos == newPos) return;
@freeeve
freeeve / compoundRangeIndex.js
Created February 2, 2012 22:26
generate random data for some compound index ordering comparisons
function getRandomTime() {
return new Date(new Date() - Math.floor(Math.random()*1000000));
}
function initialInsert() {
// insert 1 million records
for(var i = 0; i < 1000000; i++) {
db.test.save({
date_added:getRandomTime(),
optical_lumo:Math.random()*30-10, // let's make the range 1/3 of the result
@freeeve
freeeve / stateSelect.html
Created February 4, 2012 02:00
list of states in select/option HTML format
<label for="state">*State</label>
<select id="state" name="state">
<option value="">Select one...</option>
<option value='AL'>Alabama</option>
<option value='AK'>Alaska</option>
<option value='AZ'>Arizona</option>
<option value='AR'>Arkansas</option>
<option value='CA'>California</option>
<option value='CO'>Colorado</option>
<option value='CT'>Connecticut</option>