Skip to content

Instantly share code, notes, and snippets.

View portableworld's full-sized avatar

Charles Caldwell portableworld

View GitHub Profile
@portableworld
portableworld / gist:6062046
Created July 23, 2013 12:35
Nick Carver's methodology about Stack Overflow infrastructure.

We are fanatical about performance - everything boils down to that. Every day we look for ways to improve.

  • Can we not run a query here?
  • Can we consolidate queries?
  • Can we extend this index to cover 20% more cases?
  • Can we denormalize this data to eliminate a join?
  • Can we stick this in redis?
  • Should we stick this in redis?
  • Should we aggregate this into a central DB?
  • Can we eliminate this API call?
@portableworld
portableworld / Pragmatic Notes.md
Last active October 17, 2016 02:26
The notes I'm taking while reading The Pragmatic Programmer.

3) Provide Options, Don't Make Lame Excuses

4) Don't Live with Broken Windows

5) Be a Catalyst for Change

  • Stone Soup
  • People find it easier to join an ongoing success

6) Remember the Big Picture

  • Too many little things can get out of hand
@portableworld
portableworld / norris.rb
Created September 19, 2012 18:32
Don't mess with Chuck Norris
trace_var(:$chuck_norris) {|v|
puts %Q{You can't change Chuck Norris to #{v}.
#{v} becomes Chuck Norris.}
}
$chuck_norris = "Awesome"
@portableworld
portableworld / array.rb
Created September 17, 2012 19:29
Adding Array#average with tests
class Array
def not_empty?
!self.empty?
end
def average
temp = self.compact
temp.map! {|e| e.is_a?(String) && (e.match(/\d/)) ? e.to_f : e}
return nil if (temp.not_empty?) && (temp.reject! {|e| !e.is_a? Numeric}; temp.empty?)
return 0.0 if temp.empty?
class Hash
# By default, only instances of Hash itself are extractable.
# Subclasses of Hash may implement this method and return
# true to declare themselves as extractable. If a Hash
# is extractable, Array#extract_options! pops it from
# the Array when it is the last element of the Array.
def extractable_options?
instance_of?(Hash)
end
end
require 'enumerator'
def scan(arr, pile)
val = ""
a = Array.new
a[0] = "#{pile}"
until val == "done" do
val = gets.chop!
unless val == "done"
val.chop!
#!/usr/local/bin/ruby
# This script will be set by crontab to run once a day at midnight
require 'rubygems' # require to bring in other Gems
require 'mysql' # require Mysql gem (2.8.1) to interact with database
require 'activesupport' # To make time calculations easier and more readable
# Establish today's date
today = Date.today # Will output "year-month-day" if sent to_s