Skip to content

Instantly share code, notes, and snippets.

View huantt's full-sized avatar
🎯
Focusing

Jack huantt

🎯
Focusing
View GitHub Profile
@huantt
huantt / ParseWord.groovy
Last active January 21, 2019 02:44
Regex get string between 2 words
String regex = "(?<=GET ).*(?=\\ HTTP)";
Pattern pattern = Pattern.compile(regex);
new File("src/main/resources/access.log.2019-01-18.log").readLines().each { line ->
def matcher = pattern.matcher(line)
if (matcher.find()){
matcher.group(0)
}
}
@huantt
huantt / InitObjectFromMap.groovy
Created April 9, 2019 03:51
We can use this function to copy value from an object to another object that has some fields is the same
DeviceInfo deviceInfo = new DeviceInfo()
InvokerHelper.setProperties(deviceInfo, deviceDetector.getDeviceInfo(client.userAgent).properties)
@huantt
huantt / MultiMongoConfig.groovy
Created August 16, 2019 03:36
Spring multi mongodb configuration
@CompileStatic
@Configuration
class MongoDBConfig {
@Value('${mongodb.uri.meta}')
private String metaURI
@Value('${mongodb.uri.sdk}')
private String sdkURI
private MongoMappingContext mongoMappingContext
@huantt
huantt / CombileMultiFuture.java
Last active February 6, 2020 02:07
Combile Multiple Futures in Java + Async-http-client example
package app
import org.asynchttpclient.AsyncHttpClient
import org.asynchttpclient.Response
import java.util.concurrent.CompletableFuture
import java.util.concurrent.TimeUnit
import static org.asynchttpclient.Dsl.asyncHttpClient
import static org.asynchttpclient.Dsl.config;
class Runner {
!function(e){function t(t){for(var r,i,s=t[0],l=t[1],c=t[2],d=0,p=[];d<s.length;d++)i=s[d],a[i]&&p.push(a[i][0]),a[i]=0;for(r in l)Object.prototype.hasOwnProperty.call(l,r)&&(e[r]=l[r]);for(u&&u(t);p.length;)p.shift()();return o.push.apply(o,c||[]),n()}function n(){for(var e,t=0;t<o.length;t++){for(var n=o[t],r=!0,s=1;s<n.length;s++){var l=n[s];0!==a[l]&&(r=!1)}r&&(o.splice(t--,1),e=i(i.s=n[0]))}return e}var r={},a={0:0},o=[];function i(t){if(r[t])return r[t].exports;var n=r[t]={i:t,l:!1,exports:{}};return e[t].call(n.exports,n,n.exports,i),n.l=!0,n.exports}i.m=e,i.c=r,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e
<!DOCTYPE html>
<html ng-app="app" ng-strict-di>
<head lang="en">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<base href="/">
<title>Redash</title>
<script src="/static/unsupportedRedirect.js" async></script>
<link rel="icon" type="image/png" sizes="32x32" href="/static/images/favicon-32x32.png">
[
{
"createdAt": "2021-12-15T05:22:33.565Z",
"name": "Mệnh Mộc hợp màu gì? Kỵ màu gì? Màu sắc tốt cho mệnh Mộc nhất",
"avatar": "/assets/images/news/SubNews/new-2-1.jpg",
"description": [
{
"id": 1,
"name": "Để góp phần mang lại may mắn, tài lộc cho gia chủ trong đường công danh, sự nghiệp hay tình duyên thì việc chọn lựa được màu sắc hợp mệnh rất quan trọng. Người mệnh Mộc hợp màu gì? Kỵ màu gì? Tìm hiểu qua bài viết dưới đây."
},
@huantt
huantt / run.tpl
Last active April 17, 2022 01:06 — forked from efrecon/run.tpl
`docker inspect` template to regenerate the `docker run` command that created a container. Run by `docker inspect --format "$(<run.tpl)" {CONTAINER_ID}`
docker run \
--name {{printf "%q" .Name}} \
{{- with .HostConfig}}
{{- if .Privileged}}
--privileged \
{{- end}}
{{- if .AutoRemove}}
--rm \
{{- end}}
{{- if .Runtime}}
@huantt
huantt / slug.js
Created May 1, 2022 11:19 — forked from bluzky/slug.js
Remove vietnamese accent javascript / Bỏ dấu tiếng Việt
function stringToSlug(str) {
// remove accents
var from = "àáãảạăằắẳẵặâầấẩẫậèéẻẽẹêềếểễệđùúủũụưừứửữựòóỏõọôồốổỗộơờớởỡợìíỉĩịäëïîöüûñçýỳỹỵỷ",
to = "aaaaaaaaaaaaaaaaaeeeeeeeeeeeduuuuuuuuuuuoooooooooooooooooiiiiiaeiiouuncyyyyy";
for (var i=0, l=from.length ; i < l ; i++) {
str = str.replace(RegExp(from[i], "gi"), to[i]);
}
str = str.toLowerCase()
.trim()
@huantt
huantt / clean_code.md
Created May 3, 2022 02:47 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules