Skip to content

Instantly share code, notes, and snippets.

View tmountain's full-sized avatar

Travis Whitton tmountain

View GitHub Profile
Travis-Whitton's-MacBook-Pro:nix traviswhitton$ cat node.nix
# This imports the nix package collection,
# so we can access the `pkgs` and `stdenv` variables
with import <nixpkgs> {};
# Make a new "derivation" that represents our shell
stdenv.mkDerivation {
name = "my-environment";
# The packages in the `buildInputs` list will be added to the PATH in our shell
@tmountain
tmountain / gen_rel_table.rb
Created November 15, 2018 22:16
Generates a table of farmers/cows given a file with one name per line.
#!/usr/bin/ruby
fh = File.new('names.csv', 'r')
names = []
while line = fh.gets
line.chomp!
names << line
end
names = names.shuffle
Scalable program architectures
Haskell design patterns differ from mainstream design patterns in one important way:
Conventional architecture: Combine a several components together of type A to generate a "network" or "topology" of type B
Haskell architecture: Combine several components together of type A to generate a new component of the same type A, indistinguishable in character from its substituent parts
This distinction affects how the two architectural styles evolve as code bases grow.
The conventional architecture requires layering abstraction on top of abstraction:
module Shape where
import Data.List (nub)
data Circle = Circle { radius :: Float }
data Triangle = Triangle { a :: Float, b :: Float, c :: Float }
class Dimensions shape where
name :: shape -> String
@tmountain
tmountain / chapter4.purs
Created October 24, 2018 12:41
Purescript by Example Solutions (Chapter 4)
module Even where
import Prelude
import Data.Foldable (product)
import Data.Array (concatMap, null, sort, filter, length, (..))
import Data.Array.Partial (head, tail)
import Partial.Unsafe (unsafePartial)
import Control.MonadZero (guard)
@tmountain
tmountain / folds.hs
Created October 24, 2018 12:39
Lazy vs Non-Lazy Folds
-- lazy vs non-lazy folds
-- works on infinite lists
take 5 $ foldr (:) [] [1..]
-- infinite loop
cons' = flip (:) -- acc is first arg to foldl
take 5 $ foldl cons' [] [1..]
Optimization terminated successfully.
Current function value: 0.375376
Iterations: 6
Function evaluations: 6339
Logit Regression Results
==============================================================================
Dep. Variable: agency No. Observations: 31414
Model: Logit Df Residuals: 31315
Method: MLE Df Model: 98
Date: Thu, 19 Apr 2018 Pseudo R-squ.: 0.4584
Optimization terminated successfully.
Current function value: 0.272877
Iterations: 8
Function evaluations: 8498
Logit Regression Results
==============================================================================
Dep. Variable: agency No. Observations: 31414
Model: Logit Df Residuals: 31313
Method: MLE Df Model: 100
Date: Thu, 19 Apr 2018 Pseudo R-squ.: 0.6063
/usr/local/lib/python2.7/site-packages/statsmodels/compat/pandas.py:56: FutureWarning: The pandas.core.datetools module is deprecated and will be removed in a future version. Please use the pandas.tseries module instead.
from pandas.core import datetools
/usr/local/lib/python2.7/site-packages/statsmodels/discrete/discrete_model.py:1214: RuntimeWarning: overflow encountered in exp
return 1/(1+np.exp(-X))
/usr/local/lib/python2.7/site-packages/statsmodels/discrete/discrete_model.py:1264: RuntimeWarning: divide by zero encountered in log
return np.sum(np.log(self.cdf(q*np.dot(X,params))))
Warning: Maximum number of iterations has been exceeded.
Current function value: inf
Iterations: 35
Traceback (most recent call last):
module Main where
import Set
import Text.Pretty.Simple (pPrint)
c1 = Card { shape = Pill, color = Red, shade = Clear, count = One }
c2 = Card { shape = Squiggle, color = Purple, shade = Clear, count = Two }
c3 = Card { shape = Diamond, color = Green, shade = Clear, count = Three }
c4 = Card { shape = Squiggle, color = Purple, shade = Solid, count = Two }
c5 = Card { shape = Diamond, color = Green, shade = Solid, count = One }