Skip to content

Instantly share code, notes, and snippets.

search_exported_names() {
local export_name="$1"
local file_list
local count
count=$(rg -F --type-add 'ts:*.ts' --type-add 'tsx:*.tsx' --type 'ts' --type 'tsx' -c --no-filename "${export_name}" < /dev/null | awk '{sum += $1} END {print sum}' || echo "0")
echo "Search term: ${export_name} - Count: ${count}"
}
@wrhall
wrhall / pe049.hs
Created August 17, 2014 17:22
A couple solutions to project euler 49.
import qualified Data.Set as Set
import qualified Data.Numbers.Primes as Primes
import Data.List (sort)
import Control.Monad
arePerms :: (Integral a, Show a) => a -> a -> Bool
arePerms a b = ((sort $ show a) == (sort $ show b))
fourDigitPrimes :: [Integer]
fourDigitPrimes = takeWhile (<10000) $ dropWhile (<1000) Primes.primes
@wrhall
wrhall / learnHaskell.md
Last active February 12, 2016 20:15
Complete Beginners Guide to Learning Haskell

I've thought about it a little, and here are my ideas about some good starting points for a new Haskeller. Note -- this is not meant to be a list of every blog or article about haskell.

It isn't trying to point to every tutorial or language reference. It is trying to describe a roughly linear path a newcomer to Haskell could follow without ever feeling completely over their head.

With that in mind, please tweet any suggestions for additional content to @wrhall (or fork!)

Complete beginner

@wrhall
wrhall / majority.hs
Last active August 29, 2015 14:01
Majority Element Algorithm implemented in Haskell
module Majority
( isMajority
, majority
, occurrences
) where
majority :: Eq a => [a] -> Maybe a
majority [] = Nothing
majority xs'@(x: xs) = if isMajority majority' xs' then Just majority' else Nothing
where
@wrhall
wrhall / InsertSort.md
Last active August 29, 2015 13:59
A small blurb about Insert Sort in Haskell (and Python)

This is completely inspired by the paper linked here: http://www.cs.ox.ac.uk/people/daniel.james/sorting/sorting.pdf

In brief

Insert Sort is a method of sorting in which you "reinsert" each element into the list of elements before it. Essentially, for each element, you move that element left past each element that is bigger than it.

The algorithmic invariant you have is that the list up to the current element is sorted.

Python

@wrhall
wrhall / sieve.py
Created November 5, 2013 03:55
Sieve (quickly thrown together)
6 import math
7
8 def sieve(n):
9 a = range(n+1)
10 a[1] = 0
11 index = 0
12 while index < len(a):
13 if a[index] != 0:
14 increment = a[index]
15 for i in xrange(2*increment, len(a), increment):
@wrhall
wrhall / dot_prod.py
Last active December 26, 2015 06:08
Fast, low-dependency dot product in Python
from itertools import imap
import operator
def dot_prod(v1, v2):
return sum(imap(operator.mul, v1, v2))
@wrhall
wrhall / merge_sort.rb
Created September 6, 2013 18:17
Sample code from a blog post I wrote
def merge_sort(a)
return a if a.length <= 1
first_half = a.first(a.length / 2)
second_half = a.last(a.length - a.length / 2)
sorted_first_half = merge_sort(first_half)
sorted_second_half = merge_sort(second_half)
merge_step(sorted_first_half, sorted_second_half)
end