Skip to content

Instantly share code, notes, and snippets.

View ehgoodenough's full-sized avatar

Andrew Goodenough ehgoodenough

View GitHub Profile
@ehgoodenough
ehgoodenough / fibonacci.java
Created July 11, 2012 16:57
Just your genericly recursive fibonacci function; nothing is concatenated, obfuscated or optimized. It's written in java to use in various assignments.
public class fibonacci
{
public static void main(String[] args)
{
System.out.println(fibonacciValue(5));
}
public static int fibonacciValue(int fibonacciIndex)
{
if(fibonacciIndex < 2) {return 1;}
@ehgoodenough
ehgoodenough / bin2dec.py
Last active October 10, 2015 17:28
I've had a bit of difficulty working the equations assigned in digital logic that are designated in base two, so I coded this up to acquaint myself with binary.
import random
while True:
decivalue = random.randrange(0,99)
binavalue = bin(decivalue)[2:]
answer = int(input("What is " + binavalue + " in base ten? "))
if answer == decivalue:
print("..hooray! :D")
@ehgoodenough
ehgoodenough / fractions.cpp
Last active December 16, 2015 20:59
Adding together fractions of different denominators through a bit of operating overloading and cross multiplication.
#include <sstream>
#include <iostream>
using namespace std;
int getGCD(int a, int b)
{
if(a % b == 0)
{
return b;
}
@ehgoodenough
ehgoodenough / server.js
Created May 4, 2013 20:10
Routing and serving webpages through NodeJS. The system is currently configured to accept and return any request for any document.
var app = require("http").createServer(handler).listen(1337);
//var io = require("socket.io").listen(app, {log: false});
var path = require("path");
var url = require("url");
var fs = require("fs");
function handler(request, response)
{
var action = "." + url.parse(request.url, true).pathname;
@ehgoodenough
ehgoodenough / mergesort.java
Last active December 17, 2015 01:19
Although I managed to implement the recursive divide and conquer algorithm, the code generates a new array as it traverses up the stack, which is really quite wasteful. There must be a more efficient implementation that mergesorts the array all in place.
public class MergeSort
{
public static void main(String[] args)
{
int[] array = {57, 36, 13, 5, 24, 42, 68, 79};
array = sort(array);
for(int num = 0; num < array.length; num++)
{
@ehgoodenough
ehgoodenough / columns.htm
Created May 8, 2013 00:22
By styling the columns as table, you can ensure that all elements of the page remain the same height, regardless of the amount of content.
<!DOCTYPE hmtl>
<html>
<head>
<style>
body
{
margin:0px;
}
#partition
@ehgoodenough
ehgoodenough / magicsquare.cpp
Last active December 17, 2015 10:58
A magic square is an array of numbers where the sum of each column or row return the same value. This class can analyze the array for a magic square.
class Square
{
private:
const int size;
int* grid;
public:
Square() : size(4) {grid = new int[size * size];}
Square(int size) : size(size) {grid = new int[size * size];}
void setNode(int value, int x, int y) {grid[y * size + x] = value;}
@ehgoodenough
ehgoodenough / kbdin.js
Last active December 17, 2015 13:49
As discussed over at www.stackoverflow.com/questions/14893988, binding the functionality of a keystroke to an action instead of a state will establish noninterrupting events while still preserving individual keystrokes.
var kbdin =
{
downbinded: new Object(),
upbinded: new Object(),
stroked: new Object(),
downbindKeystroke: function(keyCode, functionality)
{
this.downbinded[keyCode] = functionality;
},
@ehgoodenough
ehgoodenough / insortion.java
Last active December 21, 2015 21:09
An implementation of an iterative insertion sort.
public class Insortion
{
public static void main(String[] args)
{
char[] array = {'a', 'c', 'b', 'e', 'd'};
insertionSort(array);
for(int i = 0; i < array.length; i++) {System.out.print(array[i]);}
}
var mailer = require("nodemailer");
var scheduler = require("node-schedule");
scheduler.scheduleJob({hour: 0, minute: 0}, function() //runs this function every morning at midnight.
{
var transport = mailer.createTransport("SMTP", {service: "gmail", auth: require("./gmail.auth.js")});
var settings = {
from: "do-not-reply@fake.com",
to: "some-person@aol.lol.com",