Instantly share code, notes, and snippets.

View anonymous-gist.go
// p := profile.Start(profile.CPUProfile, profile.ProfilePath("/tmp/prof"), profile.NoShutdownHook)
p := profile.Start(profile.MemProfile, profile.ProfilePath("/tmp/prof"), profile.NoShutdownHook)
time.AfterFunc(time.Minute, func() {
fmt.Printf("1 minute until profiling stopped\n")
})
time.AfterFunc(time.Minute*2, func() {
fmt.Printf("stopping profiling\n")
p.Stop()
View anonymous-gist.go
func PrintMemUsage(id int, name string) {
var m runtime.MemStats
runtime.ReadMemStats(&m)
// For info on each, see: https://golang.org/pkg/runtime/#MemStats
fmt.Printf(
"Call %v from %v -- Alloc = %v MiB\tTotalAlloc = %v MiB\tSys = %v MiB\tNumGC = %v\n",
id,
name,
bToMb(m.Alloc),
bToMb(m.TotalAlloc),
View example-service.go
// PingMe ...
func (s *Service) PingMe(ctx context.Context, in *api.PingMessage) (*api.PongMessage, error) {
header := metadata.Pairs("header-key", "val")
err := grpc.SendHeader(ctx, header)
return &api.PongMessage{Response: fmt.Sprintf("pongback: %v", in.Greeting)}, err
}
// StreamIn ...
func (s *Service) StreamIn(stream api.Ping_StreamInServer) error {
count := 0
View k8s.yml
---
apiVersion: v1
kind: Service
metadata:
name: users
spec:
ports:
- port: 80
targetPort: 80
protocol: TCP
View battery-status
#!/bin/bash
#
# battery-status
#
# A quick little indicator for battery status on your Mac laptop, suitable for
# display in your prompt.
battery=$(upower -e | grep BAT)
state=$(upower -i $battery | grep state | tail -1 |awk -F":" '{print $2}' |sed -e 's/\s*//')
time_left=$(upower -i $battery |grep "time to empty" |tail -1 |awk -F":" '{print $2}' | sed -e 's/\s*//')
View oauth.go
package app
// Routes to handle validating user login against the auth app.
// Currently doesn't do anything because the Auth app isn't up yet. Need to get
// that deployed so this can be fleshed out.
import (
"fmt"
"github.com/KloudKtrl/internal/database"
"github.com/dgrijalva/jwt-go"
View email-customize.el
;; mu4e stuff
(require 'mu4e)
;; tell message-mode how to send mail
(setq message-send-mail-function 'smtpmail-send-it)
;; if our mail server lives at smtp.example.org; if you have a local
;; mail-server, simply use 'localhost' here.
(setq smtpmail-smtp-server "localhost")
(setq mu4e-view-prefer-html t)
View imap-passwords.py
#!/usr/bin/python
#import gtk
import gnomekeyring as gkey
import getpass
class Keyring(object):
def __init__(self, name, server, protocol):
self._name = name
self._server = server
View imap-passwords.py
#!/usr/bin/python
#import gtk
import gnomekeyring as gkey
import getpass
class Keyring(object):
def __init__(self, name, server, protocol):
self._name = name
self._server = server
View .offlineimap.py
#!/usr/bin/python
import sys
#import gtk
import gnomekeyring as gkey
class Keyring(object):
def __init__(self, name, server, protocol):
self._name = name
self._server = server