Skip to content

Instantly share code, notes, and snippets.

View huantt's full-sized avatar
🎯
Focusing

Jack huantt

🎯
Focusing
View GitHub Profile
@huantt
huantt / theodoiFile.java
Created June 7, 2016 15:08
Example use "Theo doi file"
public class a {
public static void main(String[] args) throws IOException, InterruptedException {
//tạo một object WatchDirService, theo dõi quá trình tạo file và xóa file
final WatchDirService watchService = new WatchDirService(StandardWatchEventKinds.ENTRY_CREATE,
StandardWatchEventKinds.ENTRY_DELETE);
//đăng ký thư mục cần theo dõi, có thể đăng ký nhiều lần
watchService.registerDir(Paths.get("D:\\"));
@huantt
huantt / MyQueue.java
Created June 7, 2016 16:28
Tu tao Queue chuc nang giong voi ArrayBlockingQueue
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package MyQueue;
import java.util.LinkedList;
import java.util.Queue;
@huantt
huantt / Main
Last active June 26, 2016 13:43
Dùng comparator sắp xếp Object theo thuộc tính
//Class Main
public class Test {
public static void main(String[] args) {
Nguoi n1 = new Nguoi("A");
Nguoi n2 = new Nguoi("C");
Nguoi n3 = new Nguoi("B");
Nguoi[] n = new Nguoi[3];
n[0] = n1;
n[1] = n2;
n[2] = n3;
@huantt
huantt / DowloadFile
Created July 3, 2016 14:22
Download file sử dụng stream
package com.phongbm.filemanager;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
package com.huantt.downloader;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
/**
* Created by Huan on 7/5/2016.
*/
@huantt
huantt / DownloadManager.java
Last active July 6, 2016 18:17
Download File using MutilThread in java. Mấu chốt là dùng thằng conn.setRequestProperty("Range", "bytes=" + byteRange)
package com.huantt.downloader;
import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@huantt
huantt / Coord.java
Last active July 8, 2016 03:36
Xử lý json từ api openWeatherMap để lấy thông tin thời tiết
package com.huantt;
/**
* Created by Huan on 7/8/2016.
*/
public class Coord {
float lon;
float lat;
public Coord(float lon, float lat) {
@huantt
huantt / test-php-basic-auth.php
Created January 31, 2018 15:54 — forked from rchrd2/test-php-basic-auth.php
PHP basic auth example
<?php
function require_auth() {
$AUTH_USER = 'admin';
$AUTH_PASS = 'admin';
header('Cache-Control: no-cache, must-revalidate, max-age=0');
$has_supplied_credentials = !(empty($_SERVER['PHP_AUTH_USER']) && empty($_SERVER['PHP_AUTH_PW']));
$is_not_authenticated = (
!$has_supplied_credentials ||
$_SERVER['PHP_AUTH_USER'] != $AUTH_USER ||
$_SERVER['PHP_AUTH_PW'] != $AUTH_PASS
package x10adflex.growthhacking.common
import java.text.Normalizer
import java.util.regex.Pattern
/**
* @author huantt on 2018-12-27
*/
class AccentRemover {
@huantt
huantt / nginxproxy.md
Created January 12, 2019 16:09 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers