Skip to content

Instantly share code, notes, and snippets.

Avatar

Tylor Sherman tylor

View GitHub Profile
@tylor
tylor / word_wrap.js
Created Apr 9, 2020
JavaScript JS port of Ruby word_wrap
View word_wrap.js
// 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")
}
View gist:9c2732cc2d03e185eb6c92b66b2e02c9
### 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 Nov 1, 2016
Pumpkin Patch Code
View index.js
/**
* 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}"
*
View gist:dfb1a9b4fc40db80935a
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 Aug 29, 2015
EAST VAN logo generator in bash
View gist:e1ebf330dd4d1797d6a6
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 Mar 2, 2014
Scrape the CrossFit Open 2014 Results and create a CSV
View package.json
{
"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 Dec 17, 2015
Add CORS headers to an API endpoint.
View Procfile
web: node index.js
@tylor
tylor / index.js
Created May 1, 2013
Convert GPS tagged images to CSV for graphing on a map
View index.js
/**
* 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 Dec 16, 2015
Old assembly program
View gist:5475887
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 Feb 4, 2013
Sort by column in simple CSV (eg. BC Hydro usage)
View gist:4708786
cat input.csv | sort -t ',' -k3
You can’t perform that action at this time.