Skip to content

Instantly share code, notes, and snippets.

View cdemers's full-sized avatar

Charle Demers cdemers

  • Wellington & King, Inc.
  • Montreal
  • 08:30 (UTC -05: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 {
@cdemers
cdemers / Installing a Go development environment on Mac OS for beginners.md
Last active June 21, 2020 20:08
How to install a functional Go development environment on MacOS with Atom and all the bells and whistles.

Warning! This doc is pretty outdated, I'm rewriting it right now and I'll update this as soon as it's done.


Installing a Go development environment on Mac OS for Beginners

Installing Go

First, install the Go compiler from Google's Go Website: https://golang.org/dl/

#!/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
# Python code sample to listen to TCP multicast traffic on
# port 67 (?), which should be traffic destined to a DHCP server
# that will listen to multicast on that port.
# Tested on OSX.
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
# Next line might or might not work, depending on your platform.
# 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
// === 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)
@cdemers
cdemers / raspi-blacklist.conf
Last active May 27, 2019 18:14
Disable WiFi and Bluetooth on a Raspberry Pi 3
# To disable WiFi and Bluetooth on a Raspberry Pi 3, there is
# no other way (yet) than to add this file to the modprobe.d
# folder (/etc/modprobe.d/raspi-blacklist.conf)
# Prevents WiFi:
blacklist brcmfmac
blacklist brcmutil
# Prevents Bluetooth:
blacklist btbcm
@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 / 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 "\$@"