Skip to content

Instantly share code, notes, and snippets.

View cdemers's full-sized avatar

Charle Demers cdemers

  • Wellington & King, Inc.
  • Montreal
  • 00:21 (UTC -04:00)
View GitHub Profile
@cdemers
cdemers / SampleGoHttpPost.go
Created May 5, 2016 13:33
Sample Go program that does an HTTP post of a JSON payload, includes setting request headers, doing the request, getting the response and printing it out.
func main() {
var jsonBuffer = []byte(`{"my_key":"My Value."}`)
req, _ := http.NewRequest("POST", "http://api.mycompany.com", bytes.NewBuffer(jsonBuffer))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
#!/bin/sh
# Starts a bash within a container running on Kubernetes while initializing
# the terminal type to xterm and the size to your actual terminal size. Makes
# it possible to have vi, more, etc work in a usable way until PR #25273 is
# merged. Derived from a snip by Hubert Chen (https://github.com/hubt)
if [ "$1" = "" ]; then
echo "Usage: kbash.sh {pod} [container]"
exit 1
fi
// === BEGIN ===
[Unit]
Description=Datadog Agent
After=multi-user.target
[Service]
Type=idle
ExecStart=/the_path/.datadog-agent/bin/agent
Restart=always
# Stop all local containers
docker stop $(docker ps -a)
# Remove all local containers
docker rm $(docker ps -a -q)
# This bashrc is aimed at clustered CoreOS marchines running on
# VMware. It will display the IP of the ens192 VMware interface
# in the prompt, which is useful to identify the host in a cattle
# type cluster.
if [[ $- != *i* ]] ; then
# Shell is non-interactive. Be done now!
return
fi
@cdemers
cdemers / format_float.go
Created January 18, 2017 03:24
Go (golang) float formatting WITHOUT rounding
s := fmt.Sprintf("%.4f", 10/6.0)[0:5]
@cdemers
cdemers / spinner.go
Last active March 15, 2017 14:26
Quicky spinner Go (golang) code using the nice briandowns' spinner library
import "github.com/briandowns/spinner"
someSillySet := []string{"🐶", "🐱", "🐭", "🐹", "🐰", "🐻", "🐼", "🐨", "🐯", "🦁"}
s := spinner.New(someSillySet, 100*time.Millisecond)
// or
s := spinner.New(spinner.CharSets[9], 75*time.Millisecond)
s.Start()
defer s.Stop()
@cdemers
cdemers / ar_and_xz_reader.go
Created May 4, 2017 15:59
Sample code to read content from a .deb file in Go
package main
import (
"archive/tar"
"bytes"
"io"
"log"
"os"
"github.com/blakesmith/ar"
@cdemers
cdemers / not_sourced_detection.bash
Created August 3, 2017 18:56
Warning for scripts that should be sourced, instead of executed.
[[ $_ == $0 ]] && echo "This script should probably be sourced."
@cdemers
cdemers / CoreOS_install_socat.sh
Last active September 14, 2017 19:08
Install the socat binary into a CoreOS installation
# Insightful instructions, originally posted by Xynova (https://github.com/xynova)
# Make socat directories
mkdir -p /opt/bin/socat.d/bin /opt/bin/socat.d/lib
# Create socat wrapper
cat << EOF > /opt/bin/socat
#! /bin/bash
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/opt/bin
LD_LIBRARY_PATH=/opt/bin/socat.d/lib:$LD_LIBRARY_PATH exec /opt/bin/socat.d/bin/socat "\$@"