Skip to content

Instantly share code, notes, and snippets.

View dmichael's full-sized avatar

David Michael dmichael

View GitHub Profile
{
"actions":[
{
"add":{
"index":"%s",
"alias":"%s",
"filter":[
{
"term":{
"meta.publish_records.timestamp":"%s"
# Thanks https://coderwall.com/p/khym-w
curl -s "http://someapi.com/json" | ruby -rawesome_print -rjson -e 'ap JSON.parse(STDIN.read)'
@dmichael
dmichael / gist:5751886
Created June 10, 2013 20:15
Unpad a PKCS7 pad from a block cipher
// http://play.golang.org/p/YfMF5mG3v2
func UnPKCS7Padding(data []byte) []byte {
dataLen := len(data)
// Grab the last byte which is *always* the pad byte for the password implementation
endIndex := int(data[dataLen-1])
fmt.Println(data[dataLen-1])
@dmichael
dmichael / httpclient.go
Last active October 18, 2023 20:07
Light wrapper for the Go http client adding (essential) timeouts for both connect and readwrite.
package httpclient
import (
"net"
"net/http"
"time"
)
type Config struct {
ConnectTimeout time.Duration
@dmichael
dmichael / gist:5622511
Last active May 25, 2017 17:47
Struct copy/clone
package main
import "fmt"
type Cat struct {
name string
skill string
}
func main() {
@dmichael
dmichael / gist:5532334
Last active December 17, 2015 01:59
Simple ad-hoc query for count
var db *sql.DB
func Count() (int, error) {
rows, err := db.Query("SELECT COUNT(*) AS count FROM users")
if err != nil {
return nil, err
}
var count int
zcat foo.sql.gz | mysql -uroot -ppassword foo
// The dumb way to deal with SOAP requests
func userRequest(userId string) string {
template := soapify(userTemplate)
return fmt.Sprintf(template, userId)
}
func soapify(template string) string {
return fmt.Sprintf(soapTemplate, template)
}
$ sudo networksetup -getwebproxystate "iPhone USB"
Enabled: No
Server: 127.0.0.1
Port: 6666
$ sudo networksetup -setwebproxystate "iPhone USB" off