Skip to content

Instantly share code, notes, and snippets.

View geowa4's full-sized avatar
🏠
Working from home

George Adams geowa4

🏠
Working from home
View GitHub Profile
@geowa4
geowa4 / install.sh
Created December 3, 2011 21:51
Simple Bash script to download Tomcat 7.0.23 and deploy a WAR.
#!/bin/bash
TOMCAT=apache-tomcat-7.0.23
TOMCAT_WEBAPPS=$TOMCAT/webapps
TOMCAT_CONFIG=$TOMCAT/conf/server.xml
TOMCAT_START=$TOMCAT/bin/startup.sh
TOMCAT_ARCHIVE=$TOMCAT.tar.gz
TOMCAT_URL=http://apache.mirrorcatalogs.com/tomcat/tomcat-7/v7.0.23/bin/$TOMCAT_ARCHIVE
WAR_FILE=whatever.war
@geowa4
geowa4 / flotr2-issue89.html
Created May 19, 2012 22:49
Reproducing an incompatibility issue between RequireJS and Flotr2
<!DOCTYPE html>
<html>
<head>
<title>Flotr2 Issue #89 (Date: Sat, 19 May 2012 22:48:31 GMT)</title>
<script src="http://requirejs.org/docs/release/1.0.8/comments/require.js"></script>
<script src="https://raw.github.com/HumbleSoftware/Flotr2/master/flotr2.js"></script>
</head>
<body>
<p>Look at your console.</p>
<p>In Chrome, I get <code>Uncaught ReferenceError: bean is not defined</code> on line 1359.
@geowa4
geowa4 / countPairs.hs
Last active December 11, 2015 21:18
Count the number of pairs in `nums` that total `target`. Sort is performed at the very beginning to allow for some assumptions to be made in the recursive routine. I want to figure out how to remove the sort; it wouldn't be needed in the declarative version.
import Data.List
countPairs :: (Integral a, Num b) => [a] -> a -> b
countPairs nums target = counter (sort nums) target
where
counter :: (Integral a, Num b) => [a] -> a -> b
counter [] _ = 0
counter [_] _ = 0
counter sn t
| s == t = 1 + counter (init (tail sn)) t
@geowa4
geowa4 / makeLines.hs
Created February 3, 2013 04:08
Take a string and split it over multiple lines of a specified max length. If a word is too big to fit on a single line, just put it on its own line for simplicity.
import Data.List
makeLines :: Int -> String -> String
makeLines len = (intercalate "\n") . (foldl (buildLine len) [""]) . words
where
buildLine :: Int -> [String] -> String -> [String]
buildLine len currLines word =
if length newLine > len
then currLines ++ [word]
else ls ++ [newLine]
[color]
ui = true
[alias]
lol = log --graph --decorate --pretty=oneline --abbrev-commit --all
st = status
co = checkout
ci = commit
count = shortlog -sn
lost = log --stat
patchlog = log --patch
@geowa4
geowa4 / euler1.hs
Created February 8, 2013 00:35
Project Euler Problem #1
euler1 :: Int
euler1 = sum [x | x <- [1..999], rem x 3 == 0 || rem x 5 == 0]
@geowa4
geowa4 / euler2.hs
Created February 8, 2013 01:13
Project Euler Problem #2
fib :: Int -> Int
fib 1 = 1
fib 2 = 2
fib n = fib (n - 1) + fib (n - 2)
euler2 = sum $ takeWhile (<4000000) $ filter (even) [fib x | x <- [1..]]
@geowa4
geowa4 / euler3.hs
Created February 8, 2013 01:19
Project Euler Problem #3
leastDivisor :: Integer -> Integer -> Integer
leastDivisor divisor n
| rem n divisor == 0 = divisor
| divisor^2 > n = n
| otherwise = leastDivisor (divisor+1) n
factors :: Integer -> [Integer]
factors 1 = []
factors n = ld : factors (n `div` ld)
where ld = leastDivisor 2 n
@geowa4
geowa4 / euler4.hs
Last active December 12, 2015 07:19
Project Euler Problem #4
findPalindrome :: Int
findPalindrome = maximum [x | y <- [100..999], z <- [y..999], let x = y * z, let s = show x, s == reverse s]
@geowa4
geowa4 / euler5.hs
Created February 8, 2013 01:22
Project Euler Problem #5
import Data.List (foldr1)
euler5 :: Int
euler5 = foldr1 lcm [1..20]