Skip to content

Instantly share code, notes, and snippets.

View jakecoffman's full-sized avatar

Jake Coffman jakecoffman

View GitHub Profile
@jakecoffman
jakecoffman / go_functional.go
Last active December 14, 2021 16:04
Example of functional programming in Golang.
package main
import (
"constraints"
"fmt"
)
func main() {
fmt.Println(Sum(1, 2, 3, 4))
fmt.Println(Sum("1", "2", "3"))
@jakecoffman
jakecoffman / generator.go
Last active August 29, 2015 14:01
Python style generator in Golang example
package main
import "fmt"
func main() {
gen := GetIncrementor()
for i := gen(); i <= 10; i = gen() {
fmt.Println(i)
}
}
@jakecoffman
jakecoffman / main.go
Created July 10, 2014 18:22
Simple Negroni example
package main
import (
"log"
"net/http"
"github.com/codegangsta/negroni"
)
func Mids() negroni.HandlerFunc {
@jakecoffman
jakecoffman / resizer.go
Last active August 7, 2017 08:02
Resize all images in a directory (Golang)
package main
import (
"fmt"
"image/jpeg"
"io/ioutil"
"log"
"os"
"strings"
@jakecoffman
jakecoffman / modifying_proxy.go
Last active August 29, 2015 14:05
Golang reverse proxy.
package main
import (
"log"
"net/http"
"net/http/httputil"
"net/url"
)
func main() {
@jakecoffman
jakecoffman / transducer.py
Last active August 29, 2015 14:07
transducers in python
def even(gen):
for i in gen:
if i % 2 == 0:
yield i
def stringify(gen):
for i in gen:
yield str(i)
def transduce(gen):
@jakecoffman
jakecoffman / pipeline.go
Created January 9, 2015 16:11
Unix-y pipelines in Go (functional programming)
package main
import (
"bufio"
"fmt"
"log"
"os"
"runtime"
"strings"
)
@jakecoffman
jakecoffman / monads.go
Created March 29, 2015 15:29
Go monads
package main
import "fmt"
type Monad interface {
Bind(func(interface{}, Monad) Monad) Monad
Return(interface{}) Monad
}
// First, let's do Maybe
@jakecoffman
jakecoffman / ldap.groovy
Created September 9, 2015 14:42
apache directory ldap ssl example
package com.jakecoffman.ldap
import org.apache.directory.api.ldap.model.entry.DefaultEntry
import org.apache.directory.api.ldap.model.message.SearchScope
import org.apache.directory.ldap.client.api.LdapConnectionConfig
import org.apache.directory.ldap.client.api.LdapNetworkConnection
import org.apache.directory.ldap.client.api.NoVerificationTrustManager
// I hope this helps someone
def sslConfig = new LdapConnectionConfig()
@jakecoffman
jakecoffman / main.groovy
Last active September 15, 2015 01:25
example implementation of the visitor pattern in groovy
def randomElement
// simulate user input, for instance
if (new Random().nextInt() % 2 == 0) {
randomElement = new Element1()
} else {
randomElement = new Element2()
}
new PrinterVisitor().visit(randomElement)