Skip to content

Instantly share code, notes, and snippets.

View vtno's full-sized avatar
👾
building

Tino Thamjarat vtno

👾
building
View GitHub Profile
@vtno
vtno / VSCODE_settings.json
Last active September 14, 2017 04:47
My VSCODE setting.
{
"window.zoomLevel": 1,
"editor.tabCompletion": false,
"editor.tabSize": 2,
"files.insertFinalNewline": false,
"editor.scrollBeyondLastLine": false,
"stylelint.enable": true,
"stylelint.config": {
"extends": "stylelint-config-standard",
"rules": {
@vtno
vtno / Ruby Lambdas.md
Created May 9, 2017 09:38 — forked from Integralist/Ruby Lambdas.md
Ruby lambdas

Lambda: standard

# Creating a lambda
l = lambda { |name| "Hi #{name}!" }

# Executing the lambda
l.call("foo") # => Hi foo!
@vtno
vtno / aws-workshop.md
Created May 19, 2017 08:44
AWS-workshop instruction

AWS Workshop

Instructions

VPC

  1. Select pin on top of the page and drag VPC, EDS, ElasticCache and EC2 to it.
  2. Create VPC in Your VPC menu
  3. Create Subnet
  4. Create Gateway
  5. Associate subnet with gateway
@vtno
vtno / parameterized-1.rb
Last active July 13, 2017 04:24
Refactoring blog: Parameterization
def weight_avg_gross_profit(reports)
# find total weight, sum of sale_revenue
total_weight = reports.reduce(0) { |sum, r| sum + r.sale_revenue }
# find sum products
sum_prod = reports.reduce do |sum, r|
sum + (r.percent_gross_profit * r.sale_revenue)
end
# simple weight average formula, (w1*x1 + w2*x2) / (w1 + w2)
@vtno
vtno / parameterized-2.rb
Last active July 13, 2017 04:23
Refactoring blog: Parameterized
def weight_avg_gross_profit(reports)
# find total weight, sum of sale_revenue
total_weight = reports.reduce(0) { |sum, r| sum + r.sale_revenue }
# find sum products
sum_prod = reports.reduce(0) do |sum, r|
sum + (r.percent_gross_profit * r.sale_revenue)
end
# simple weight average formula, (w1*x1 + w2*x2) / (w1 + w2)
def weight_avg_gross_profit(reports)
weight_avg(reports, 'gross_profit')
end
def weight_avg_cogs(reports)
weight_avg(reports, 'cogs')
end
def weight_avg(reports, value)
total_weight = reports.reduce(0) { |sum, r| sum + r.sale_revenue }
@vtno
vtno / parameterized_working_example.rb
Created July 13, 2017 05:09
This accept values for 2 reports and then calculate weight average by sale revenue of gross profit and cogs of those reports.
# frozen_string_literal: true
Report = Struct.new(:sale_revenue, :gross_profit, :cogs)
def main
puts '## First report ##'
puts 'Input revenue: '
revenue1 = gets.chomp.to_f
puts 'Input gross profit: '
gp1 = gets.chomp.to_f
@vtno
vtno / functional_cart.rb
Last active July 14, 2017 11:39
My attempt on mixing functional programming and good ol' OO in Ruby.
Item = Struct.new(:amount, :price, :name) do
def total_price
amount * price
end
end
Cart = Struct.new(:items) do
# total amount is finding sum of item amount
def total_amount
# a.k.a finding sum by item.amount function
@vtno
vtno / preciseMath.js
Last active August 22, 2017 05:13
handle floating point annoying operation
const preciseOperation = f => (a, b, decimalDigits) => {
decimalDigits = decimalDigits || 12
+(f(a, b)).toFixed(decimalDigits)
}
const add = (a, b) => a + b
const minus = (a, b) => a - b
const multiply = (a, b) => a * b
const divide = (a, b) => a / b
export const preciseAdd = (a, b, decimalDigits) => preciseOperation(add)(a,b, decimalDigits)
export const preciseMinus = (a, b, decimalDigits) => preciseOperation(minus)(a,b, decimalDigits)
@vtno
vtno / atom-stylesheet
Created September 13, 2017 02:31
My atom stylesheet
/*
* Your Stylesheet
*
* This stylesheet is loaded when Atom starts up and is reloaded automatically
* when it is changed and saved.
*
* Add your own CSS or Less to fully customize Atom.
* If you are unfamiliar with Less, you can read more about it here:
* http://lesscss.org
*/