Create QRCode to be opened URL in browser - url

In my application I need to show a QRCode that embeds a URL to be opened in a browser.
I'm using the Nayuki library in my Qt/C++ application and I encode this string:
"http://mydevice.local"
but my device (Android) decodes it as a literal string, asking me if I want to copy the text.
Encoding a commercial website, say:
"http://www.google.com"
instead works as expected, asking me if I want to open the URL in a browser.
Because the protocol is not enough to trigger this feature, how I need to encode such a URL?

If http://www.google.com works, but http://mydevice.local doesn't, then it's probably not an encoding problem. Maybe the library that decodes qr codes on your device simply doesn't recognize .local as a valid TLD.
I don't have an android device on hand, but an iphone running IOS 15.1 opens a browser with the desired url for both urls.
for reference, here are the qr codes I used (generated using qrencode -t ansiutf8):
http://mydevice.local:
█████████████████████████████████
█████████████████████████████████
████ ▄▄▄▄▄ █▄▄▄ ▀█▄███ ▄▄▄▄▄ ████
████ █ █ ██▄▀ █ ▄ ▀█ █ █ ████
████ █▄▄▄█ ██▀▄ ▄▀▄█ █ █▄▄▄█ ████
████▄▄▄▄▄▄▄█ ▀▄█ ▀▄▀ █▄▄▄▄▄▄▄████
████▄ █ ▄█▄▀▀▄▀█▄█ ▀ █▄▀▀▀▀▀▄████
████▄▀▀▄ ▄▄▀▄██▄█ ▄▄▀ ▄ ▀▀ ████
████ ██ ▀▄█▀▄ █▀█▀ █▄█▀██▀▄████
████ ▄ ▄█▀▄ ▄█▀▄ ▀ ▀█▄ ▄ ████
████▄██▄█▄▄█▀▄▄ ▄▀▄▄ ▄▄▄ █▄ █████
████ ▄▄▄▄▄ ███▄▀▄▀ ▀ █▄█ ▄██▄████
████ █ █ █ ▀▀▄▀ ▀ ▄▄ █ ████
████ █▄▄▄█ █▀ ▄ ▀ █▄▄█▀ █ ████
████▄▄▄▄▄▄▄█▄▄▄▄▄▄██▄▄███▄██▄████
█████████████████████████████████
█████████████████████████████████
http://www.google.com:
█████████████████████████████████
█████████████████████████████████
████ ▄▄▄▄▄ █▄▄▄ ▀█▄█ █ ▄▄▄▄▄ ████
████ █ █ ██▄▀ █ █▄▀█ █ █ ████
████ █▄▄▄█ ██▀▄ ▄▀▄█ █ █▄▄▄█ ████
████▄▄▄▄▄▄▄█ ▀▄█ ▀▄█ █▄▄▄▄▄▄▄████
████ █ █▄██▄▀█▄▀ ▀▄▀▄▀▀▀▀▀▄████
████ ▀▄█▄▄▄▀▄▄██▄▄▀ ▄█▄ █ ▀▀ ████
████ █▀█▄▄▄▀█ █▀█▀ ▄▄█▀██▀▄████
████ ▄ ▀█▀▄▄▄ █▀▄▄ █▄█▀ ▄ ▄ ████
████▄███▄▄▄█▀ ▀ ▄▀▄█ ▄▄▄ █▄ █████
████ ▄▄▄▄▄ ██ ▀▀▄▀ ▀ █▄█ ▄██▄████
████ █ █ █ ▄█▄▀ ▀ ▄ ▄ █ ████
████ █▄▄▄█ █▀▄▄ ▀ ██▄▄▀ █ ████
████▄▄▄▄▄▄▄█▄█▄▄▄▄██▄████▄██▄████
█████████████████████████████████
█████████████████████████████████

Related

Can't attach avatar to model in Rails 6 usgin ActiveStorage

