Skip to content

Instantly share code, notes, and snippets.

View brooksgarrett's full-sized avatar

Brooks Garrett brooksgarrett

View GitHub Profile
@brooksgarrett
brooksgarrett / gist:ff60bc691521735e71a0
Created May 22, 2015 13:24
Download DOCX, convert to HTML
#!/bin/bash
dl_file=$(basename "$1")
filename=$(basename "$1" .docx)
wget $1
echo Downloaded $dl_file
unoconv -f html $dl_file
echo Unoconv complete with exit $?
pandoc -f html -o $filename.md $filename.html
echo pandoc complete with exit $?

Keybase proof

I hereby claim:

  • I am brooksgarrett on github.
  • I am brooksgarrett (https://keybase.io/brooksgarrett) on keybase.
  • I have a public key whose fingerprint is B361 0C94 96DB A3EF B82D FB8D 7D03 5804 5781 3A91

To claim this, I am signing this object:

@brooksgarrett
brooksgarrett / SmartCounter.coffee
Created July 17, 2013 13:34
I came across this today and it provides a pretty slick way of looping an array by index without running out of bounds. With array length of 3::: 1 mod 3 is 1; 2 mod 3 is 2; 3 mod 3 is 0; 4 mod 3 is 1; This is not my creation. I'm sure it is fairly standard but I saw it first in the Comments widget from the Dashing Dashboard.
(@currentIndex + 1) % comments.length
@brooksgarrett
brooksgarrett / BuildGetParameters.cs
Last active December 15, 2015 23:39
Dynamically build REST GET Query Strings with an Options object. This code doesn't care what type of Object comes in. It simply parses through the Properties of the object and if they are not default (null for Strings and 0 for int) then they get added to the query string.
private String buildGetParameters(PingdomSearchOptions opts)
{
// If the options object is null then don't set any parameters
if (opts != null)
{
// Start with a string builder primed with ?
StringBuilder urlBuilder = new StringBuilder("?");
// This bool is used to control adding the & character. Not needed unless Params > 1.
bool first = true;
// Start the loop through the object.
@brooksgarrett
brooksgarrett / Hashing Ip's
Created November 30, 2009 19:02
C# Code for Hasing IP's
public UInt32 hashIP(string ip)
{
try
{
string[] octets = ip.Split('.');
UInt32 temp = ((Convert.ToUInt32(octets[0]) * 256 + Convert.ToUInt32(octets[1])) * 256 +
Convert.ToUInt32(octets[2])) * 256 + Convert.ToUInt32(octets[3]);
return temp;
}
catch (Exception e)