Skip to content

Instantly share code, notes, and snippets.

View hartfordfive's full-sized avatar

Alain L hartfordfive

View GitHub Profile
@hartfordfive
hartfordfive / signed_url.php
Created January 16, 2016 12:54
Created a singed URL for an Amazon S3 resource
<?php
// Your AWS secret key and access key
$secretKey = '[YOUR_SECRET_KEY]';
$awsAccessKey = '[YOUR_ACCESS_KEY]';
$bucket = 'my-bucket';
/**
* Calculate the HMAC SHA1 hash of a string.
@hartfordfive
hartfordfive / struct_tags_example.go
Created February 4, 2016 14:38
Accessing Go Struct Tags
package main
import (
"fmt"
"reflect"
)
type Person struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
@hartfordfive
hartfordfive / tcp-server.go
Created February 16, 2016 20:46
Simple Go TCP server with asynchronous writing to log file
package main
// Source: http://divan.github.io/posts/go_concurrency_visualize/
import (
"fmt"
"net"
"time"
)
@hartfordfive
hartfordfive / find-large-files.bash
Created February 20, 2016 12:53
Bash command to find large files
#!/bin/bash
DIR=$1
MAX_SIZE_BYTES=$2
echo "Last Modified, Size, File Path"
find ${DIR} -type f -size +${MAX_SIZE_BYTES}k -not -path "/proc/*" -exec ls -lh {} \; | awk '{ print $8 ": " $5 " " $9}'
@hartfordfive
hartfordfive / port_conn_top.sh
Created February 24, 2016 15:33
Get total number of active and closing connections for a given port
!/bin/bash
PORT=$1
if [ "$PORT" == "" ]; then
echo "Usage: $0 [PORT]"
exit 1
fi
while [ true ]
@hartfordfive
hartfordfive / response_hijack.go
Created March 20, 2016 11:11
Hijacking Golang http response
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
http.HandleFunc("/hijack", func(w http.ResponseWriter, r *http.Request) {
@hartfordfive
hartfordfive / gist:6db95bef1b2f07f64fca96e5a6436adf
Created April 17, 2016 22:59 — forked from grantr/gist:1105416
Chef mysql master/slave recipes
## mysql::master
ruby_block "store_mysql_master_status" do
block do
node.set[:mysql][:master] = true
m = Mysql.new("localhost", "root", node[:mysql][:server_root_password])
m.query("show master status") do |row|
row.each_hash do |h|
node.set[:mysql][:master_file] = h['File']
node.set[:mysql][:master_position] = h['Position']
end
@hartfordfive
hartfordfive / undo-commit.txt
Created April 18, 2016 17:31
Move accidental commit on "master" to another branch [Git]
In the situation you've accidentally already committed changes to your "master" branch and want the moved to a seperate branch:
git branch [NEW_BRANCH_NAME] # Create new branch with the changes you just committed
git reset --hard HEAD~[NUM_COMMITS] # Go back [NUM_COMMITS] commits. You *will* lose uncommitted work.*1
git checkout [NEW_BRANCH_NAME] # Checkout the newly created branch that contains your modifications
@hartfordfive
hartfordfive / com.apple.newsyslog.plist
Created April 19, 2016 15:56
Example newsyslog configuration
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.apple.newsyslog</string>
<key>ProgramArguments</key>
<array>
<string>/usr/sbin/newsyslog</string>
</array>
@hartfordfive
hartfordfive / haproxy-socket-stats
Created April 22, 2016 21:16
Get HAProxy stats via socket
echo "show info" | socat unix-connect:[STATS_SOCKET_PATH] stdio
echo "show stat" | socat unix-connect:[STATS_SOCKET_PATH] stdio
echo "show errors" | socat unix-connect:[STATS_SOCKET_PATH] stdio
echo "show sess" | socat unix-connect:[STATS_SOCKET_PATH] stdio