Skip to content

Instantly share code, notes, and snippets.

View tylor's full-sized avatar

Tylor Sherman tylor

View GitHub Profile
@tylor
tylor / word_wrap.js
Created April 9, 2020 17:49
JavaScript JS port of Ruby word_wrap
// Port of Rails word_wrap(): https://github.com/rails/rails/blob/master/actionview/lib/action_view/helpers/text_helper.rb#L260
// rstrip using: https://stackoverflow.com/a/1418059
const word_wrap = (text, line_width, break_sequence) => {
line_width = line_width || 80
break_sequence = break_sequence || "\n"
return text.split("\n").map((line) => {
return line.length > line_width ? line.replace(new RegExp(`(.{1,${line_width}})(\\s+|$)`, 'gm'), `$1${break_sequence}`).replace(/^\s+|\s+$/g, '') : line
}).join("\n")
}
### Keybase proof
I hereby claim:
* I am tylor on github.
* I am tylorsherman (https://keybase.io/tylorsherman) on keybase.
* I have a public key ASCzt3oU8N8wUbRji-ONxVuvuHS0Ox2x48oqm5kNnnOSAwo
To claim this, I am signing this object:
@tylor
tylor / index.js
Last active November 1, 2016 00:40
Pumpkin Patch Code
/**
* Handy commands for setting everything up:
*
* Get Particle access token:
* $ curl https://api.particle.io/oauth/token -u particle:particle -d grant_type=password -d username={Your Particle email address} -d password={Your Particle password}
*
* Get list of devices from Particle:
* $ curl "https://api.particle.io/v1/devices?access_token={Your Particle access token}"
*
@tylor
tylor / gist:dfb1a9b4fc40db80935a
Last active August 29, 2015 14:05
Such sign in
I always forget I'm signed in with my personal GMail account, and want
to access our businesses Google Analytics, so here's what happens:
1. Load up http://www.google.com/analytics/
2. Click 'Access Google Analytics'
3. Woops, wrong account. Click 'Sign out'
4. Choose business account
5. Enter password
6. Takes me to 'Personal Info - Account Settings'
7. Load up http://www.google.com/analytics/
@tylor
tylor / gist:e1ebf330dd4d1797d6a6
Last active August 29, 2015 14:03
EAST VAN logo generator in bash
VAN=`egrep -i "^...$" /usr/share/dict/words | perl -MList::Util=shuffle -e "print shuffle<STDIN>" | head -n 1 | tr "[:lower:]" "[:upper:]"` && \
LETTER=${VAN:1:1} && \
EAST=`egrep -i "^.${LETTER}..$" /usr/share/dict/words | perl -MList::Util=shuffle -e "print shuffle<STDIN>" | head -n 1 | tr "[:lower:]" "[:upper:]"` && \
echo " ${EAST:0:1}" && \
echo $VAN && \
echo " ${EAST:2:1}" && \
echo " ${EAST:3:1}"
@tylor
tylor / package.json
Created March 2, 2014 05:11
Scrape the CrossFit Open 2014 Results and create a CSV
{
"name": "xf-games-open-14-scrape",
"version": "0.0.0",
"license": "MIT",
"dependencies": {
"request": "~2.34.0",
"cheerio": "~0.13.1",
"async": "~0.2.10"
}
}
@tylor
tylor / Procfile
Last active December 17, 2015 20:19
Add CORS headers to an API endpoint.
web: node index.js
@tylor
tylor / index.js
Created May 1, 2013 07:44
Convert GPS tagged images to CSV for graphing on a map
/**
* This script takes a directory of images, looks for GPS
* coordinates in each file, and then writes the filename and
* decimal degrees to CSV. If you're pulling images off of your
* iPhone, using Image Capture is a quick way to move them onto
* your computer and get started.
*
* Make sure you have imagemagick installed:
* $ brew install imagemagick
* Download these files and install dependencies:
@tylor
tylor / gist:5475887
Last active December 16, 2015 18:09
Old assembly program
0AEA:0100 mov cx,0 # move 0 into CX
0AEA:0103 mov ah,1 # move 1 into AH
0AEA:0105 int 21 # interrupt: read character (AH=1), drop in AL
0AEA:0107 push ax # push AX (AH, AL) onto stack
0AEA:0108 inc cx # increment CX
0AEA:0109 cmp al,20 # compare AL with 0x20 (space character)
0AEA:010B jnz 105 # jump if not zero to 0105
0AEA:010D pop dx # pop stack into DX
0AEA:010E sub dx,20 # subtract 0x20 from DX (making characters uppercase)
0AEA:0111 mov ah,2 # mov 2 into AH
@tylor
tylor / gist:4708786
Created February 4, 2013 19:06
Sort by column in simple CSV (eg. BC Hydro usage)
cat input.csv | sort -t ',' -k3