Skip to content

Instantly share code, notes, and snippets.

View veganstraightedge's full-sized avatar
🐢
Computers were a mistake.

Shane Becker veganstraightedge

🐢
Computers were a mistake.
View GitHub Profile
@veganstraightedge
veganstraightedge / longest_common_subsequence.rb
Last active September 22, 2018 05:03
A Ruby port of a solution to the Longest common subsequence problem : https://en.wikipedia.org/wiki/Longest_common_subsequence_problem
#!/usr/bin/env ruby
if ARGV.length != 2
puts
puts 'ERROR! This script needs exactly two strings as input. Example: '
puts
puts ' ruby subsequence.rb XMJYAUZ MZJAWXU'
puts
exit -1
end
#!/usr/bin/env ruby
if ARGV.length != 2
puts
puts 'ERROR! This script needs exactly two strings as input. Example: '
puts
puts ' ruby subsequence.rb XMJYAUZ MZJAWXU'
puts
exit -1
end
@veganstraightedge
veganstraightedge / bootstrap.sh
Last active August 30, 2018 23:43
These lines of commands work when run directly in Terminal, but fail when run as the contents of a file.
#!/bin/sh
# this test case script assumes that you are on macOS and have Homebrew (brew) installed
set -e
brew install nvm
mkdir -p ~/.nvm
export NVM_DIR="$HOME/.nvm"
```
Fetching rmagick 2.16.0
Installing rmagick 2.16.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Users/s/.gem/ruby/2.5.1/gems/rmagick-2.16.0/ext/RMagick
/Users/s/.rubies/ruby-2.5.1/bin/ruby -r ./siteconf20180624-31720-1jgmacc.rb extconf.rb
checking for clang... yes
checking for Magick-config... yes
checking for outdated ImageMagick version (<= 6.4.9)... no
promises = []
# Create the collection of promises to do
(1..10).each do |i|
promises << Concurrent::Promise.execute do
thing = get the thing from the API
Thing.create! name: thing.name
end
end
@veganstraightedge
veganstraightedge / app_redirect.rb
Created March 27, 2018 22:06
Redirect `app.any-domain.tld` to `any-domain.tld` while keeping the path in place.
module Rack
class AppRedirect
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
if request.host.start_with?("app.")
@veganstraightedge
veganstraightedge / shanes-sequence.rb
Last active February 22, 2018 05:08
Shane's Sequence of Prime Numbers. (Every prime-th prime.)
require 'prime'
output = []
current_index = 0
range = Prime.first(10000)
Prime.first(20).each do |next_prime|
output << range[current_index]
current_index += next_prime
end
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<style type="text/css">
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
> heroku open -r staging
module.js:557
throw err;
^
Error: Cannot find module '@cli-engine/engine'
at Function.Module._resolveFilename (module.js:555:15)
at Function.Module._load (module.js:482:25)
at Module.require (module.js:604:17)
@veganstraightedge
veganstraightedge / convert.sh
Created January 26, 2018 01:11
Convert Ruby hashes from 1.8 style to 1.9+ style. From: http://effectif.com/ruby/update-your-project-for-ruby-19-hash-syntax
find . -name \*.rb -exec perl -p -i -e 's/([^:]):(\w+)\s*=>/\1\2:/g' {} \;