Skip to content

Instantly share code, notes, and snippets.

@anklos
anklos / rails_upgrade.md
Last active February 16, 2024 06:14
Rails upgrade from 4.2 to 5.2

Overall

This documents the upgrade from Rails 4.2 to 5.2 through four parts: Backend, Frontend, Infrascture and Checkboxes

Backend

Rails update task

Run rake command rails app:update, it creates a set of new configration files for active storage, action cable, content security policy etc. As we dont use these features, the default ones from code generation are kept.

@anklos
anklos / test.rb
Last active December 5, 2016 00:13
openssl sha256 signature
require 'openssl'
require "base64"
DELIMITER = ":cba_signature_delimiter:"
# Airtasker sends encoded data
key = OpenSSL::PKey::RSA.new(File.read('private.pem'))
timestamp = '31480574670' # unix time stamp in utc timezone
signature = key.sign(OpenSSL::Digest::SHA256.new, timestamp)
data = timestamp + DELIMITER + Base64.strict_encode64(signature)
@anklos
anklos / test_paper_trail.rb
Last active April 13, 2016 04:07
remove attachment test with paper trail
# Use this template to report PaperTrail bugs.
# It is based on the ActiveRecord template.
# https://github.com/rails/rails/blob/master/guides/bug_report_templates/active_record_gem.rb
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
@anklos
anklos / 0_reuse_code.js
Created January 11, 2016 01:33
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@anklos
anklos / prf.md
Last active June 7, 2017 02:01
socket vs http performance

Apache benchmark test:

ab -n 900 -c 80 -p test.data http://localhost:8183/api/accounts/authenticate

HTTP:

Percentage of the requests served within a certain time (ms)
  50%    151
  66%    163
 75% 173
@anklos
anklos / create_hash
Last active August 29, 2015 13:58
create hash string
crypto.createHmac('sha512', salt).update(content).digest("base64");
http://adambard.com/blog/3-wrong-ways-to-store-a-password/
@anklos
anklos / gist:7817953
Created December 6, 2013 03:08
move dom target in selenium driver
require 'test_helper'
class DragDropTest < ActionDispatch::IntegrationTest
setup do
Capybara.current_driver = Capybara.javascript_driver # :selenium by default
end
def test_drag_item_1_to_list_2
visit '/drag_drop'
element = page.find(:id, 'item_1')
@anklos
anklos / .vimrc
Created June 27, 2013 06:08
.vimrc
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'gmarik/vundle'
filetype plugin indent on
" github vim plugins
#borrow from https://github.com/apotonick/hooks
#changes:
#remove block call support
#extend ActiveSupport::Concern into module to support nested module dependency
#add ability to pass multiple call_back methods params to a trigger
#for example: after_failed :job1, :job2..
require 'active_support/concern'
module Hooks
@anklos
anklos / tasks.rb
Created June 11, 2012 23:33
simple callbacks
module Callbacks
def self.included(base)
base.class_eval do
extend ClassMethods
include InstanceMethods
end
end
module ClassMethods
def define_callback(callback_name)