Skip to content

Instantly share code, notes, and snippets.

View dungdm93's full-sized avatar
🏁
Working hard

Đặng Minh Dũng dungdm93

🏁
Working hard
  • VPBank
  • Hanoi, Vietnam
  • Facebook dungdm93
View GitHub Profile
@dungdm93
dungdm93 / YAML.rb
Created March 16, 2016 09:24
serialize using YAML coder
###
# define serialize in +ActiveRecord::AttributeMethods::Serialization#serialization+
# => create coder
# which is used in +ActiveRecord::Type::Serialized+
# attr is loaded in +ActiveRecord::Type::Serialized#type_cast_from_database+
# attr is dumped in +ActiveRecord::Type::Serialized#type_cast_for_database+
###
# active_record/coders/yaml.rb
module ActiveRecord::Coders
@dungdm93
dungdm93 / serializable.rb
Created March 19, 2016 11:20
Serializable Attribute
module Serializable
extend ActiveSupport::Concern
module ClassMethods
def dump(obj)
return if obj.nil?
assert_valid_value obj
ActiveSupport::JSON.encode obj
end
@dungdm93
dungdm93 / web-fragment.xml
Last active May 7, 2016 07:16
Sample web.xml
<web-fragment version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd">
</web-fragment>
@dungdm93
dungdm93 / TimeZone vs. ZondID.java
Last active June 29, 2018 03:05
[Java] TimeZone
Arrays.stream(TimeZone.getAvailableIDs()).forEach(id -> {
boolean flag = false;
try {
ZoneId.of(id);
flag = true;
} catch (Exception e) {
//ignore;
}
if (!flag)
System.out.printf("[%s] %s%n", flag ? "x" : " ", id);
@dungdm93
dungdm93 / jinja-cli.py
Last active October 18, 2018 14:31
Render Jinja template
import jinja2
loader = jinja2.FileSystemLoader(searchpath="./")
env = jinja2.Environment(loader=loader)
TEMPLATE_FILE = "template.j2"
template = env.get_template(TEMPLATE_FILE)
output = template.render()
print(f"[{output}]")
@dungdm93
dungdm93 / bash-color.sh
Created October 23, 2018 04:16
Colorize terminal
#!/bin/bash
##### Color table #####
# Black 0;30 Dark Gray 1;30
# Red 0;31 Light Red 1;31
# Green 0;32 Light Green 1;32
# Brown/Orange 0;33 Yellow 1;33
# Blue 0;34 Light Blue 1;34
# Purple 0;35 Light Purple 1;35
# Cyan 0;36 Light Cyan 1;36
alias ..='cd ..'
if [[ ! "$PATH" =~ (^|:)"$HOME/.local/bin"(:|$) ]]; then
export PATH="$HOME/.local/bin:$PATH"
fi
export SDKMAN_DIR="$HOME/.sdkman"
[[ -s "$SDKMAN_DIR/bin/sdkman-init.sh" ]] && source "$SDKMAN_DIR/bin/sdkman-init.sh"
export NVM_DIR="$HOME/.nvm"
@dungdm93
dungdm93 / 0-README.md
Last active July 7, 2019 04:10
Django serve staticfiles

Django Staticfiles

Django staticfiles is the most common problem you need to solve before putting your app on the production. In this tutorial, I and you will walk through the solution options, included.

  • runserver: Only in development environment.
  • gunicorn: Use gunicorn as your app server.
  • nginx: Put nginx web server in a front of your app server (gunicorn).
  • whitenoise: Let your django app self-serve static files.
@dungdm93
dungdm93 / semver-regex.md
Last active September 23, 2019 07:25
SemVer regex

Canonical regex

/^
(?'MAJOR'
    0|(?:[1-9]\d*)
)
\.
(?'MINOR'
 0|(?:[1-9]\d*)
@dungdm93
dungdm93 / README.md
Last active February 11, 2020 02:40
faster import nyc-taxi-data

PostgreSQL

Monitoring Progress of Index Construction

PostgreSQL 12+

SELECT 
  now()::TIME(0), 
  a.query, 
  p.phase, 
  p.blocks_total, 
  p.blocks_done,