This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import randint | |
from sortedcontainers import SortedList | |
def rollingMedian(xs): | |
prior_values = SortedList() | |
for x in xs: | |
if len(prior_values): | |
yield prior_values[len(prior_values)//2] | |
else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_ = require 'underscore' | |
# Pure functional (with foldl and filter) | |
countZeroes1 = (xs) -> count1 (_.filter xs, (x) -> x == 0) | |
count1 = (xs) -> _.foldl xs, ((l, r) -> l + 1), 0 | |
# Pure function (with list length -- usually available in function setting) | |
countZeroes2 = (xs) -> (_.filter xs, (x) -> x == 0).length | |
# Underscore 'chain'... has some functional aspects to it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkLoader = (thingToLoad) -> | |
-> console.log "loading #{thingToLoad}" | |
console.log 'create loaders' | |
loaderA = mkLoader 'foo' | |
loaderB = mkLoader 'bar' | |
console.log 'begin loading' | |
loaderA() | |
loaderB() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A lonely import (for the very end) | |
> import Control.Applicative | |
Given some association list (like a map, but slower) | |
> myMap :: [(String, Integer)] | |
> myMap = [("Small", 1), ("Big", 2)] | |
And a function that deals with two numbers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Perhaps a = Definitely a | NoWay deriving Show | |
perhapsMap :: (a -> b) -> Perhaps a -> Perhaps b | |
perhapsMap f (Definitely x) = Definitely (f x) | |
perhapsMap f NoWay = NoWay | |
main = do | |
print $ perhapsMap (+2) (Definitely 10) | |
print $ perhapsMap (+2) (NoWay) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import maybe.Maybe; | |
import maybe.Mapper; | |
public class Main { | |
public static void main(String[] args) { | |
Mapper<Integer> addTwo = new Mapper<Integer>() { | |
public Integer map(Integer value) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CoverPhoto = Backbone.Model.extend | |
urlRoot: "https://graph.facebook.com/" | |
Album = Backbone.Model.extend {} | |
AlbumList = Backbone.Collection.extend | |
url: "https://graph.facebook.com/203771702995922/albums" | |
model: Album | |
parse: (response) -> response['data'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
var Album, AlbumList, AlbumView, Albums, App, AppView; | |
Album = Backbone.Model.extend({ | |
defaults: function() { | |
return { | |
source: null, | |
name: 'Unnamed Album' | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Backbone with Mighty Moo Photos</title> | |
</head> | |
<body> | |
<ul id="albums-list"> | |
</ul> | |
<ul id="friends-list"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ldp :: Integer -> Integer | |
ldp = ldpf primes1 | |
ldpf :: [Integer] -> Integer -> Integer | |
ldpf (p:ps) n | rem n p == 0 = p | |
| p^2 > n = n | |
| otherwise = ldpf ps n | |
primes1 :: [Integer] | |
primes1 = 2 : filter prime [3..] |
NewerOlder