Skip to content

Instantly share code, notes, and snippets.

View nvh0412's full-sized avatar

Hoa Nguyen nvh0412

View GitHub Profile
@nvh0412
nvh0412 / benchmark.rb
Created March 27, 2021 08:05
Benchmark mini_mime vs marcel
require 'marcel'
require 'memory_profiler'
require 'benchmark/ips'
puts "Memory stats for requiring mini_mime"
result = MemoryProfiler.report do
require 'mini_mime'
end
puts "Total allocated: #{result.total_allocated_memsize} bytes (#{result.total_allocated} objects)"
@nvh0412
nvh0412 / js
Created June 19, 2017 11:07
Formsy
return (
<Formsy.Form ref={(form) => {this.formsyForm = form;}} onSubmit={(model) => { onSubmit(model); }} onValid={this.enableButton} onInvalid={this.disableButton}>
<Dialog
title="Tạo bill mới"
actions={actions}
open={selectedBill.editing}
>
<BillInput name='bill[full_name]' isSmall={true} required label="Họ Tên" value={selectedBill.full_name} validations="isExisty" errorMessage="Điền họ tên vào nhé người đẹp"/>
<BillPhoneNumberInput name='bill[phone_number]' isSmall={true} label="Số điện thoại" value={selectedBill.phone_number} required validations="maxLength:13" validationError="Số ĐT tối đa 11 số"/>
<BillAddressInput name='bill[ship_address]' label="Địa chỉ" value={selectedBill.ship_address} requied/>
@nvh0412
nvh0412 / production.rb
Created December 13, 2015 18:08
Mail configuration
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: ENV['MAIL_DOMAIN'],
user_name: ENV['MAIL_ID'],
password: ENV['MAIL_PASSWORD'],
authentication: 'plain',
enable_starttls_auto: true }
@nvh0412
nvh0412 / Order.rb
Created December 8, 2015 14:52
Send SMS with twilio
def send_message(cart)
message = "\nYour order:\n"
cart.orderlines.each do |orderline|
message += "* #{orderline.food.name} x #{orderline.quantity} - price: $#{orderline.unit_price}\n"
end
message += "\nTotal value: #{cart.orderlines.sum(:unit_price)}"
@client = Twilio::REST::Client.new ENV['TWILIO_SID'], ENV['TWILIO_TOKEN']
@client.messages.create(
from: ENV['TWILIO_TEL'],
to: phone,