Skip to content

Instantly share code, notes, and snippets.

@aparrish
aparrish / understanding-word-vectors.ipynb
Last active April 29, 2024 17:57
Understanding word vectors: A tutorial for "Reading and Writing Electronic Text," a class I teach at ITP. (Python 2.7) Code examples released under CC0 https://creativecommons.org/choose/zero/, other text released under CC BY 4.0 https://creativecommons.org/licenses/by/4.0/
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@aparrish
aparrish / spacy_intro.ipynb
Last active August 9, 2023 01:41
NLP Concepts with spaCy. Code examples released under CC0 https://creativecommons.org/choose/zero/, other text released under CC BY 4.0 https://creativecommons.org/licenses/by/4.0/
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cb372
cb372 / jargon.md
Last active May 8, 2023 16:03
Category theory jargon cheat sheet

Category theory jargon cheat sheet

A primer/refresher on the category theory concepts that most commonly crop up in conversations about Scala or FP. (Because it's embarassing when I forget this stuff!)

I'll be assuming Scalaz imports in code samples, and some of the code may be pseudo-Scala.

Functor

A functor is something that supports map.

@soc
soc / gist:8454725
Created January 16, 2014 13:07
My experience with C#
I did a small project in C# recently, and I basically assumed
that coming from Scala I could enjoy all the benefits of a
(more) mainstream language and a polished, integrated
ecosystem.
Boy was I wrong.
My experience starts with installing Microsoft's latest Visual
Studio 2013 Express Desktop IDE which went really smooth.
@vmarquez
vmarquez / Polymorphism.scala
Last active December 23, 2015 09:49
Two implementations of a Design by Contract Cache interface. Parametric Polymorphism is more flexible than subtype polymorphism.
case class GenericCache[A[_,_], B, C](instance: A[B,C], getf: B=>C, putf: (B,C)=>Unit) {
def retrieve(b: B) = getf(b)
def insert(b: B, c: C) = putf(b,c)
}
//Notice how neither cache implementations have to even be aware of the existnace of the typeclass. much more flexible than inheritance
class FastCache[A,B] {
private var m = Map[A,B]() //excuse mutability for illustration purposes
def add(a: A, b: B): Unit = {
m = m + (a->b)
@puffnfresh
puffnfresh / getinstance.js
Created March 29, 2013 02:04
Two nice helper functions for creating constructors in JavaScript.
// Polyfill for Object.create
function create(proto) {
function Ctor() {}
Ctor.prototype = proto;
return new Ctor();
}
// Always returns an instance of constructor
function getInstance(self, constructor) {
return self instanceof constructor ? self : create(constructor.prototype);
@fogus
fogus / gist:5163546
Last active December 14, 2015 23:09
How do I say this Haskell?
-- THE SEARCH CONTINUES
data GenericThing = SpecificThing Char
| DifferentSpecificThing Double
| AnotherSpecificThing String
| YetAnotherDifferentSpecificThing Integer
foo :: [GenericThing] -> GenericThing
foo [] = return $ AnotherSpecificThing ""
foo [SpecificThing one] = -- do something
(use '[clojure.core.logic])
(require '[clojure.core.logic.fd :as fd])
(defn simple []
(run* [x y]
(fd/in x y (fd/interval 0 9))
(fd/eq
(= (+ x y) 9)
(= (+ (* 4 x) (* 2 y)) 24))))
@tonymorris
tonymorris / TReader.scala
Created October 13, 2012 11:16
Reader monad in Scala
case class T() // your data type that you want to "implicitly" thread through
case class TReader[+A](run: T => A) {
def map[B](f: A => B): TReader[B] =
sys.error("VFJlYWRlcihmIGNvbXBvc2UgcnVuKQ==")
def flatMap[B](f: A => TReader[B]): TReader[B] =
sys.error("VFJlYWRlcih0ID0+IGYocnVuKHQpKSBydW4gdCk=")
def &&&[B](x: TReader[B]): TReader[(A, B)] =
@tonymorris
tonymorris / TypeClass.hs
Last active September 15, 2020 13:17
Type-class hierarchy
Moved to https://github.com/tonymorris/type-class