I'm trying to attach an avatar to a profile model. I had rails 5.2 application and updated to rails 6. Here is the form for uploading the avatar.
In the configuration, I require the active storage engine
require_relative 'boot'
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "active_storage/engine"
# require "action_cable/engine"
require "sprockets/railtie"
require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module ArtsySpace
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.1
# Use Vips for processing variants.
config.active_storage.variant_processor = :vips
# Use ActiveStorage for file storage
config.active_storage.service
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
end
end
When I look for a profile avatar I can see it in the console. But when I check if is attached it returns false.
2.5.0 :004 > Profile.first.avatar.methods
Profile Load (0.4ms) SELECT "profiles".* FROM "profiles" ORDER BY "profiles"."id" ASC LIMIT $1 [["LIMIT", 1]]
=> [:detach, :blank?, :purge, :attach, :attachment, :purge_later, :attached?, :method_missing, :record, :name, :to_json, :to_param, :to_query, :deep_dup, :acts_like?, :with_options, :duplicable?, :present?, :presence, :html_safe?, :as_json, :__binding__, :pry, :in?, :presence_in, :instance_values, :instance_variable_names, :to_yaml, :pretty_print_cycle, :pretty_print_inspect, :pretty_print, :pretty_print_instance_variables, :try!, :try, :unloadable, :require_or_load, :load_dependency, :instance_variable_set, :instance_variable_defined?, :remove_instance_variable, :instance_of?, :kind_of?, :is_a?, :tap, :instance_variable_get, :public_methods, :instance_variables, :pretty_inspect, :method, :public_method, :define_singleton_method, :singleton_method, :public_send, :class_eval, :extend, :to_enum, :enum_for, :gem, :<=>, :===, :=~, :!~, :eql?, :respond_to?, :freeze, :inspect, :object_id, :send, :byebug, :remote_byebug, :debugger, :to_s, :display, :nil?, :hash, :class, :clone, :singleton_class, :itself, :dup, :taint, :yield_self, :untaint, :tainted?, :untrusted?, :untrust, :trust, :frozen?, :methods, :singleton_methods, :protected_methods, :private_methods, :!, :equal?, :instance_eval, :instance_exec, :==, :!=, :__id__, :__send__]
2.5.0 :005 > Profile.first.avatar.attached?
Profile Load (0.4ms) SELECT "profiles".* FROM "profiles" ORDER BY "profiles"."id" ASC LIMIT $1 [["LIMIT", 1]]
ActiveStorage::Attachment Load (0.5ms) SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = $1 AND "active_storage_attachments"."record_type" = $2 AND "active_storage_attachments"."name" = $3 LIMIT $4 [["record_id", 1], ["record_type", "Profile"], ["name", "avatar"], ["LIMIT", 1]]
=> false
How can I attach Image to the profile avatar?
I had the following in production but not on development and that was causing the issue.
config.active_storage.service = :local

Paperclip validation not working for excel file for Rails 4 app

