Skip to content

Instantly share code, notes, and snippets.

View davidrichards's full-sized avatar

David Richards davidrichards

View GitHub Profile

Try This

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@davidrichards
davidrichards / prob.rb
Last active June 29, 2016 17:44
We had some data on the response time of some code after we deployed a speed up and we wanted to know if it was fast enough. The numbers I have below are in milliseconds, and we have to deliver under 1 second. I used Python for my work, this is a Ruby version of the same. Requires the distribution gem to be installed.
mu = 522 # mean observation
max = 859 # max observation, assumed 2 standard deviations above the mean
std = (max - mu) / 2.0 # standard deviation
z = (1000 - mu) / std # 1,000 is when we have a problem, so what is the z-score of a problem?
p = Distribution::Normal.cdf(z) # get the probability of this event
# Python version of the same is: p = stats.norm.cdf(z)
1 - p # The probability of having a problem
@davidrichards
davidrichards / test_dimensional.py
Created June 27, 2016 04:19
A kind of a cheatsheet to remind me some of the basics
import unittest
from unittest.mock import MagicMock
class Bar(object):
def thud(self):
return "thunk"
def baz(self):
return self.thud()

Introducing Dimensional

The organizers of Utah County Data Science Meetup all have data needs. Surprise. And we spend a lot of time sourcing, cleaning, and integrating that data into our projects (writing high quality ETL scripts). What if, asks the illustrious Jeff Potter we could share?

Share you ask?

Yes, share data, share scripts.

How do I know that what I have is useful to other people?

@davidrichards
davidrichards / cohort.rb
Created June 16, 2016 03:37
Setting up a singleton for bit_analytics in a Rails application
require "singleton"
class Cohort
include Singleton
def self.instance
@@instance ||= new.db
end
@davidrichards
davidrichards / caudio
Last active December 7, 2021 02:00
Collecting ffmpeg snippets that work for me and converting them to reusable scripts.
#!/usr/bin/env bash
set -e
gain=${3-"1"}
if [ "$#" -lt 2 ]; then
echo "Usage: $0 input.aifc output.aifc [gain=2]"
exit 1
else
@davidrichards
davidrichards / 00_basic_notes.md
Last active May 10, 2016 22:50
Bloc Student Questions

Generally, I like to build a rapport with people I teach. Sometimes I'll give stronger answers and sometimes I'll just help them get unstuck but leave them engaged in the question so they can really get the subject. I like to think that my main value is that I've been there many times and I can help people find their confidence as they work. In the examples below I showed a few different approaches that may or may not be appropriate for different students.

Knowing my students is even more important when I choose language. If they're native English speakers and have no issues with metaphor, I prefer the style of communication I use below. A neurological study (I've lost the link) shows a tight correlation with the language centers of our brains when we try and read and understand software code and I've found that this kind of mentality helps people (myself included) get into a productive flow.

Thanks,

David

@davidrichards
davidrichards / multiply.rb
Created April 8, 2016 03:00
Quick-entry command line number multiplier (because of some quantitative self efforts I'm doing: http://bit.ly/1MXqjTc)
#! /usr/bin/ruby
puts "Space-delimit numbers to multiply"
string = gets.chomp
until string.length == 0
numbers = string.split(/\s+/).map(&:to_f)
result = numbers.reduce(1.0) {|p, e| p * e}
puts "Input: #{numbers.inspect}", "Result: ", result, "Another? (return nothing to quit)"
string = gets.chomp