Skip to content

Instantly share code, notes, and snippets.

View vinh0604's full-sized avatar

Vinh Bachsy vinh0604

View GitHub Profile
@vinh0604
vinh0604 / SketchSystems.spec
Last active July 3, 2023 08:38
Merchant Checkout
Merchant Checkout
Display QRPH QR code
scan -> Payment Info
Tenant Mobile App
Payment Info
input amount currency -> Confirm Payment
Confirm Payment
confirm -> Submit Transaction
Submit Transaction&
@vinh0604
vinh0604 / sample.js
Created May 21, 2017 11:43
Medium Code Sample 2 - Refactoring legacy code base
filterByRegion(request, region)
filterByPrice(request, minPrice, maxPrice)
@vinh0604
vinh0604 / sample.js
Created May 21, 2017 11:41
Medium code sample - Refactoring legacy code base
// adding region filter to the request
// if region is not provided, considering it as select all
if (regions === null || regions.length === 0) {
request.filter.bool.must.push({
match: {
region: 'all'
}
})
} else {
regions.forEach((region) => {
@vinh0604
vinh0604 / index.3000.html
Created April 23, 2017 14:25
Sample index page for site 3000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Hello from 3000</title>
</head>
<body>
<h1>Hello from 3000:</h1>
@vinh0604
vinh0604 / index.html
Created April 23, 2017 14:24
Sample index page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Hello from 80</title>
</head>
<body>
<h1>Hello from 80:</h1>
@vinh0604
vinh0604 / JodaMoneySerializer.scala
Created February 26, 2016 14:40
json4s-jackson custom serializer for Joda Money
class JodaMoneySerializer extends CustomSerializer[Money](format => (
{
case JObject(JField("value", JDecimal(value)) :: JField("currency", JString(currency)) :: Nil) =>
Money.of(CurrencyUnit.getInstance(currency), value.bigDecimal)
},
{
case money: Money =>
JObject(
JField("value", JDecimal(BigDecimal(money.getAmount))) ::
JField("currency", JString(money.getCurrencyUnit.getCurrencyCode)) ::
@vinh0604
vinh0604 / gist:2d447b3e878a0130da33
Created December 26, 2014 12:33
Paperclip handler for Hashie::Mash and Hash (Grape API)
module Paperclip
class HashieMashUploadedFileAdapter < AbstractAdapter
attr_accessor :original_filename # use this accessor if you have paperclip version < 3.3.0
def initialize(target)
@tempfile, @content_type, @size = target.tempfile, target.type, target.tempfile.size
self.original_filename = target.filename
end
end
@vinh0604
vinh0604 / unaccent.rules
Created August 16, 2014 16:52
Postgres unaccent rules for Vietnamese
À A
Á A
Ả A
Ạ A
 A
Ấ A
Ầ A
Ẩ A
Ậ A
Ẫ A

I wanted a way to scale up and down the dynos in Heroku based on time of day. To do so, I added the scheduler add-on to heroku heroku addons:add scheduler

In my Rails app, I added the scale_dynos.rake file in /lib/tasks/ and the following line to the Gemfile: gem 'heroku-api', '~> 0.3.17', :require => false

Now I can run heroku run rake scale_dynos:up (and down) through the command line, as well as scheduling the command rake scale_dynos:up in the Scheduler add-on. a

@vinh0604
vinh0604 / info.plist
Created January 31, 2014 02:59
Alfred Workflow
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>bundleid</key>
<string>vn.ducvinh.alfred-awesome-units</string>
<key>connections</key>
<dict>
<key>4EF792DA-655D-49A8-ADE8-13AB0A6273B4</key>
<array>