This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'sinatra' | |
| require 'uri' | |
| helpers do | |
| include Rack::Utils | |
| end | |
| get '/' do | |
| <<HTML | |
| <form action="/" method="post"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'sinatra' | |
| require 'json' | |
| post '/' do | |
| JSON.parse(params[:data]).inspect | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "net/http" | |
| remote_cmd = 'cat /tmp/2012-03-05-blogg.athega.se.sql | grep -E "^20../"' | |
| slugs = `ssh athega.se #{remote_cmd}`.split("\n") | |
| req = Net::HTTP.new('athega.se', 80) | |
| slugs.each do |slug| | |
| response = req.request_head("/blogg/#{slug}") | |
| puts (response.code != "200") ? "Missing: #{slug}" : "OK: #{slug}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'yajl' | |
| require 'minitest/spec' | |
| require 'minitest/autorun' | |
| describe Yajl do | |
| def parse(*args) | |
| Yajl::Parser.parse(*args) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'rubygems' | |
| require 'redcarpet' | |
| require 'pygments.rb' | |
| class HTMLwithPygments < Redcarpet::Render::HTML | |
| def block_code(code, language) | |
| Pygments.highlight(code, :lexer => language.to_sym, :options => { | |
| :encoding => 'utf-8' | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MultiValue < BasicObject | |
| attr_reader :secondary | |
| def initialize(obj, *secondary) | |
| @obj, @secondary = obj, secondary | |
| end | |
| def method_missing(sym, *args, &block) | |
| @obj.__send__(sym, *args, &block) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function($) { | |
| $.QueryString = (function(a) { | |
| if (a == "") return {}; | |
| var b = {}; | |
| for (var i = 0; i < a.length; ++i) | |
| { | |
| var p=a[i].split('='); | |
| if (p.length != 2) continue; | |
| b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " ")); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| source :rubygems | |
| gem "sinatra", "~> 1.3.2" | |
| group :test do | |
| gem "minitest", "~> 2.10" | |
| gem "rack-test", "~> 0.6.1" | |
| gem "capybara", "~> 1.1" | |
| gem "capybara-webkit", "~> 0.11" | |
| gem "capybara_minitest_spec", "~> 0.2" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # encoding: utf-8 | |
| class WeekNumber | |
| attr_reader :cweek, :year | |
| def initialize(cweek = Date.today.cweek, year = Date.today.year) | |
| @year = year.to_i | |
| @cweek = cweek.to_i | |
| if @cweek > WeekNumber.weeks_in(@year) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'json' | |
| class ImageDimensions < Sinatra::Base | |
| get "/" do | |
| 'API: GET /[ur_product_id].json' | |
| end | |
| get /(\d{6})\.json/ do |ur_product_id| | |
| content_type :json | |
| data = { exists: false } |