Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View tuanna-hsp's full-sized avatar
🏠
Working from home

Nguyễn Anh Tuấn tuanna-hsp

🏠
Working from home
View GitHub Profile
@tuanna-hsp
tuanna-hsp / type-of-clients.ts
Last active October 18, 2022 06:55
Type of clients
class ScrapingClient extends AbstractAggregationClient {
//
// Extending life cycle hooks
//
protected beforeAggregation(params): void {
// Calling superclass implementation to do some common preparation
super.beforeAggregation(params);
// Initialize Chrome instance for scraping
@tuanna-hsp
tuanna-hsp / template-methods.ts
Last active December 15, 2021 04:13
Template methods
abstract class AbstractAggregationClient {
constructor(private readonly options) {}
//
// Public interface
//
public getAccounts(params): AggregationResult {
try {
// Preparation step
@tuanna-hsp
tuanna-hsp / factory.example.ts
Last active December 15, 2021 04:13
Factory class example
class AggregationService {
constructor(private readonly clientFactory: AggregationClientFactory) {}
public processRequest(request: AggregationRequest): void {
const client = this.clientFactory.createClient(request.serviceName);
if (request.type === "getAccounts") {
const result = client.getAccounts();
// Save result
}
<script lang="ts">
export default Vue.extend({
watch: {
saas: {
immediate: true,
handler(value): void {
if (value) {
// Clear current attr values
this.clearFormAttributes();
// Initialize form attributes for new service, note that we must use $set to preserve Vue reactiviy on `form` object
<script lang="ts">
import Vue, { PropType } from "vue";
import { requiredIf } from "vuelidate/lib/validators";
export default Vue.extend({
validations() {
const form: { [rule: string]: any } = {};
this.allAttributes.forEach(attr => {
form[attr] = {
required: requiredIf(function(this: any): boolean {
<template>
<div>
<form ref="form" class="mt-4" autocomplete="off" @submit.stop.prevent="handleSubmit">
<div v-for="attr in allAttributes" :key="attr">
<form-input-integration
v-model="$v.form[attr].$model"
:attribute-name="attr"
:state="validateForm(attr)"
/>
</div>
<template>
<div>
<form ref="form" class="mt-4" autocomplete="off" @submit.stop.prevent="handleSubmit">
<div v-for="attr in allAttributes" :key="attr">
<form-input-integration
v-model="$v.form[attr].$model"
:attribute-name="attr"
:state="validateForm(attr)"
/>
</div>
@tuanna-hsp
tuanna-hsp / Minesweeper.java
Created February 16, 2020 00:22
Minesweeper
class Solution {
int width;
int height;
Queue<Point> q;
HashSet<Integer> h;
class Point {
int x;
@tuanna-hsp
tuanna-hsp / IsSubsequence.java
Created February 16, 2020 00:21
Is subsequence
class Solution {
public boolean isSubsequence(String s, String t) {
if (s.isEmpty()) {
return true;
}
int lastBreak = 0;
int sIndex = 0;
int tIndex = 0;
int sLength = s.length();
@tuanna-hsp
tuanna-hsp / RomanToInteger.java
Created February 16, 2020 00:18
Roman to integer
class Solution {
private int symbolValue(char ch) {
switch (ch) {
case 'I':
return 1;
case 'V':
return 5;
case 'X':
return 10;
case 'L':