https://www.ssllabs.com/ssltest/analyze.html
https://www.ssllabs.com/ssltest/analyze.html
Assume you have a branch_new branch and want to overwrite branch_old with its content:
git checkout branch_new
git merge -s ours branch_old
git checkout branch_old
git merge branch_new
When using the vcr gem, you may encounter the problem, that you need to have variables in your requests. For example, your colleagues use different hostnames for local api endpoints. Then you have the problem, that a recorded cassette does not work everywhere.
VCR has a configuration option that is called define_cassette_placeholder. With this option you can define a string and a code block, that will be run replacing this string in your cassette.
Here is a simplified example:
# spec/support/vcr.rb
VCR.configure do |c|
c.define_cassette_placeholder("<API_HOST>") do
hosts = {
'default' => 'my_app.ldev'
'kara.thrace' => 'my_app.localdev',
'bill.adama' => 'my_app.dev'
}
user = ENV.fetch('USER') { default }
hosts[user]
end
end
# spec/fixtures/vcr_cassettes/example.yml
...
http_interactions:
- request:
method: get
uri: http://<API_HOST>/api/v1/cic/dradis_status.json
Things to know:
The default tld .dev does not work anymore:
$ dig issue.dev TXT +short
"Your DNS configuration needs immediate attention see https://icann.org/namecollision"
You can restart servers via:
touch tmp/restart.txt
Don’t know how or if it is possible to handler apps with different ruby versions.
TODO:
Install apt-file:
sudo apt-get install apt-file
sudo apt-file update
Search for something:
sudo apt-file find curl.h
If you have engines, that - for your testing convenience - include factories, you may want to use them:
# spec/support/factory_girl_rails.rb:
require 'factory_girl_rails'
FactoryGirl.definition_file_paths << MultiClient::Engine.root.join(*%w(spec factories))
FactoryGirl.factories.clear
FactoryGirl.find_definitions
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end
To avoid forgetting translations or params, you can add following settings to your application. Then, missing translations or unpermitted params will raise an exception.
# config/environments/development.rb
# Raises error for missing translations
config.action_view.raise_on_missing_translations = true
# Raises an error on unpermitted attributes assignment
config.action_controller.action_on_unpermitted_parameters = :raise
A simple way to add Header Authentication to Authlogic, is to use a before_action filter to extract the authentication information from the header and inject it to the params hash. So you can use the default single access token.
class BackendController < ApplicationController
before_action :extract_authentication_from_header, if: -> { request.headers['Authorization'].present? }
before_action :authenticate_user!
private
def single_access_allowed?
true
end
# Extract authentication from request headers and inject it into params.
# Accepted headers example:
#
# Authorization: Token token="<SINGLE_ACCESS_TOKEM>"
#
def extract_authentication_from_header
authlogic_params_key = :user_api_key
raw_header = request.headers['Authorization']
auth_token = raw_header.split("=\"").last[0..-2]
params[authlogic_params_key] = auth_token
end
end
The structure of the header is very losely based on this document: https://tools.ietf.org/html/draft-hammer-http-token-auth-01#section-5.1
When using myFritz and dyndns it is mandatory, that you use the myFritz dns names as VPN addresses on both sides. It is not possible to use dyndns entries. If you use them anyways, you’ll get following error in the logs:
VPN-Fehler: xyz.dynvpn.de, IKE-Error 0x1c
The AVM docs (https://avm.de/service/fritzbox/fritzbox-7390/wissensdatenbank/publication/show/687_VPN-Verbindung-zwischen-zwei-FRITZ-Box-Netzwerken-kann-nicht-hergestellt-werden/) hide this pretty well in the last sentence of their vpn debugging faq:
Wichtig:Ist in einer FRITZ!Box sowohl MyFRITZ! als auch Dynamic DNS aktiv, muss bei der Einrichtung der VPN-Verbindung zwingend der MyFRITZ!-Domainname als "Internetadresse" eingetragen werden. Soll bei der VPN-Verbindung als "Internetadresse" eine feste ("statische") öffentliche IP-Adresse verwendet werden, darf in der FRITZ!Box weder MyFRITZ! noch Dynamic DNS aktiv sein.
# Gemfile
gem 'capybara', groups: [:test]
gem 'factory_girl_rails', groups: [:test]
gem 'rspec-rails', groups: [:development, :test]
gem 'shoulda-matchers', groups: [:test]
gem 'guard-bundler', groups: [:development]
gem 'guard-rails', groups: [:development]
gem 'guard-rspec', groups: [:development]
gem 'rubocop'
gem 'yaml_db'
Route Translator
gem 'route_translator'
RouteTranslator.config do |config|
config.force_locale = true
end
Simple Form
gem 'simple_form'
Commandline: rails generate simple_form:install –bootstrap
Clones and resizes source.vmdk to resized.vmdk (64GB):
VBoxManage clonehd "source.vmdk" "cloned.vdi" --format vdi
VBoxManage modifyhd "cloned.vdi" --resize 65536
move source.vmdkk source.vmdk.original
VBoxManage clonehd "cloned.vdi" "source.vmdk" --format vmdk
VBoxManage.exe internalcommands sethduuid source.vmdk
Then replace all occurences of the old UUID with the new UUID in your virtual box xml file. The extra space can now be allocated with partitioning tools like gparted, etc.
when trying to test an active admin backend with Rspec, you can stumble upon following error:
ActionController::RoutingError:
uninitialized constant Admin::DashboardController
If this happens, append following lines to your spec/rails_helper.rb:
# spec/rails_helper.rb
require_relative 'dummy/app/admin/dashboard'
require_relative 'dummy/config/routes'
.btn-group{ role: :group }
- if item.published?
%button.btn.btn-secondary.btn-xs.disabled{ type: :button }
%span.glyphicon.glyphicon-eye-open
%button.btn.btn-xs.btn-disabled
%span.glyphicon.glyphicon-ok
= link_to(toggle_published_item_path(item), class: 'btn btn-xs btn-danger', method: :post, title: t('.unpublish')) do
%span.glyphicon.glyphicon-eye-close
- else
= link_to(toggle_published_item_path(item), class: 'btn btn-xs btn-success', method: :post, title: t('.publish')) do
%span.glyphicon.glyphicon-eye-open
%button.btn.btn-xs.btn-disabled
%span.glyphicon.glyphicon-remove
%button.btn.btn-secondary.btn-xs.disabled{ type: :button }
%span.glyphicon.glyphicon-eye-close
When trying to test active admin with rails and rspec and your get following error:
ActionController::RoutingError:
uninitialized constant Admin::DashboardController
Try adding following lines to your rails_helper:
require_relative 'dummy/app/admin/dashboard'
require_relative 'dummy/config/routes'
If you want to add routes in rails, based on a timeframe, you can do this as follows:
In config/routes.rb
scope constraints: lambda { |request| TimeRoutingConstraint.new('18.11.2015 18:00', '17.12.2015 00:00').matches?(request) } do
get 'gewinnspiel', to: 'contest/registrations#new',
as: 'new_contest_registration'
mount Contest::Engine, at: '/contest'
end
get 'gewinnspiel', to: 'contest/registrations#closed'
In app/routing_constraints/time_routing_constraint.rb
class TimeRoutingConstraint
def initialize(from, to)
@from = Time.zone.parse(from)
@to = Time.zone.parse(to)
end
def matches?(request)
now = Time.zone.now
if now > @from && now < @to
true
else
false
end
end
end
Set credentials:
aws configure
Show bucket files:
aws s3 ls s3://<bucket_name>
Get bucket region:
aws s3api get-bucket-location --bucket <bucket_name>
Upload folder to bucket:
aws s3 cp <local_folder> s3://<bucket_name> --recursive
Same with region:
aws s3 cp <local_folder> s3://<bucket_name> --recursive --region <region>
Hint: Frankfurt is eu-central-1
Build docker image from Dockerfile
docker build .
Tag image:
docker tag <hash> <organisation>/<image_name>:<version>
Push to dockerhub:
docker push <organisation>/<image_name>
List local docker images
docker images
Delete docker tag:
docker rmi <hash>
List running images/processes:
docker ps -l
Stop container:
docker stop <container_idsh>
Start container
docker start <hash>
Run an image and bash into it:
docker run -t -i <hash/image_name:tag> /bin/bash
Run a container with the current directory mounted int /app:
docker run -v $PWD:/app -it <hash/image_name:tag> /bin/bash
Bundle and run Rspec suite:
docker run --volume $PWD:/data --workdir /data -ti example/rails:2.0.2 /bin/bash -lc 'cd . && bundle install && bundle exec rspec'
find . -wholename "*/locales/*de.yml" -print | zip locale_files-2015-07-08.zip -@
# foo/engine.rb
module Foo
class Engine < ::Rails::Engine
config.autoload_paths += Dir["#{config.root}/lib/**/"]
end
end
$ ssh-copy-id -i username@remote-host
To view a list of users and their status use following SQL statement:
select username,expiry_date,account_status from dba_users;
To unlock a user:
alter user <USERNAME> identified by <PASSWORD> account unlock;
To unlock an expired system user on oracle 12c, you habe to specify the container:
alter session set container=CDB$ROOT;
alter user system identified by oracle container=all;
Otherwise you’ll get following error:
ORA-65066: The specified changed must apply to all containers
SELECT username,
osuser,
terminal
FROM v$session
WHERE username IS NOT NULL
ORDER BY username ASC;
SELECT b.Total_MB,
b.Total_MB - round(a.used_blocks*8/1024) Current_Free_MB,
round(used_blocks*8/1024) Current_Used_MB,
round (max_used_blocks*8/1024) Max_used_MB
FROM v$sort_segment a,
(SELECT round(sum(bytes)/1024/1024) Total_MB
FROM dba_temp_files) b;
Good blog post!
Append ‘?pp=profile-gc’ to the url