Skip to content

Instantly share code, notes, and snippets.

@aquajach
aquajach / gist:3529e5a7541620ad5e8f
Last active August 29, 2015 14:11
Is it possible?
<youtube-video data-code='hkk68&$'></youtube-video>
<template>
<iframe src="http://youtube.com/#{youtube-code}/"></iframe>
</template>
<!-- I want use the youtube-video element with code to get the iframe of of YouTube video --!>
<!-- Is it possible to make youtube-code in template generic as a variable whose value is data-code in youtube-video? --!>
<!-- The template is more complex than above in reality by the way --!>
@aquajach
aquajach / gist:a0271fcf6551ad0a0e99
Last active August 29, 2015 14:12
Front-end style
#for css
body#search{
...
}
#for js
- if $('body#search').length
......
#for layout view file, e.g. applicaiton.html.haml
@aquajach
aquajach / gist:64c1a772a99007284535
Created January 6, 2015 03:20
Exception in production
ActiveRecord::StatementInvalid (PG::SyntaxError: ERROR: syntax error at or near ")"
LINE 20: ...(CASE WHEN lower(partners_languages.language) IN () THEN 1 E...
^
:
SELECT users.id FROM (
SELECT users.id, (CASE WHEN lower(users.my_sector) = lower('Real Estate') THEN users.score + 2 ELSE users.score END) AS score
FROM (
SELECT users.id, users.my_sector, SUM(location) AS score
FROM (
SELECT
@aquajach
aquajach / gist:d55a57931c2503d0cda0
Created June 2, 2015 06:57
Cube Crash Log in iPod Touch 5
Incident Identifier: 57DEF0EE-1D59-4D9F-B964-F50AEDAF84E8
CrashReporter Key: feb41b2edb9ca5ec937b84d25db077c80c5c2d24
Hardware Model: iPod5,1
Process: aggregated [28]
Path: /System/Library/PrivateFrameworks/AggregateDictionary.framework/Support/aggregated
Identifier: aggregated
Version: ???
Code Type: ARM (Native)
Parent Process: launchd [1]
APP_CERT_PEM = File.read("#{Rails.root}/certs/app_cert.pem")
APP_KEY_PEM = File.read("#{Rails.root}/certs/app_key.pem")
def encrypt_for_paypal(values)
signed = OpenSSL::PKCS7::sign(OpenSSL::X509::Certificate.new(APP_CERT_PEM),
OpenSSL::PKey::RSA.new(APP_KEY_PEM, ''), values.map { |k, v| "#{k}=#{v}" }.join("\n"), [], OpenSSL::PKCS7::BINARY)
OpenSSL::PKCS7::encrypt([OpenSSL::X509::Certificate.new(PAYPAL_CERT_PEM)], signed.to_der, OpenSSL::Cipher::Cipher::new("DES3"), OpenSSL::PKCS7::BINARY).to_s.gsub("\n", "")
end
<% payment_service_for @order_id, @seller_account_email,
:amount => @total_price,
:currency => @currency,
:service => 'paypal',
:html => { :id => 'my-form' } do |service| %>
<% service.customer :first_name => @customer.first_name,
:last_name => @customer.last_name,
:phone => @customer.phone,
:email => @customer.email %>
mkdir certs
cd certs
openssl genrsa -out app_key.pem 1024
openssl req -new -key app_key.pem -x509 -days 365 -out app_cert.pem
#Encrypt the transaction information
cert_id =YAML.load(File.open("#{RAILS_ROOT}/config/paypal.yml"))[ENV["RAILS_ENV"]]['paypal']['cert_id']
paypal_params = {:cert_id=&gt;cert_id}
service.form_fields.collect do |field, value|
paypal_params.merge!({field=&gt;value})
end
result << hidden_field_tag(:cmd, "_s-xclick")
result << "\n"
result << hidden_field_tag(:encrypted, encrypt_for_paypal(paypal_params))
# result << service.form_fields.collect do |field, value|
development:
paypal:
login:
password:
signature:
cert_id :
paypal_standard:
email:
password: