View RegEx-Dates
\w{3}\s\d+,\s\d{4}
Matches both "May 15, 1980", and "May 5, 1980"
View parse-read-books.py
with open('books.txt') as f_old, open('newbook.txt', 'w+') as f_new:
for line in f_old:
if "[" in line and "]" in line:
# Process the line only if it has the "[" and "]" characters
book_name, sep1, old_date_str = line.partition("[")
_, _, book_name = book_name.partition("-")
month, _, tmp = old_date_str.partition("/")
day, _, tmp = tmp.partition("/")
year, _, _ = tmp.partition("]")
View program.js
// Note: Does not use any external node.js packages.
// *** Exercise 9: JUGGLING ASYNC
var http = require('http');
var count = 3;
var urls = process.argv.slice(2);
var results = [];
function httpGet(index)
View huffman.hs
-- Problem 50, 99 Haskell Problems (https://wiki.haskell.org/99_questions/46_to_50)
{-# OPTIONS_GHC -Wall #-}
import Data.Ord(comparing)
import Data.List(sortBy)
huffman :: [(Char, Int)] -> [(Char, String)]
huffman = sortBy (comparing fst) . (serializeHTree . buildHTree . createHTreeList)
View miscellaneous.hs
-- a function that's equivalent to the standard library's sequence function
myseq ms = foldr k ([[]]) ms
where k m m' = [x:xs | x <- m, xs <- m']
-- another variant of the sequence function, uses return [] instead of [[]]
myseq1 ms = foldr k (return []) ms
where k m m' = [x:xs | x <- m, xs <- m']
View arithmetic.hs
-- Miscellaneous arithmetic functions
-- Square roots using Newton's method
sqrtNewton :: (Floating a, Ord a) => a -> a
sqrtNewton n = head $ dropWhile (\g -> abs(n - g^2) > tolerance) $ iterate (newGuess n) 1
where
tolerance = 0.000001
newGuess :: Floating a => a -> a -> a
newGuess n oldGuess = (oldGuess + n / oldGuess) / 2
View pascal-triangle.hs
-- Takes an array of integers, and adds pairs of numbers to create a new
-- array. For example, [1,2,3,4] changes to [(1+2), (2+3), (3+4)], resulting
-- in [3,5,7]
sumOfPairs :: [Integer] -> [Integer]
sumOfPairs [] = []
sumOfPairs (x:[]) = []
sumOfPairs (x:y:ys) = (x+y) : sumOfPairs (y:ys)
-- Given a row of Pascal's triangle, returns the next row
View list-index-ops.hs
-- Index based list operations using folds
--
-- Author: Umair Saeed
-- Date: 05/17/2015
--
-- insert at an index, implemented via foldr
insertAt :: a -> [a] -> Int -> [a]
insertAt x ys n = foldr insertHelper [] $ zip [0..] ys
where