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/ruby | |
# Instead of rails dbconsole. This loads a lot quicker, since it doesn't load all of rails. | |
# Place user/password in ~/.my.cnf as | |
# [client] | |
# user=whathaveyou | |
# password=whathaveyoupwd | |
require 'erb' |
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 for Rails apps | |
# Place this in app/controllers/shutdown_controller.rb | |
# | |
# When you want to start up a new Rails server, but some other one is already running | |
# simply run this command: "curl http://localhost:3000/shutdown/exit" -- it will go away. | |
# | |
# This will work without any other changes if your routes include something like | |
# match '/:controller(/:action(/:id))', via: [:all] | |
# | |
# Also, add app/controllers/shutdown_controller.rb to your global .gitignore file and noone will ever know! |
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
# Simple Key-Value store in Ruby | |
# Stephan Wehner, May 2017 | |
# | |
# 2 sample sessions illustrate usage: | |
# In one terminal: | |
# $ ruby simple-key-value-store.rb | |
# In another terminal session: | |
# | |
# $ telnet localhost 3333 | |
# Trying ::1... |
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
# See the Aug. 2014 paper Tackling the Minimal Superpermutation Problem by Robin Houston at http://arxiv.org/abs/1408.5108 | |
# It announces a superpermutation for 6 symbols with length 872 | |
# This Ruby script verifies it is a superpermutation and finds that all permutations only occur once. | |
# Kind of complements http://arxiv.org/src/1408.5108v1/anc/splitsuperperm.py ("Take a superpermutation, and print it as a sequence of permutations.") | |
# Invocation: | |
# ruby check_super_permutation_6.rb | |
# (Runs in 0.05 secs on a standard laptop, no optimizations necessary) | |
# Could also read this from http://arxiv.org/src/1408.5108v1/anc/superperm-6-866.txt | |
SUPER_PERMUTATION =<<END_PERM.gsub("\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
# JSON hashes of course allow multiple values for the same key. | |
# Only one is kept | |
# E.g. | |
# > h = JSON.parse '{"a":1, "a":2}' | |
# => {"a"=>2} | |
# | |
# If you don't like that, you can use this : | |
require 'json' | |
class DuplicateEntryCatchingHash < Hash |
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
# | |
# Suppose the file mainsurvey_sqldump.txt (available from colorsurvey.tar.gz, link at http://blog.xkcd.com/2010/05/03/color-survey-results/) has been loaded into file mainsurvey_sqldump.sqlite3, possibly with the command | |
# | |
# sqlite3 mainsurvey_sqldump.sqlite3 < mainsurvey_sqldump.txt | |
# | |
# Invocation of this Ruby script (UNIX command line) | |
# | |
# echo 'select r,g,b,colorname from answers;' | mainsurvey_sqldump.sqlite3 | ruby THIS-FILE > result.html | |
omit_colors = %w( grey gray yellow red green blue purple brown pink black violet white orange cyan gray ).sort.uniq |
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
# Avoiding heredoc.chomp as in | |
# assert_select "div#order p", <<-STR.chomp | |
# Test ABC | |
# Test DEF | |
# STR | |
def assert_select(a,b) | |
puts "assert_select: #{a.inspect}, #{b.inspect}" | |
end |
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
# Add two numbers in Ruby. | |
# Strategy: make a list of known sums, and look up the one in question. | |
# What's the point? The point is: nowadays computing machinery is so powerful that | |
# implementation in many cases doesn't matter. The most ridiculous approach can still be | |
# useful, and improving it, a waste of time. | |
# So here's a very silly way how to add numbers. | |
def add_by_grep(a,b) |
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
Searched Google for "if i wasn't on bittorrent relevant" (don't ask ...) | |
Got this at end of result listing: | |
"In response to a complaint we received under the US Digital Millennium Copyright Act, we have removed 1 result(s) from this page. If you wish, you may read the DMCA complaint that caused the removal(s) at ChillingEffects.org." | |
The chillingeffects.org page, http://www.chillingeffects.org/notice.cgi?sID=234923 says, | |
Quote: |