Skip to content

Instantly share code, notes, and snippets.

View icholy's full-sized avatar
💥
breaking things

Ilia Choly icholy

💥
breaking things
View GitHub Profile
express = require 'express'
httpProxy = require 'http-proxy'
sysPath = require 'path'
config = require('./config').config
startExpress = (port, base, path, callback) ->
server = express()
server.use (request, response, next) ->
response.header 'Cache-Control', 'no-cache'
next()
exports.config =
# other stuff ...
server:
path: 'server.coffee'
port: 3333
run: yes
routes: [
{ host: '127.0.0.1', port: 80, re: /\/blocks/ } # apache redirect
@icholy
icholy / go_zsh_complete.md
Last active January 9, 2022 19:19
Zsh Tab Completion for Golang

Zsh Tab Completion for Golang

This is pretty specific to my setup but the idea can be adapted to work with pretty much anything.

Go has a flag package which makes parsing command line arguments really easy.

package main
@icholy
icholy / _godoc
Last active February 17, 2022 19:17
godoc completions
#compdef godoc
typeset -A opt_args
local context state line
local pkgdir usrpkgdir
pkgdir="$GOROOT/src/pkg"
usrpkgdir="$GOPATH/src"
godoctmpl=~/.godoc_templates
@icholy
icholy / bit_flags.go
Last active December 15, 2015 23:10
Bit flags in Go
package main
// explicite
const (
SAY_NIL = 0x00 // 0b00000000
SAY_HELLO = 0x01 // 0b00000001
SAY_FOO = 0x02 // 0b00000010
SAY_BYE = 0x04 // 0b00000100
)
# show welcome message
ZSH_HINTS=()
ZSH_HINTS+=("CTRL + A Move to the beginning of the line")
ZSH_HINTS+=("CTRL + E Move to the end of the line")
ZSH_HINTS+=("CTRL + [left arrow] Move one word backward (on some systems this is ALT + B)")
ZSH_HINTS+=("CTRL + [right arrow] Move one word forward (on some systems this is ALT + F)")
ZSH_HINTS+=("CTRL + U (bash) Clear the characters on the line before the current cursor position")
ZSH_HINTS+=("CTRL + U (zsh) If you're using the zsh, this will clear the entire line")
ZSH_HINTS+=("CTRL + K Clear the characters on the line after the current cursor position")
ZSH_HINTS+=("C + [backspace] Delete the word in front of the cursor")
@icholy
icholy / gist:5396374
Created April 16, 2013 14:31
golang watch/recompile
# watch/recompile go
function gowatch () {
echo
echo "Watching files in $(pwd)"
echo
ls | grep ".go$" | while read go_file; do
echo " - $go_file"
done
echo
while true; do
@icholy
icholy / tips.md
Last active December 16, 2015 12:38
Go Tips

1. strings, slices and interfaces are reference type, so pass them by value

src: http://research.swtch.com/godata

// don't do this
func foo(s *string) { fmt.Printf("The String: %s", *s) }
// do this
@icholy
icholy / map_filter_reduce.go
Last active February 20, 2017 01:44
chaining channels in go
package main
import (
"unicode/utf8"
)
type Item string
type Stream chan Item
type Acc string
@icholy
icholy / better_stream.go
Last active December 16, 2015 15:09
Go stream chaining with error handling
package main
import (
"errors"
"log"
)
type Item struct {
val string
err error