Skip to content

Instantly share code, notes, and snippets.

View jasonhancock's full-sized avatar
meh

Jason Hancock jasonhancock

meh
View GitHub Profile
@jasonhancock
jasonhancock / main.go
Created October 20, 2022 16:27
Go YAML Unmarshal list of interfaces
package main
import (
"errors"
"fmt"
"log"
"math"
"gopkg.in/yaml.v3"
)
@jasonhancock
jasonhancock / main.go
Created November 29, 2018 19:28
bcrypt time cost at various difficulty factors
package main
import (
"fmt"
"log"
"time"
"golang.org/x/crypto/bcrypt"
)
@jasonhancock
jasonhancock / harvest_one_item.md
Created April 30, 2018 23:12
Harvesting a single item from s3 via the GrayMeta Platform API

How to initiate a harvest of a single asset in s3 that has not been previously indexed into the GrayMeta Platform

NOTE: my endpoint is http://localhost:7000. Your endpoint will be different.

Step 1:

You must know the name of the s3 bucket and the s3 key (the path within the bucket) to the asset.

For our example today, I want to harvest the key 5aba86635fc9cbec3a81839abc0fc2a9.jpg inside the hancocktest bucket in s3.

@jasonhancock
jasonhancock / main.go
Created August 30, 2017 20:44
simple udp server to debug statsd stuff
package main
import (
"fmt"
"log"
"net"
)
func handleUDPConnection(conn *net.UDPConn) {
@jasonhancock
jasonhancock / README.md
Last active December 14, 2017 14:45
jenkins to statsd

A cheap way to get build events from jenkins into graphite via statsd:

/usr/local/bin/buildstats

#!/bin/bash
. /etc/default/buildstats
echo "$BUILD_PREFIX.$JOB_NAME:1|c" | nc -w 1 -u $STATSD_SERVER $STATSD_PORT

/etc/default/buildstats:

package main
import (
"bufio"
"fmt"
"github.com/Azure/azure-sdk-for-go/storage"
"io"
"log"
"os"
)
#!/bin/bash
ADDR='[email protected]'
PRODUCT_ID=2885
TMP_FILE=/tmp/adafruit.tmp
wget -O $TMP_FILE -q https://www.adafruit.com/product/$PRODUCT_ID > /dev/null 2>&1
@jasonhancock
jasonhancock / gist:5445430
Created April 23, 2013 17:01
Ordering IP ranges in CIDR notation stored in a SQL DB correctly

Imagine you're storing IP ranges in CIDR notation in a database table like this:

CREATE TABLE ranges (
    block VARCHAR(50)
);

INSERT INTO ranges(block) VALUES ('192.168.2.0/24'),('192.168.10.0/24');
@jasonhancock
jasonhancock / VersionAssetManager.php
Created March 3, 2013 00:42
An asset manager for the Yii PHP framework to publish static assets with a hash that's load-balancer and development environment friendly.
<?php
/**
* CAssetManager class file.
*
* @author Jason Hancock <[email protected]>
* @copyright Copyright &copy; 2013 Jason Hancock
* @license http://www.yiiframework.com/license/
*/
@jasonhancock
jasonhancock / gist:4675588
Last active December 11, 2015 23:18
stupid quick and dirty script to parse apache combined log format
#!/usr/bin/perl
use strict;
use warnings;
my $file = $ARGV[0] or die("No file passed");
open IN, "<$file" or die("Can't open file $file");
while(my $line=<IN>) {