Konfigurasi NCSA Authentication pada Proxy Squid

htpasswd -c /etc/squid3/users andreas
chmod o+r /etc/squid3/users
mousepad /etc/squid3/squid.conf
auth_param basic program /usr/lib/squid3/ncsa_auth /etc/squid3/users
auth_param basic children 5
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 2 hours
auth_param basic casesensitive off

acl ncsa_users proxy_auth REQUIRED
acl manager proto cache_object
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1

acl SSL_ports port 443
acl Safe_ports port 80		# http
acl Safe_ports port 21		# ftp
acl Safe_ports port 443		# https
acl Safe_ports port 70		# gopher
acl Safe_ports port 210		# wais
acl Safe_ports port 1025-65535	# unregistered ports
acl Safe_ports port 280		# http-mgmt
acl Safe_ports port 488		# gss-http
acl Safe_ports port 591		# filemaker
acl Safe_ports port 777		# multiling http
acl CONNECT method CONNECT

http_access allow ncsa_users
http_access allow manager localhost
http_access deny manager

http_access deny !Safe_ports

http_access deny CONNECT !SSL_ports

http_access allow localhost

http_access deny all

http_port 192.168.137.128:3128

coredump_dir /var/spool/squid3

refresh_pattern ^ftp:		1440	20%	10080
refresh_pattern ^gopher:	1440	0%	1440
refresh_pattern -i (/cgi-bin/|\?) 0	0%	0
refresh_pattern .		0	20%	4320
# service squid3 restart
Advertisements

SQL: Menggunakan Subquery

SELECT ename, hiredate
FROM emp
WHERE LOWER(ename) != 'blake'
AND deptno = (SELECT deptno FROM emp WHERE LOWER(ename) = 'blake');
SELECT empno, ename
FROM emp
WHERE sal > (SELECT AVG(sal) FROM emp) ORDER BY sal DESC;
SELECT empno, ename
FROM emp
WHERE deptno IN (SELECT deptno FROM emp WHERE ename LIKE '%T%');
SELECT ename, sal
FROM emp
WHERE empno IN (SELECT e.empno FROM emp e, emp m WHERE e.mgr=m.empno AND
LOWER(m.ename) LIKE 'king');
SELECT deptno, ename, job
FROM emp WHERE deptno = (SELECT deptno FROM dept WHERE LOWER(dname) = 'sales');
SELECT empno, ename
FROM emp
WHERE deptno IN (SELECT deptno FROM emp WHERE ename LIKE '%T%') AND sal >
(SELECT AVG(sal) FROM emp);
Posted in SQL

SQL: Menampilakan Data dari Banyak Tabel

SELECT emp.ename, dept.deptno, dept.dname
FROM emp, dept
WHERE emp.deptno = dept.deptno;
SELECT DISTINCT emp.job, dept.loc
FROM emp, dept
WHERE emp.deptno = dept.deptno AND dept.deptno = 30;
SELECT emp.ename, dept.dname, dept.loc
FROM emp, dept
WHERE emp.deptno = dept.deptno AND emp.comm IS NOT NULL;
SELECT emp.ename, dept.dname
FROM emp, dept
WHERE emp.deptno = dept.deptno AND emp.ename LIKE '%A%';
SELECT emp.ename, emp.job, dept.deptno, dept.dname
FROM emp, dept
WHERE emp.deptno = dept.deptno AND LOWER(dept.loc) = 'dallas';
SELECT e.empno, e.ename AS pegawai, m.empno, m.ename AS manager
FROM emp e, emp m
WHERE e.mgr = m.empno;
Posted in SQL

Java: Membaca File CSV menggunakan OpenCSV

Berikut cara untuk membaca file CSV dengan menggunakan library OpenCSV.

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.List;
import com.opencsv.CSVReader;

public class ReaderCSV3  {
  public static void main(String[] args) throws Exception {
    String file = "src/data.csv";
    String[][] csv = readCSV(file);
    double[][] data = getDouble(csv);

    for (int i = 0; i < data.length; i++) {
      for (int j = 0; j < data[0].length; j++) {
        System.out.print(data[i][j] + "\t");
      }
      System.out.println("");
    }
  }

  public static String[][] readCSV(String fileName) throws Exception {
    try (CSVReader reader = new CSVReader(new BufferedReader(
      new FileReader(fileName)));) {

      List<String[]> lines = reader.readAll();
      String[][] data = new String[lines.size()][];
      data = lines.toArray(new String[lines.size()][]);

      return data;
    }
  }

  public static double[][] getDouble(String[][] data) {
    double[][] dataDouble = new double[data.length][data[0].length];

    for (int i = 0; i < data.length; i++) {
      for (int j = 0; j < data[0].length; j++) {
        dataDouble[i][j] = Double.parseDouble(data[i][j]);
      }
    }

    return dataDouble;
  }
}

Python: Membuat Model Klasifikasi Support Vector Machines menggunakan Scikit-learn

Berikut merupakan teknik untuk membuat model prediksi menggunakan teknik Support Vector Machines.

from sklearn import datasets
from sklearn import svm
from sklearn.cross_validation import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.metrics import classification_report
import _pickle as pickle
import requests, json

iris = datasets.load_iris()
X = iris.data
y = iris.target

X_train, X_test, y_train, y_test = train_test_split(X, y)

clf = svm.SVC()
clf.fit(iris.data, iris.target).predict(iris.data)

print("Accuracy = %0.2f" % accuracy_score(y_test, clf.predict(X_test)))
print(classification_report(y_test, clf.predict(X_test)))

pickle.dump(clf, open("iris_svm.pkl", "wb"))
my_support_vector_machines = pickle.load(open("iris_svm.pkl", "rb"))

print("Accuracy = %0.2f" % accuracy_score(y_test, my_support_vector_machines.predict(X_test)))
print(classification_report(y_test, my_support_vector_machines.predict(X_test)))

Python: Membuat Model Klasifikasi Gaussian Naïve Bayes menggunakan Scikit-learn

Berikut merupakan teknik untuk membuat model prediksi menggunakan teknik Gaussian Naïve Bayes.

from sklearn import datasets
from sklearn.naive_bayes import GaussianNB
from sklearn.cross_validation import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.metrics import classification_report
import _pickle as pickle
import requests, json

iris = datasets.load_iris()
X = iris.data
y = iris.target

X_train, X_test, y_train, y_test = train_test_split(X, y)

gnb = GaussianNB()
gnb.fit(iris.data, iris.target).predict(iris.data)

print("Accuracy = %0.2f" % accuracy_score(y_test, gnb.predict(X_test)))
print(classification_report(y_test, gnb.predict(X_test)))

pickle.dump(gnb, open("iris_gnb.pkl", "wb"))
my_gaussian_naive_bayes = pickle.load(open("iris_gnb.pkl", "rb"))

print("Accuracy = %0.2f" % accuracy_score(y_test, my_gaussian_naive_bayes.predict(X_test)))
print(classification_report(y_test, my_gaussian_naive_bayes.predict(X_test)))