This file contains hidden or 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
# Export table to CSV from psql: | |
COPY table_name TO 'filepath' WITH DELIMITER AS ',' CSV HEADER; |
This file contains hidden or 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
result = ActiveRecord::Base.connection.execute("SELECT DISTINCT SUBSTRING(postcode, '[A-Z0-9]{3,} [0-9]{1}') FROM postcodes") | |
result.values.first | |
# => ['AB1 1'] |
This file contains hidden or 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
# Convert file encoding for CSV in OS X: | |
iconv -f iso-8859-1 -t UTF-8 original.csv > utf-output.csv | |
# Where | |
# -f is current encoding | |
# -t is target encoding | |
# Guestimate of original file encoding with: | |
file -I |
This file contains hidden or 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
puts `clear` | |
exercises = ["How much wood can a woodchuck chuck?", "What's the time Mr.Wolf?", "Peter Piper picked a peck of pickled peppers."] | |
def check_diff text, input | |
text.length.times.map{|i| 1 unless text.chars[i] == input.chars[i]}.count(1) + (input.length > text.length ? input.length - text.length : 0) | |
end | |
exercises.each do |exercise| | |
puts "Type the following:\n---\n#{exercise}\n---\n\n" | |
start_time, input, end_time = Time.now, gets.chomp, Time.now | |
puts "Mistakes: #{check_diff(exercise, input)} characters. Time taken: #{(end_time - start_time).round(2)} seconds.\n\n" | |
end |
This file contains hidden or 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
# EXAMPLE 1: Cascade | |
# Two modules happen to have the same method ('say'). | |
# If we include the Shouting module last, the Shouting 'say' method overwrites the Talkable 'say' method. | |
module Talkable | |
def say (str) | |
puts str | |
end | |
end |
NewerOlder