This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 - ")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem 'unimidi' | |
gem 'midi-message' | |
gem 'activesupport', '~> 4.2.3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a very bare-bones (and incomplete) implementation of the idea | |
// behind Promise, using a new function called Commitment: | |
const Commitment = function(func) { | |
this.state = 'PENDING' // will be changed to 'FULFILLED' or 'REJECTED' | |
const resolve = (result) => { | |
this.state = 'FULFILLED' | |
this.resolver && this.resolver(result) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// List of 1000 basic English words from Wikipedia | |
// https://simple.wikipedia.org/wiki/Wikipedia:List_of_1000_basic_words | |
var BASIC_WORDS = ['a', 'about', 'above', 'across', 'act', 'active', 'activity', 'add', 'afraid', 'after', 'again', 'age', 'ago', 'agree', 'air', 'all', 'alone', 'along', 'already', 'always', 'am', 'amount', 'an', 'and', 'angry', 'another', 'answer', 'any', 'anyone', 'anything', 'anytime', 'appear', 'apple', 'are', 'area', 'arm', 'army', 'around', 'arrive', 'art', 'as', 'ask', 'at', 'attack', 'aunt', 'autumn', 'away', 'baby', 'back', 'bad', 'bag', 'ball', 'bank', 'base', 'basket', 'bath', 'be', 'bean', 'bear', 'beautiful', 'bed', 'bedroom', 'beer', 'behave', 'before', 'begin', 'behind', 'bell', 'below', 'besides', 'best', 'better', 'between', 'big', 'bird', 'birth', 'birthday', 'bit', 'bite', 'black', 'bleed', 'block', 'blood', 'blow', 'blue', 'board', 'boat', 'body', 'boil', 'bone', 'book', 'border', 'born', 'borrow', 'both', 'bottle', 'bottom', 'bowl', 'box', 'boy', 'branch', 'brave', ' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative "university" | |
University.open_db | |
student = University::Student.new('Tanner Welsh') | |
student.save | |
student = University::Student.new('Mike Busch') | |
student.save |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# <<< gistclone >>> | |
# | |
# Why clone gists with HTTP when you can use SSH? | |
# | |
# Just put this somewhere in your PATH, make it executable, and you're good to go. | |
# | |
# Usage: | |
# $ gistclone <gist_url> [<directory>] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "Installing debugger gem..." | |
gem install 'debugger' | |
echo "Creating and modifying ~/.rdebugrc config file..." | |
touch ~/.rdebugrc | |
echo -e "set autolist\nset autoeval\nset autoreload" > ~/.rdebugrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Setup an array of 99 numbers between 1 and 100, randomly sorted | |
@numbers = (1..1_000_000).to_a.shuffle | |
@numbers.delete_at(rand(1_000_000)) | |
def sort_find | |
sorted = @numbers.sort | |
sorted.each_with_index do |n, i| | |
next if n == sorted[i-1] + 1 || n == 1 | |
return n-1 |
NewerOlder