Skip to content

Instantly share code, notes, and snippets.

View nerdyworm's full-sized avatar
:shipit:
distracted like an adhd squirrel

Benjamin Rhodes nerdyworm

:shipit:
distracted like an adhd squirrel
View GitHub Profile
<?php
function endsWith($haystack,$needle) {
return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)),$needle)===0);
}
$uri = $_SERVER['REQUEST_URI'];
if(is_404() && endsWith($uri, '/')) {
header("HTTP/1.1 301 Moved Permanently" );
header("Location: ".substr($uri, 0, strlen($uri) - 1).".html");
}
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
#include "mpi.h"
main(int argc, char **argv )
{
char buffer[100];
int i, rank, size, type=99;
MPI_Status status;
/**
* Copyright 2010 Coderloop.com.
* Author: Diego, the architect
**/
package com.coderloop.puzzles;
import java.util.List;
import java.util.LinkedList;
//! This class implements a Megafasttree
@nerdyworm
nerdyworm / mail.rb
Created December 9, 2010 15:20
My rails mail initializer file.
ActionMailer::Base.smtp_settings = {
:address => ENV['SMTP_ADDRESS'],
:port => ENV['SMTP_PORT'],
:domain => ENV['SMTP_DOMAIN'],
:user_name => ENV['SMTP_USERNAME'], #username@domain.com for google apps accounts
:password => ENV['SMTP_PASSWORD'],
:authentication => "plain",
:enable_starttls_auto => true
}
@nerdyworm
nerdyworm / echo.sh
Created January 12, 2011 16:51
simple
#!/bin/bash
java -jar your-project.jar
(ns topfive.topfive
(:import
(java.io BufferedReader FileReader)
(java.util Hashtable)))
(def filename
(if (nil? *command-line-args*)
(str "topfive/topfive-a.in")
(first *command-line-args*)))
@nerdyworm
nerdyworm / producer_consumer.rb
Created January 24, 2011 23:59
User of a Fiber block to create a simple producer consumer thing.
@b = nil
@x = nil
@y = nil
@z = nil
def producer
Fiber.new do
loop do
@b = rand()
Fiber.yield #or consumer resume
over_paid = 53
change = []
[100, 25, 10, 5, 1].each do |i|
while i <= over_paid do
if i <= over_paid
over_paid -= i
change << i
end
end
@nerdyworm
nerdyworm / page.rb
Created April 13, 2011 15:38
simple things
class Page
Pages = {
'/about/' => {
:title => 'About',
:template => '/pages/about/index.html.erb'
}
}
def self.find_by_path(path)
@nerdyworm
nerdyworm / noun.rb
Created April 30, 2011 14:15
Silly list based noun finder
class String
@@nouns = []
def is_noun?
String.nouns.include? self.downcase
end
def find_nouns
self.split(/\s/).collect { |w| w if w.is_noun? }.compact
end