Skip to content

Instantly share code, notes, and snippets.

require 'httparty'
class Wmata
include HTTParty
base_uri "https://api.wmata.com"
#debug_output $stdout
def initialize(api_key="aad8b98dbe614b879c472e88a621d2d0")
@options = {query: {api_key: api_key} }
end
@bennacer860
bennacer860 / README.md
Last active August 29, 2015 14:14
Classy Dashing widget

##Description A Dashing widget to display the total amount of donations you have received through classy.org. It is set by default to display the past 30 days but you can set up the start and end date to an arbitrary date.

you would need to ask for a classy access token and a cid from the classy.org customer technical staff. Just shoot them an email and the will reply very quickly ##Usage

To use this widget, copy classy.html, classy.coffee, and classy.scss into the /widgets/classy directory. copy classy.rb to /jobs/ and set up the variables in the begining of the file.

To include the widget in a dashboard, add the following snippet to the dashboard layout file:

require 'pry-byebug'
@wires = {}
def is_integer? n
return n.to_i.to_s == n
end
def first_pass
File.readlines('input.txt').each do |line|
line = line.split("->")
require 'pp'
require 'pry-byebug'
class Grid
attr_accessor :grid
def initialize
@grid = Array.new
read_input 'input.txt'
0.upto(99) do
tick
class FakeDatabase
def self.connection query
puts "executing : #{query}"
return {count: 33}
end
end
require 'sinatra'
class Main < Sinatra::Base
get '/' do
# make call to the database
result = FakeDatabase.connection "select count(*) from users"
"Hello World! #{result[:count]}"
end
end
class Main < Sinatra::Base
get '/' do
# make call to the database
result = number_of_users
"Hello World! #{result[:count]}"
end
def number_of_users
Cache.fetch "number_of_users" do
FakeDatabase.connection "select count(*) from users"
class Cache
@redis = {}
def self.fetch key, &block
if @redis.key?(key)
# fetch and return result
puts "fetch from cache"
@redis[key]
else
if block_given?
# make the DB query and create a new entry for the request result
$ rackup
[2017-03-31 23:24:49] INFO WEBrick 1.3.1
[2017-03-31 23:24:49] INFO ruby 2.3.0 (2015-12-25) [x86_64-darwin15]
[2017-03-31 23:24:49] INFO WEBrick::HTTPServer#start: pid=51672 port=9292
did not find key in cache, executing block ...
executing : select count(*) from users
::1 - - [31/Mar/2017:23:25:01 -0400] "GET / HTTP/1.1" 200 15 0.0385
fetch from cache
::1 - - [31/Mar/2017:23:25:04 -0400] "GET / HTTP/1.1" 200 15 0.0012
fetch from cache
class Cache
@redis = {}
def self.fetch key, expires_in = 30, &block
puts ""
puts @redis
if @redis.key?(key) && (@redis[key][:expiration_time] > Time.now.to_i)
# fetch and return result
puts "fetch from cache and will expire in #{@redis[key][:expiration_time] - Time.now.to_i}"
@redis[key][:value]
else