Skip to content

Instantly share code, notes, and snippets.

View russmatney's full-sized avatar

Russell Matney russmatney

View GitHub Profile
@russmatney
russmatney / Full JS test with mocked service
Last active August 29, 2015 13:56
Angular Controller Unit tests, featuring a mocked service
'use strict';
describe('Controller: ScenesCtrl', function(){
beforeEach(module('app'));
var scope, scenesCtrl;
var actId = '987';
var listOfScenes = [
{_id: '123', name:'scene one'},
{_id: '456', name:'scene two'}
];
@russmatney
russmatney / pig-latin-filter.coffee
Created September 29, 2013 00:40
Basic CoffeeScript + AngularJS Pig-latin filter + unit tests. Only moves first letter at the moment. AngularJS filters are my favorite TDD.
'use strict';
angular.module('pig-latin', [])
.filter 'pig-latin', () ->
# input is handed into the filter
(input) ->
# equals itself or ''
input ||= ''
if input.length > 0

Keybase proof

I hereby claim:

  • I am russmatney on github.
  • I am russmatney (https://keybase.io/russmatney) on keybase.
  • I have a public key whose fingerprint is 3378 B53A B12A 8811 99F2 0F0C 38B4 5CA1 46C8 CD72

To claim this, I am signing this object:

viewExamples :: IO ()
viewExamples = do
let bob = User (UserName "Bob") 42 Nothing HM.empty
print "Bob's name is: "
print $ view userName bob
-- UserName "bob"
print $ bob ^. userName
-- UserName "bob"
composedViewExamples :: IO ()
composedViewExamples = do
let
bob = User (UserName "bob") 42 Nothing HM.empty
fitzgerald = Pet (PetName "Fitzgerald")
jeff = User (UserName "jeff") 42 (Just fitzgerald) HM.empty
print "Bob's pet's name is: "
print $ preview (pet . _Just . petName) bob
-- Nothing
previewExamples :: IO ()
previewExamples = do
let maybeIntA = Just 1
-- Have to tell the compiler this was a 'Maybe Int' for it to be printable
maybeIntB = Nothing :: Maybe Int
print "maybeIntA"
print $ maybeIntA ^? _Just
-- Just 1
print "maybeIntB"
setExamples :: IO ()
setExamples = do
let bob = User (UserName "bob") 0 Nothing HM.empty
print "Bob, with an updated score"
print $ set score 42 bob
-- User {_userName = UserName "bob", _userScore = 42, _userPet = Nothing, _userInventory = fromList []}
print $ (score .~ 42) bob
-- User {_userName = UserName "bob", _userScore = 42, _userPet = Nothing, _userInventory = fromList []}
fancySetExamples :: IO ()
fancySetExamples = do
let bob = User (UserName "bob") 0 Nothing HM.empty
-- check out this multi-line string, why don't ya?
print "Bob changes his name to 'Bill'\
\, updates his score, and now owns Jeff's pet fish,\
\who is named Fitzgerald."
print $
bob
-- StorageError in a module somewhere
newtype StorageError = StorageError Text deriving (Eq, Show)
-- WebError wraps storage Error
data WebError
= WebTextError Text
| WebStorageError StorageError
deriving (Eq, Show)
-- Let's convert an 'Either StorageError a' to an 'Either WebError a'
atIxExamples :: IO ()
atIxExamples = do
-- Yep, you can use apostrophes in var names. Not that you should...
let bob'sInventory = HM.fromList [ ("gold", Item 99 10)
, ("silver", Item 10 9)
]
bob = User (UserName "bob") 42 Nothing bob'sInventory
print "Printing Bob's gold value"
print $ bob ^? inventory . at "gold" . _Just . value