Skip to content

Instantly share code, notes, and snippets.

View jasondew's full-sized avatar

Jason Dew jasondew

View GitHub Profile
@jasondew
jasondew / conway-twitter.rb
Created May 17, 2012 00:52
My current best try at a twitter-length implementation of Conway's Game of Life for #roguesgolf
n=(0..3);g=[!1]*4;b=[g,g,[!1]+[1]*3,g]
4.times{b=n.map{|x|n.map{|y|l=[x-1,x+1,x].product([y-1,y+1,y])[0..7].select{|f,g|(r=b[f])&&r[g]}.size
l==3||b[x][y]&&l==2}}
b.map{|r|puts r.map{|c|c ??#:?.}*""}}
@jasondew
jasondew / gist:5050066
Last active April 8, 2018 02:28
Luhn Checksum project
Luhn Checksum
http://en.wikipedia.org/wiki/Luhn_algorithm
Implement a Ruby program that outputs the validity of a number by applying the Luhn Checksum.
Input:
The program should accept a single number to validate.
Output:
class Courier < ActionMailer::Base
CIPHER = ActiveSupport::MessageEncryptor.new("redacted", "aes-256-cbc")
module ClassMethods
delegate :encrypt, :to => :"Courier::CIPHER"
def valid_email_address? email_address
(not email_address.blank?) and email_address.include?("@")
end
POSSCON = Conference.create(:awesome => true) do
starts_on "2010-04-15"
ends_on "2010-04-17"
speakers %w(Obie Yehuda Wanstrath)
end
POSSCON.include?(self) or fail
class CreditCard < ActiveRecord::Base
belongs_to :order
has_one :billing_address, :as => :addressable, :class_name => "Address", :dependent => :destroy
accepts_nested_attributes_for :billing_address
before_validation :clean_number
@client.diagnoses.include? Diagnosis.get(:hiv)
module Algebra
class MaximumIterationsReached < Exception
end
class NewtonsMethod
def self.calculate(function, x)
x - function.evaluated_at(x) / function.derivative_at(x)
end
require 'algebra'
class IRR
def self.calculate(profits)
begin
function(profits).zero
rescue Algebra::MaximumIterationsReached => mir
nil
end
@jasondew
jasondew / http.elm
Created February 1, 2016 02:35
HTTP error handling
update : Action -> Model -> ( Model, Effects Action )
update action model =
case action of
HandleResponse result ->
case result of
Ok movies ->
( { model | movies = movies }, Effects.none )
Err error ->
let

Keybase proof

I hereby claim:

  • I am jasondew on github.
  • I am jasondew (https://keybase.io/jasondew) on keybase.
  • I have a public key whose fingerprint is D4FD 83C6 D891 37EC 3045 8745 3581 0583 7D91 64D9

To claim this, I am signing this object: