Skip to content

Instantly share code, notes, and snippets.

View flanger001's full-sized avatar
🧱

David Shaffer flanger001

🧱
View GitHub Profile
@flanger001
flanger001 / mta.rb
Last active December 17, 2015 22:19
Dave F's train line problem
module MTA
LINES = {
n: ['ts', '34th', '28th-n', '23rd-n', 'us'],
l: ['8th', '6th', 'us', '3rd', '1st'],
s: ['gc', '33rd', '28th-s', '23rd-s', 'us']
}
Stop = Struct.new(:line, :point)
class Route
@flanger001
flanger001 / delayedsearch.js
Created July 8, 2014 20:39
A simple implementation of a delayed search with jQuery and Ajax
var ReverseSearch = {
onReady: function(){
$("#rsearch input").on("keyup change", ReverseSearch.wait);
},
wait: function(e){
clearTimeout($.data(this, 'timer'));
if (e.keyCode == 13){
ReverseSearch.rsearch(true);
} else {
$(this).data('timer', setTimeout(ReverseSearch.rsearch, 500));
# Now more objecty
class PotOfCoffee
attr_reader :scoops
def initialize(quantity: 12, strength: :normal)
@quantity = quantity
@strength = strength
end
@flanger001
flanger001 / kaprekar.rb
Created May 27, 2015 20:18
Kaprekar number
# https://rubymonk.com/learning/books/1-ruby-primer/problems/150-kaprekar-s-number
def kaprekar?(k)
k_st = k.to_s
kk = k**2
kk_st = kk.to_s
offset_length = kk.to_s.length.odd? ? k_st.length - 1 : k_st.length
left = kk_st[0, offset_length]
right = kk_st[offset_length, k_st.length]
k == left.to_i + right.to_i
end
require 'set'
class Subway
attr_reader :stops
def initialize(lines)
@stops = {}
lines.each_pair {|line, stops|
stops.each do |stop|
@flanger001
flanger001 / rename_photos.rb
Created June 25, 2015 20:08
A script I wrote to convert files from IMG_XXXX.jpg to YYYY-MM-DD HH.MM.SS.jpg format, with proper duplicate file
require 'exifr'
files = Dir['*.jpg']
puts "Renaming #{files.count} files..."
new_file_names = Hash.new { |h,k| h[k] = [] }
files.each do |file|
exif = EXIFR::JPEG.new(file)
dt = exif.date_time_original
new_file_name = "#{dt.strftime('%Y-%m-%d %H.%M.%S')}"
@flanger001
flanger001 / zalgo.js
Created September 23, 2015 14:05
I stole a Zalgo text generator
/* <![CDATA[ */
//============================================================
// ZALGO text script by tchouky
//============================================================
// data set of leet unicode chars
//---------------------------------------------------
//those go UP
var zalgo_up = [
@flanger001
flanger001 / application.rb
Last active October 14, 2015 13:00
Dynamic error pages in Rails with testing
# in configure block
config.exceptions_app = self.routes
@flanger001
flanger001 / Fan Mail.md
Last active January 23, 2017 03:01
This is my bucket list that I accidentally wrote one day. I say "accidentally" because I didn't set out to write a bucket list, that's just what it became.
  • Mark Hamill - P.O. Box 287, Grand Blanc, MI 48480, USA
  • Harrison Ford - P.O. Box 49344, Los Angeles, CA 90049-0344, USA
  • Dave Grohl -
  • Josh Freese - Rebel Waltz, Inc., 31652 2nd Avenue, Laguna Beach, CA 92651, USA
  • Tom Hanks - Playtone, P.O. Box 7340, Santa Monica, CA 90406-7340, USA
  • Bill Murray - Ziffren, Brittenham, 1801 Century Park West, Los Angeles, CA 90067-6406, USA
  • Dan Akroyd - Applied Action Research Corp., 859 Hollywood Way, Box 497, Burbank, CA 91505, USA
  • John Cleese - Phil McIntyre Management Ltd., 3rd Floor, 85 Newman Street, London, W1T 3EU, UK