Skip to content

Instantly share code, notes, and snippets.

View joeljunstrom's full-sized avatar
🥰

Joel Junström joeljunstrom

🥰
  • Stockholm, Sweden
View GitHub Profile
@joeljunstrom
joeljunstrom / deploy.rake
Created November 9, 2010 08:00
ugly hack for caching out merged assets for heroku deploy
require 'jsmin'
require 'aws/s3'
require 'yui/compressor'
task :deploy => ['deploy:console']
namespace :deploy do
task :console => :environment do
if Rails.env != 'production'
puts "We need to be running in production environment, ie 'rake RAILS_ENV=production deploy'"
@joeljunstrom
joeljunstrom / purchase.rb
Created July 7, 2020 13:56
Refactor of purchase script from slack
module Shop
class Stock
attr_reader :items
def self.with(*item_attributes)
new(
*item_attributes.map { |attrs| StockItem.new(**attrs) }
)
end
class User < ApplicationRecord
attribute :otp_secret, :encrypted
end
class EncryptedType < ActiveRecord::Type::Value
class << self
memoize def secret_key
Rails.application.key_generator.generate_key("encrypted_type")
end
end
# config/routes.rb
Rails.application.routes.draw do
resource :contact_message, only: [:new, :create], path: "/contact", path_names: {new: "/"}
end
# app/controllers/contact_messages_controller.rb
class ContactMessagesController < ApplicationController
def new
render locals: {form: ContactMessageForm.new}
end
# app/models/user.rb
class User < ApplicationRecord
attribute :otp_secret, :encrypted
attribute :otp_recovery_secret, :encrypted
end
# lib/types/encrypted_type.rb
class Payment < ApplicationRecord
end
class PaymentEventMessagesController < ApplicationController
# The controller does as little as possible. Not ethat this should probably verify that the payload is legit somehow
# We offload the heavy lifting to a job to we answer the gateway asap and not bog down our servers
def create
message = PaymentEventMessage.create!(gateway: gateway, payload: params[:payload])
ProcessPaymentEventMessageJob.perform_later(message.id)
<!--[if lt IE 9]>
<link href="stylesheets/ie.css" media="screen" rel="stylesheet" type="text/css" />
<![endif]-->
function locateMe() {
var supportsLocation = function() {
return 'geolocation' in navigator;
}
var geocoder = new google.maps.Geocoder();
var onError = function(error) {
console.log(error);
2012-03-10T14:15:47+00:00 app[web.1]: Completed 200 OK in 37ms (Views: 29.5ms | ActiveRecord: 0.0ms)
2012-03-10T14:15:47+00:00 app[web.1]: cache: [GET /berattelser] miss
2012-03-10T14:15:47+00:00 heroku[router]: GET host/berattelser dyno=web.1 queue=0 wait=0ms service=243ms status=304 bytes=0
QQ
REGEXP = %r{
\b
(
(?:
https?://
|
www\d{0,3}[.]
|
[a-z0-9.\-]+[.][a-z]{2,4}/
)