Skip to content

Instantly share code, notes, and snippets.

View viphat's full-sized avatar
🎯
Focusing

Duong Vi Phat viphat

🎯
Focusing
  • Osaka, Japan
View GitHub Profile
{
"response": {
"body": {
"data": {
"id": null,
"accountMenuHeaderEnabled": true,
"affiliateEnabled": true,
"allowSignInBySaml": false,
"allowSignup": true,
"allowSignupByApple": true,
@viphat
viphat / the-art-of-readable-code.md
Last active September 7, 2022 05:03
The Art of Readable Code

The goal of this book is help you make your code better. And when we say "code", we literally mean the lines of code you are staring at in your editor. We’re not talking about the overall architecture of your project, or your choice of design patterns. Those are certainly important, but in our experience most of our day-to-day lives as programmers are spent on the “basic” stuff, like naming variables, writing loops, and attacking problems down at the function level. And a big part of this is reading and editing the code that’s already there.

KEY IDEA 1 - Code should be easy to understand.

KEY IDEA 2 - Code should be written to minimize the time it would take for someone else (may be you sixth months later) to understand it.

Is smaller always better?

The less code you write to solve a problem, the better. It probably takes less time to understand a 2000 line class than a 5000 line class

const { GoogleSpreadsheet } = require('google-spreadsheet')
const secret = require('./xxxx-yyyyyyyyyyyy.json')
const fs = require('fs')
//# Initialize the sheet
const doc = new GoogleSpreadsheet(
'1AgaWjGYPOjXXmoicyRqnh-m_wLXhcXbxtrrq30dBjak',
)
@viphat
viphat / Damage_Calculator.js
Created September 27, 2014 01:04
Pokemon Damage Calculator Kata on Codewars - http://www.codewars.com/kata/536e9a7973130a06eb000e9f
function calculateDamage(yourType, opponentType, attack, defense){
var type = {
fire:0,
water:1,
grass:2,
electric:3
};
var effectivenessTable = [[0.5,0.5,2,1],[2,0.5,0.5,0.5],[0.5,2,0.5,1],[1,2,1,0.5]];
@viphat
viphat / gist:bf6e478db39ffc870e0adec08f6c447e
Created August 24, 2020 23:47
Resend Domain Name Renewal Reminders
DomainNameMailer.renewal_reminder_email 16070, [7759], 30
DomainNameMailer.renewal_reminder_email 25697, [16261], 30
DomainNameMailer.renewal_reminder_email 31395, [917], 30
DomainNameMailer.renewal_reminder_email 32597, [10577], 30
DomainNameMailer.renewal_reminder_email 75240, [34461], 30
DomainNameMailer.renewal_reminder_email 75243, [34461], 30
DomainNameMailer.renewal_reminder_email 75254, [41933], 30
DomainNameMailer.renewal_reminder_email 75255, [41933], 30
DomainNameMailer.renewal_reminder_email 110255, [42769, 43485], 30
DomainNameMailer.renewal_reminder_email 117566, [8396, 43717], 30
%simplicity_theme {
box-sizing: border-box;
background-color: #fff;
margin-bottom: 30px;
font-size: 16px;
line-height: 170%;
img {
max-width: 100%;
height: auto !important;
[90.79.105.133] [b835e17645e393d5bc174ca464313608] [891c2732-9701-4270-a96e-8c76715de78e] Processing by CartsController#show as HTML
[90.79.105.133] [b835e17645e393d5bc174ca464313608] [1f1d7564-df12-4c1b-b48a-49a68c5d21c8] CartItem::Factory:find_item:345954
[90.79.105.133] [b835e17645e393d5bc174ca464313608] [1f1d7564-df12-4c1b-b48a-49a68c5d21c8] Rules::DiscountRules:#<Product::DomainRegister id: 1036, type: "Product::DomainRegister", slug: "domain-register-com", name: "com", unit_price: #<BigDecimal:7f210e4023e8,'0.12E2',9(18)>, duration: "1,2,3,4,5,6,7,8,9,10", unit: 2, active: true, cost_price: #<BigDecimal:7f210e402140,'0.653E1',18(27)>, minimum_selling_price: #<BigDecimal:7f210e402050,'0.698E1',18(27)>, properties: {}, created_at: "2012-10-22 16:46:58", updated_at: "2012-10-22 16:46:58">
[90.79.105.133] [b835e17645e393d5bc174ca464313608] [1f1d7564-df12-4c1b-b48a-49a68c5d21c8] CartItem::Factory:find_item:345956
[90.79.105.133] [b835e17645e393d5bc174ca464313608] [1f1d7564-df12-4c1b-b48a-49a68c5d21c8] Rules:
[90.79.105.133] [b835e17645e393d5bc174ca464313608] [74057c17-3a4b-4fff-940b-3e49c88d96a0] CartsController::edit_user:#<User::AttributesCollector:0x007fa659869488 @items=[#<CartItem::DomainRegister id: 345954, cart_id: 7788732, product_id: 1036, type: "CartItem::DomainRegister", key: "naturist-paris.com", duration: 1, discount: nil, properties: {"owner"=>"CD365364", "admin"=>"CD365364", "billing"=>"CD365364", "tech"=>"CD365364"}, created_at: "2019-05-18 10:55:00", updated_at: "2019-05-18 10:56:00">, #<CartItem::DomainRegister id: 345956, cart_id: 7788732, product_id: 1036, type: "CartItem::DomainRegister", key: "naturist-plantes.com", duration: 1, discount: nil, properties: {"owner"=>"CD365364", "admin"=>"CD365364", "billing"=>"CD365364", "tech"=>"CD365364"}, created_at: "2019-05-18 10:55:10", updated_at: "2019-05-18 10:56:00">], @users={}, @data_models={}>
...
...
...
[90.79.105.133] [b835e17645e393d5bc174ca464313608] [e437b44d-c2c2-419c-8079-38331f94ad52] Started GET "/checkout/validate" for 90.79.105.133 at
@viphat
viphat / x.sublime-settings
Last active May 18, 2018 13:16
Sublime Settings
{
"auto_complete": true,
"auto_complete_commit_on_tab": true,
"caret_style": "solid",
"color_scheme": "Packages/Predawn/predawn.tmTheme",
"copy_with_empty_selection": true,
"draw_white_space": "all",
"ensure_newline_at_eof_on_save": true,
"find_selected_text": true,
"font_face": "Source Code Variable Regular",
@viphat
viphat / table_partition.sql
Created November 17, 2017 10:26
Table Partitioning with Postgres
EXPLAIN ANALYZE
select count(*) from ais_trackings;
select * from ais_trackings LIMIT 1;
DELETE from ais_trackings WHERE last_ais_updated_at < '2017-11-15'
DROP TABLE ais_trackings_2017_11_16;
CREATE TABLE ais_trackings_2017_11_14 (