Skip to content

Instantly share code, notes, and snippets.

View faisal-w's full-sized avatar

Faisal Wirakusuma faisal-w

  • Jakarta East Customs Software
  • Jakarta, Indonesia
View GitHub Profile
@faisal-w
faisal-w / MyLogisticRegression.m
Last active August 29, 2015 14:08
Implementation of Logistic Regression using Matlab
% MyLogisticRegression
%
% by Faisal Wirakusuma
% Implementation of Logistic Regression, inspired by lecture materials from Andrew Ng
% http://openclassroom.stanford.edu/MainFolder/DocumentPage.php?course=MachineLearning&doc=exercises/ex4/ex4.html
%
classdef MyLogisticRegression < handle
properties
@faisal-w
faisal-w / MyKMeansClusterer.java
Created October 13, 2014 13:39
SimpleKMeans cluster classification example using Weka library.
import weka.core.Instance;
import weka.core.Instances;
import weka.core.converters.ArffLoader;
import weka.clusterers.SimpleKMeans;
import weka.clusterers.ClusterEvaluation;
import java.io.File;
import java.io.FileWriter;
/**
#!/usr/bin/env python
"""Simple HTTP Server With Upload.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
"""
"""
This example requires the body-streaming tornado fork at https://github.com/nephics/tornado.
Refer to http://groups.google.com/group/python-tornado/browse_thread/thread/791c67cb86c2dea2.
Supports uploading an unlimited number/size of files in a single
PUT multipart/form-data request. Each file is processed as the stream
finds the part in the form data.
==USAGE==
@faisal-w
faisal-w / tornado_upload_1.py
Last active July 22, 2021 02:37
A working example of how to upload file with Tornado Python.
import tornado.httpserver, tornado.ioloop, tornado.options, tornado.web, os.path, random, string
#Actually we didn't need this class
class Application(tornado.web.Application):
def __init__(self):
handlers = [
(r"/", IndexHandler),
(r"/upload", UploadHandler)
]
tornado.web.Application.__init__(self, handlers)
@faisal-w
faisal-w / upload_form.html
Created May 7, 2014 06:10
HTML Upload form for Tornado upload example.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Tornado Upload Application</title>
</head>
<body>
<p><h1>Tornado Upload App</h1></p>
<form enctype="multipart/form-data" action="/upload" method="post">
File: <input type="file" name="file1" />
@faisal-w
faisal-w / python_upload_1.py
Created May 4, 2014 07:09
Example how to upload file to server using python, accept http multipart request. Work if uploaded file is less than 1.5 mb.
import requests
def upload_file_to_gcs():
url = 'http://127.0.0.1:8500/save-data-to-gcs/'
f = {'file': ('Product_Master.csv', open('C:/Projects/bf/Product_Master.csv', 'rb')), 'file_name': 'Product_Master.csv'}
r = requests.post(url, files=f)
print r
upload_file_to_gcs()
def save_data_to_gcs(request):
@faisal-w
faisal-w / json_read.py
Created April 24, 2014 02:20
Code how to read json file
import os
import json
json_data = open("trayek_data.json").read()
print json_data
data = json_load(json_data)
json_data = open("trayek_data.json")
data = json.load(json_data)
jsondata = json_data.read()
jsondata
json_data = open("trayek_data.json")
@faisal-w
faisal-w / example_jquery_rest_call.js
Created February 21, 2014 02:05
Another example simple of JQuery REST call
$("#myButton").click(function() {
var artistURL = "http://development.dlwelch.com/examples/restservice/JazzArtists.svc/json/Shirley";
var returnData = "";
$.ajax({
type: "GET",
dataType: "json",
async: true,
url: artistURL,
error: function(request, status, error) { alert(request.responseText) },
success: function(data) {
@faisal-w
faisal-w / how_to_encrypt_jquery_service_call.js
Created February 21, 2014 01:38
How to encrypt javascript web service call with JQuery
$.ajax( {
url : '/model/user.json',
dataType : 'json',
beforeSend : function(xhr) {
var bytes = Crypto.charenc.Binary.stringToBytes(username + ":" + password);
var base64 = Crypto.util.bytesToBase64(bytes);
xhr.setRequestHeader("Authorization", "Basic " + base64);
},
error : function(xhr, ajaxOptions, thrownError) {
reset();