So I'm allow many types of file to be uploaded (pdf, doc, docx, ppt, pptx, xls, xlsx and zip) using Paperclip.
So far so good, everything works fine.
Except one thing. I noticed that the *.xls file where not uploaded.
Here my model Document
class Document < ActiveRecord::Base
has_attached_file :file
validates_attachment_content_type :file,
content_type: [
"application/pdf",
"application/vnd.ms-excel",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.ms-powerpoint",
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
"application/zip"]
end
I'm using S3 and this issue is happening in local and production (heroku). I kind of heard that it could be linked to the browser itself; however, I did test on (under os x) Chrome, Safari, Firefox and Opera without success.
Here the log when I try to upload a xls file name this-is-a-test-file.xls :
Started POST "/documents" for ::1 at 2016-08-26 01:41:54 +0200
Processing by DocumentsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"GdnkT1Iw8ajORrrSidpQ4Un4qlcN7qzZFk00j3fTTe0VpDO4ZhGQQG0ckO5DmrDzDdqzLw5SXI+O3p72zuP6qQ==", "document"=>{"file"=>#<ActionDispatch::Http::UploadedFile:0x007fdcc5479b78 #tempfile=#<Tempfile:/var/folders/gc/r_620xsx5hs44l70ftvwxpjr0000gn/T/RackMultipart20160826-79534-4kin0o.xls>, #original_filename="this-is-a-test-file.xls", #content_type="application/octet-stream", #headers="Content-Disposition: form-data; name=\"document[file]\"; filename=\"this-is-a-test-file.xls\"\r\nContent-Type: application/octet-stream\r\n">}, "commit"=>"upload file"}
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
Command :: file -b --mime '/var/folders/gc/r_620xsx5hs44l70ftvwxpjr0000gn/T/99ca719bb8fc2d3a1543726223f4d54520160826-79534-10bpmb.xls'
(0.2ms) BEGIN
Command :: file -b --mime '/var/folders/gc/r_620xsx5hs44l70ftvwxpjr0000gn/T/99ca719bb8fc2d3a1543726223f4d54520160826-79534-176ftj5.xls'
(0.2ms) ROLLBACK
Redirected to http://localhost:3000/documents
Completed 302 Found in 82ms (ActiveRecord: 0.8ms)
Any idea ? :)

boot2docker starting in Windows 7

I am having issues to start boot2docker in windows 7, virtualbox 4.3.26 (installed together with boot2docker).
Here is the output
Boot2Docker-cli version: v1.6.0
Git commit: 9894ae9
2015/05/05 17:08:12 executing: C:\Program Files\Oracle\VirtualBox\VBoxManage.exe showvminfo boot2docker-vm --machinereadable
2015/05/05 17:08:12 executing: C:\Program Files\Oracle\VirtualBox\VBoxManage.exe guestproperty set boot2docker-vm /VirtualBox/GuestAdd/SharedFolders/MountPrefix /
2015/05/05 17:08:12 executing: C:\Program Files\Oracle\VirtualBox\VBoxManage.exe guestproperty set boot2docker-vm /VirtualBox/GuestAdd/SharedFolders/MountDir /
2015/05/05 17:08:12 executing: C:\Program Files\Oracle\VirtualBox\VBoxManage.exe sharedfolder add boot2docker-vm --name c/Users --hostpath C:\Users --automount
VBoxManage.exe: error: Shared folder named 'c/Users' already exists
VBoxManage.exe: error: Details: code VBOX_E_OBJECT_IN_USE (0x80bb000c), component SessionMachine, interface IMachine, callee IUnknown
VBoxManage.exe: error: Context: "CreateSharedFolder(Bstr(name).raw(), Bstr(hostpath).raw(), fWritable, fAutoMount)" at line 1008 of file VBoxManageMisc.cpp
2015/05/05 17:08:12 executing: C:\Program Files\Oracle\VirtualBox\VBoxManage.exe setextradata boot2docker-vm VBoxInternal2/SharedFoldersEnableSymlinksCreate/c/Users 1
2015/05/05 17:08:12 executing: C:\Program Files\Oracle\VirtualBox\VBoxManage.exe startvm boot2docker-vm --type headless
Waiting for VM "boot2docker-vm" to power on...
VM "boot2docker-vm" has been successfully started.
2015/05/05 17:08:16 executing: C:\Program Files\Oracle\VirtualBox\VBoxManage.exe showvminfo boot2docker-vm --machinereadable
Waiting for VM and Docker daemon to start...
.Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connect
ing to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to t
cp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://loc
alhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2
022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (att
empt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0)
.Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connect
ing to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to t
cp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://loc
alhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2
022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (att
empt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0)
.Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connect
ing to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to t
cp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://loc
alhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2
022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (att
empt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0).Connecting to tcp://localhost:2022 (attempt #0)VM Host-only IP address:
Waiting for Docker daemon to start...
o2015/05/05 17:09:53 executing: C:\Program Files (x86)\Git\bin\ssh.exe ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=quiet -p 2022 -i C:\Users\zencv\.ssh\id_boot2docker docker#localhost grep tcp:// /proc/$(cat /var/run/docker.pid)/cmdline
Then it hangs..
My virtualbox config is as follows (sorry, in german):
I tried different things such as deleting the boot2docker-vm, downloading again and starting again and again.
Also please note that this seems to be different from similar issues like Boot2Docker Start up fails or docker on windows not working -- in those cases, the error message explicitly mentions that the virtualization is disabled, but I do not see any such error in my output. Unfortunately, I work in a very controlled env. and I cannot use any tools that check whether virtualization is enabled or not.
This similar boot2docker issue mentions:
It sounds like you might have a stray boot2docker-vm set up in VirtualBox -- it's probably worth trying to open the VirtualBox GUI to delete that and try:
boot2docker -v init
boot2docker -v up
The complete reinstall process is:
docker cask remove virtualbox
docker cask install virtualbox
boot2docker delete
boot2docker init
boot2docker up
Also check if you have a %HOME% environment variable defined:
The problem was my SSH Config. When it try to connect to boot2docker vm, it use my github private key and not the boot2docker private key.
I confirm it works perfectly. Just changing %HOME%/.ssh/config
I added:
Host boot2docker
Hostname localhost
IdentityFile ~/.ssh/id_boot2docker

