Skip to content

Instantly share code, notes, and snippets.

@tannerwelsh
tannerwelsh / random_word.sh
Created July 10, 2017 18:44
Get a random word of length n
#!/usr/bin/env sh
word_length=$1
all_words=/usr/share/dict/words
# use outer wrapping parens to convert to an array
words=( $(grep -E "^.{$word_length}$" $all_words) )
num_words=${#words[@]} # get length of words array
index=$(($RANDOM % $num_words)) # make a random index
const rp = require('request-promise')
const cheerio = require('cheerio')
const buildURL = (searchQuery) => {
return `http://www.imdb.com/find?q=${searchQuery}&s=tt&ref_=fn_al_tt_mr`
}
const parseResults = ($) => {
return $('td.result_text')
.map((i, el) => $(el).text().replace(/ - /g, "\n - "))
@tannerwelsh
tannerwelsh / sort.js
Created July 17, 2017 19:16
Example sort implementation
/*
A very basic sorting function (not at all optimized)
Might be useful if you're trying to understand how Array#sort() works
The way this sorting "algorithm" works is as follows:
1. start with an unsorted array of items and a comparison function
2. iterate through each item in the unsorted array
3. if there are no items in the sorted array