Skip to content

Instantly share code, notes, and snippets.

@mattmcla
mattmcla / cleanpy
Created December 8, 2011 19:17
PEP8 Python file scrubbing
#!/bin/bash -e
# Text color variables
txtund=$(tput sgr 0 1) # Underline
txtbld=$(tput bold) # Bold
txtred=$(tput setaf 1) # Red
txtgrn=$(tput setaf 2) # Green
txtylw=$(tput setaf 3) # Yellow
txtblu=$(tput setaf 4) # Blue
txtpur=$(tput setaf 5) # Purple
@mattmcla
mattmcla / cleanpy
Created January 5, 2012 00:05
cleanpy
#!/bin/bash -e
# Text color variables
txtund=$(tput sgr 0 1) # Underline
txtbld=$(tput bold) # Bold
txtred=$(tput setaf 1) # Red
txtgrn=$(tput setaf 2) # Green
txtylw=$(tput setaf 3) # Yellow
txtblu=$(tput setaf 4) # Blue
txtpur=$(tput setaf 5) # Purple
@mattmcla
mattmcla / commit-msg
Last active December 14, 2015 06:19
#!/bin/sh
#
# Automatically adds branch name every commit message.
#
NAME=$(git branch | grep '*' | sed 's/* //')
TEXT=$(cat "$1" | sed '/^#.*/d')
if [ -n "$TEXT" ]
then
echo "[$NAME]"' '$(cat "$1" | sed '/^#.*/d') > "$1"
export OI_TOKEN=<your orchestrate token here>
curl https://api.orchestrate.io/v0/movies/1 \
-X PUT \
-i \
-H 'Content-Type:application/json' \
-u "$OI_TOKEN:" \
-d '{"title": "Tremors","released": "1990","description": "Natives of a small isolated town defend themselves against strange underground creatures which are killing them one by one.", "genres": ["comedy","horror","sci-fi"],"actors": ["Kevin Bacon","Fred Ward","Finn Carter"]}'
curl https://api.orchestrate.io/v0/movies/2 \
export OI_TOKEN=<your orchestrate token here>
curl https://api.orchestrate.io/v0/movies/1 \
-X PUT \
-i \
-H 'Content-Type:application/json' \
-u "$OI_TOKEN:" \
-d '{"title": "Tremors","released": "1990","description": "Natives of a small isolated town defend themselves against strange underground creatures which are killing them one by one.", "genres": ["comedy","horror","sci-fi"]}'
curl https://api.orchestrate.io/v0/movies/2 \
export OI_TOKEN=<your orchestrate token here>
curl https://api.orchestrate.io/v0/actors/1 \
-X PUT \
-i \
-H 'Content-Type:application/json' \
-u "$OI_TOKEN:" \
-d '{"name": "Kevin Bacon"}'
curl https://api.orchestrate.io/v0/actors/2 \
curl -i "https://api.orchestrate.io/v0/movies/1/relation/actor/actors/1" -u "$OI_TOKEN:" -X PUT
curl -i "https://api.orchestrate.io/v0/movies/1/relation/actor/actors/2" -u "$OI_TOKEN:" -X PUT
curl -i "https://api.orchestrate.io/v0/movies/1/relation/actor/actors/3" -u "$OI_TOKEN:" -X PUT
curl -i "https://api.orchestrate.io/v0/movies/2/relation/actor/actors/1" -u "$OI_TOKEN:" -X PUT
curl -i "https://api.orchestrate.io/v0/movies/2/relation/actor/actors/4" -u "$OI_TOKEN:" -X PUT
curl -i "https://api.orchestrate.io/v0/movies/2/relation/actor/actors/5" -u "$OI_TOKEN:" -X PUT
curl -i "https://api.orchestrate.io/v0/movies/3/relation/actor/actors/1" -u "$OI_TOKEN:" -X PUT
curl -i "https://api.orchestrate.io/v0/movies/3/relation/actor/actors/6" -u "$OI_TOKEN:" -X PUT
curl -i "https://api.orchestrate.io/v0/movies/3/relation/actor/actors/7" -u "$OI_TOKEN:" -X PUT
@mattmcla
mattmcla / main-with-middleware.go
Last active April 18, 2016 18:27
Custom Headers on Every Response With golangs httprouter
func main() {
r := httprouter.New()
// Health check
r.GET(“/health”, HealthCheckHandler)
// Authentication
r.POST(“/token-auth”, HeaderMiddleware(TokenAuthHandler))
r.POST(“/p”, HeaderMiddleware(SomeFormHandler))
fmt.Println(“Starting server on :3030”)
http.ListenAndServe(“:3030”, r)
}
func main() {
r := httprouter.New()
// Health check
r.GET(“/health”, HealthCheckHandler)
// Authentication
r.POST(“/token-auth”, TokenAuthHandler)
r.POST(“/p”, AuthMiddleware(SomeFormHandler))
fmt.Println(“Starting server on :3030”)
http.ListenAndServe(“:3030”, &Server{r})
}
func (s *Server) ServeHTTP (w http.ResponseWriter, r *http.Request) {
w.Header().Set(“Access-Control-Allow-Origin”, “*”)
w.Header().Set(“Access-Control-Allow-Headers”, “Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization”)
s.r.ServeHTTP(w, r)
}