CSRF token authencity for sub controller

I am getting CSRF warning (resetting my session) in my rails apps whenever I post to my api_controller.rb.
My app is run on iframe in phonegap for windows phone 8 and in my application_controller, I have a p3p header to solve just this problem. But it doesn't seem to work in this case. Its like the p3p is not there...? Has anyone encountered this?
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :header_fix
protected
def header_fix
headers['P3P'] = 'CP="ALL DSP COR CURa ADMa DEVa OUR IND COM NAV"'
end
end
class Api::ApiController < ApplicationController
before_filter :login_required
skip_before_filter :detect_device
skip_before_filter :detect_browser
skip_before_filter :record_log
skip_before_filter :assign_packages
skip_before_filter :assign_daily_bonus
end
[2646 - 2013/04/05 13:04:23] (INFO) Started POST "/api/chests" for 60.50.19.249 at 2013-04-05 13:04:23 +0800
[2646 - 2013/04/05 13:04:23] (INFO) Processing by Api::ChestsController#create as */*
[2646 - 2013/04/05 13:04:23] (INFO) Parameters: {"force_new"=>"true"}
[2646 - 2013/04/05 13:04:23] (WARN) WARNING: Can't verify CSRF token authenticity
[2646 - 2013/04/05 13:04:23] (INFO) User agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)
[2646 - 2013/04/05 13:04:23] (DEBUG) User Load (4.5ms) SELECT `users`.* FROM `users` WHERE `users`.`id` IS NULL LIMIT 1
[2646 - 2013/04/05 13:04:23] (DEBUG) KeyPackage Load (1.2ms) SELECT `packages`.* FROM `packages` WHERE `packages`.`type` IN ('KeyPackage') ORDER BY cost
[2646 - 2013/04/05 13:04:23] (DEBUG) CACHE (0.0ms) SELECT `users`.* FROM `users` WHERE `users`.`id` IS NULL LIMIT 1
[2646 - 2013/04/05 13:04:23] (DEBUG) CACHE (0.0ms) SELECT `users`.* FROM `users` WHERE `users`.`id` IS NULL LIMIT 1
[2646 - 2013/04/05 13:04:23] (WARN) Lost session [60.50.19.249] (/api/chests) - Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)
This gem works for Ruby on Rails (https://github.com/grosser/ie_iframe_cookies). Solves the problem.
Even though my p3p header is valid and my user can login, I am not sure why IE10 does this.

searching by email in ActiveRecord using named scope "<field> is ambiguous'

Using rails 3.2.6.
# 1 letter domain name in email without scope
> Member.where('UPPER(email) LIKE UPPER(?)' , "a#b.com")
Member Load (0.7ms) SELECT "members".* FROM "members" WHERE (UPPER(email) LIKE UPPER('a#b.com'))
=> []
# 2 letter domain name in email without scope
> Member.where('UPPER(email) LIKE UPPER(?)' , "a#bc.com")
Member Load (0.7ms) SELECT "members".* FROM "members" WHERE (UPPER(email) LIKE UPPER('a#bc.com'))
=> []
# 1 letter domain name in email with scope
> Member.with_households.where('UPPER(email) LIKE UPPER(?)' , "a#b.com")
Member Load (0.7ms) SELECT "members".* FROM "members" WHERE (UPPER(email) LIKE UPPER('a#b.com'))
=> []
# 2 letter domain name in email with scope
> Member.with_households.where('UPPER(email) LIKE UPPER(?)' , "a#bs.com")
SQL (0.6ms) SELECT "members"."id" AS t0_r0, "members"."last_name" AS t0_r1, "members"."first_name" AS t0_r2, "members"."household_id" AS t0_r3, "members"."created_at" AS t0_r4, "members"."updated_at" AS t0_r5, "members"."phone1" AS t0_r6, "members"."phone2" AS t0_r
7, "members"."address1" AS t0_r8, "members"."address2" AS t0_r9, "members"."city" AS t0_r10, "members"."state" AS t0_r11, "members"."zip" AS t0_r12, "members"."notes" AS t0_r13, "members"."active" AS t0_r14, "members"."email" AS t0_r15, "households"."id" AS t1_r0, "ho
useholds"."balance" AS t1_r1, "households"."created_at" AS t1_r2, "households"."updated_at" AS t1_r3, "households"."notes" AS t1_r4, "members_households"."id" AS t2_r0, "members_households"."last_name" AS t2_r1, "members_households"."first_name" AS t2_r2, "members_hou
seholds"."household_id" AS t2_r3, "members_households"."created_at" AS t2_r4, "members_households"."updated_at" AS t2_r5, "members_households"."phone1" AS t2_r6, "members_households"."phone2" AS t2_r7, "members_households"."address1" AS t2_r8, "members_households"."ad
dress2" AS t2_r9, "members_households"."city" AS t2_r10, "members_households"."state" AS t2_r11, "members_households"."zip" AS t2_r12, "members_households"."notes" AS t2_r13, "members_households"."active" AS t2_r14, "members_households"."email" AS t2_r15 FROM "members
" LEFT OUTER JOIN "households" ON "households"."id" = "members"."household_id" LEFT OUTER JOIN "members" "members_households" ON "members_households"."household_id" = "households"."id" WHERE (UPPER(email) LIKE UPPER('a#bs.com'))
ActiveRecord::StatementInvalid: PGError: ERROR: column reference "email" is ambiguous
LINE 1: ..."."household_id" = "households"."id" WHERE (UPPER(email) LIK...
Here's the error:
ActiveRecord::StatementInvalid: PGError: ERROR: column reference "email" is ambiguous
A Household has_many Members.
Here's the with_households scope definition:
scope :with_households, :include => [{:household => :members}]
The email domain length may be a red herring, but I couldn't reproduce the error otherwise. Why is Arel doing a bunch of joins in just this case?
Try
Member.with_households.where('UPPER(members.email) LIKE UPPER(?)' , "a#bs.com")
ActiveRecord StatementInvalid is ambiguous is ARs way of saying: Mister, your SQL statement does not make sense because a field you are examining is found on several tables and I don't know which to use.
I'm guessing the with_households scope looks at another table which also has an email field. Or maybe you have a default_scope which does the same. Try specifying the table name everywhere, e.g. members.email and managers.email.
Member.with_households.where(Member.arel_table[:email].matches("a#bs.com"))

Resources