Skip to content

Instantly share code, notes, and snippets.

View drhanlau's full-sized avatar
💭
Working on AI projects

Dr. Lau Cher Han drhanlau

💭
Working on AI projects
View GitHub Profile
<div class="form-group" ng-class="{ 'has-error' : productForm.product_name.$invalid && productForm.product_name.$dirty }">
<label class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" name="product_name" ng-model="product.name" class="form-control" placeholder="Product Name Here" required ng-minlength=5 ng-maxlength=60>
<div class="error" ng-show="productForm.product_name.$dirty && productForm.product_name.$invalid">
<p class="help-block" ng-show="productForm.product_name.$error.required">Please input a product name</p>
<p class="help-block" ng-show="productForm.product_name.$error.minlength">The product name is required to be at least 5 characters</p>
<p class="help-block" ng-show="productForm.product_name.$error.maxlength">The product name cannot be longer than 60 characters</p>
</div>
</div>
@drhanlau
drhanlau / tweet.py
Created May 11, 2016 07:13
Twitter Streaming Test
from __future__ import absolute_import, print_function
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
import json
import sys,os,time
print(sys.version)
<!DOCTYPE html>
<html ng-app="ecommerceApp">
<head lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>E-commerce System</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<style>
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>MyAppName</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<style>
require('mocha-generators').install();
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: true })
nightmare
.goto('http://yahoo.com')
.type('input[title="Search"]', 'github nightmare')
.click('#UHSearchWeb')
.wait('#main')
.evaluate(function () {
from ..location import Location
from nose2.tools.params import params
from datetime import datetime
# def test_temperature_of_a_new_location_class_should_be_None():
# location = Location("PEN")
# assert location.temperature is None
def fibonacci(n):
assert(n >= 0), 'n must be >= 0'
return n if n in (0, 1) else fibonacci(n-1) + fibonacci(n-2)
if __name__ == '__main__':
from timeit import Timer
t = Timer('fibonacci(8)', 'from __main__ import fibonacci')
print(t.timeit())
@drhanlau
drhanlau / adapter.py
Created March 7, 2016 00:59
Adapter Pattern
class Adapter:
def __init__(self, obj, adapted_methods):
self.obj = obj
self.__dict__.update(adapted_methods)
def __str__(self):
return str(self.obj)
@drhanlau
drhanlau / main.py
Last active May 27, 2018 18:17
Observer
if __name__ == "__main__":
stock_watcher = Observable()
american_observer = AmericanStockMarket()
stock_watcher.register(american_observer)
stock_watcher.publish('KLSE Market Update', price='+0.5')
@drhanlau
drhanlau / age_validator.py
Created March 4, 2016 03:10
Code Snippets for Abstract Factory
def validate_age(name):
try:
age = raw_input('Welcome {}. How old are you? '.format(name))
age = int(age)
except ValueError as err:
print("Age {} is invalid, please try again...".format(age))
return (False, age)
return (True, age)