Skip to content

Instantly share code, notes, and snippets.

View lcaballero's full-sized avatar

Lucas Caballero lcaballero

View GitHub Profile
@lcaballero
lcaballero / indent-lines.go
Created September 17, 2015 21:02
Golang line reading that indents.
func IndentLines(indent, code string) string {
reader := bufio.NewReader(bytes.NewBufferString(code))
buf := bytes.NewBufferString("")
line, prefix, err := reader.ReadLine()
for err == nil && line != nil {
if !prefix {
buf.WriteString(indent)
}
@lcaballero
lcaballero / connection-handling.go
Created September 22, 2015 22:32
Go example of connection based handling
type Db struct {
db *bolt.DB
err error
}
func (d *Db) start() *bolt.DB {
d.db, d.err = bolt.Open("my.db", 0600, nil)
if d.err != nil {
fmt.Println(d.err)
}
@lcaballero
lcaballero / stylus-hasing-iterate
Created September 23, 2015 21:51
Stylus example of iterating over a hash
colors = {
green: #38ab0b
red: #ab130b
blue: #099aab
}
for name, color in colors
.btn-{name}
background: mix(color, white, 60%)
&:hover
@lcaballero
lcaballero / loop.sh
Created October 8, 2015 17:36
Bash looping
#!/bin/bash
# Examples of Looping in Bash
tools=( git zsh emacs tmux mlocate open-vm-tools )
for r in "${tools[@]}"; do
echo $r
done
@lcaballero
lcaballero / more-bash-loops.sh
Created November 5, 2015 04:47
more bash loops
#!/bin/bash
function clean() {
rm -rf a b c
}
function _a() {
mkdir a
}
@lcaballero
lcaballero / facets.go
Created January 8, 2016 18:40
Reflection that produces all related reflect package types.
package lookup
import "reflect"
type Lookup struct {
target interface{}
}
type Facet struct {
Method reflect.Method
@lcaballero
lcaballero / launch_godoc.sh
Created February 17, 2016 00:07
Launches godoc from inside a package opening the doc for that package.
#!/bin/bash
function godoc_procs() {
ps -ef | grep 'godoc -http=:1212' | grep -v grep | cut -f 2 -d ' '
}
function launch_godoc() {
procs=$(godoc_procs)
if [ "$procs" -gt 1 ]; then
godoc_procs | xargs kill -9
;;; go-template-mode.el --- Major mode for Go template language
;;; Commentary:
;; 1) Copy this file somewhere in your Emacs `load-path'. To see what
;; your `load-path' is, run inside emacs: C-h v load-path<RET>
;;
;; 2) Add the following to your .emacs file:
;;
;; (require 'go-template-mode)
@lcaballero
lcaballero / shortcut-summary.txt
Created March 5, 2016 22:58
List of iterm2 remapping -- just so I remember
alt-, => cmd-, do not remapped modifier
al-1 => Unicode char ¡ so that in emacs I can bind cmd-1 to neotree-toggle
c-shift-b => M-f forward-word
c-shift-f => M-b backward-word
alt-b => C-b forward-char
alt-i => M-i other-window -1
alt-o => M-o other-window +1
alt-k => M-k kill-buffer
alt-tab => cmd-tab do not remap modifier
@lcaballero
lcaballero / nginx.min.tpl.conf
Created April 10, 2016 10:51
Template for a minimal nginx.conf
## Fill in the areas with the [custom] label.
#user nobody;
worker_processes 1;
error_log [custom]/error.log;
events {
worker_connections 1024;
}