Skip to content

Instantly share code, notes, and snippets.

@easonhan007
easonhan007 / flask_api.py
Last active October 6, 2023 14:15
A simple app of flask json api
from flask import Flask, jsonify, g, request
from sqlite3 import dbapi2 as sqlite3
DATABASE = './db/test.db'
app = Flask(__name__)
def get_db():
db = getattr(g, '_database', None)
if db is None:
db = g._database = sqlite3.connect(DATABASE)
db.row_factory = sqlite3.Row
@easonhan007
easonhan007 / expected_conditions_example.py
Last active December 12, 2019 11:58
python selenium expected_conditions examples
#encoding:utf-8
# example of how to use https://github.com/SeleniumHQ/selenium/blob/master/py/selenium/webdriver/support/expected_conditions.py
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
import unittest
@easonhan007
easonhan007 / queue.js
Created September 4, 2014 09:39
implement queue using js and some examples
function Queue() {
this.dataSource = [];
this.enqueue = enqueue;
this.dequeue = dequeue;
this.front = front;
this.back = back;
this.toString = toString;
this.empty = empty;
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
</head>
import unittest
class StringTestCase(unittest.TestCase):
def setUp(self):
self.test_string = "This is a string"
def testReverse(self):
self.assertEqual("gnirts a si sihT", self.test_string[::-1])
@easonhan007
easonhan007 / bootstrap_blank_template_v3.3.7.html
Created January 29, 2017 09:36
bootstrap blank template v3.3.7
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
@easonhan007
easonhan007 / create_post.py
Created January 25, 2014 03:54
how to test wordpress using python unittest
import unittest
from selenium import webdriver
import time
from time import sleep
class WordPressTestCase(unittest.TestCase):
dr = None
login_url = 'http://localhost/wordpress/wp-login.php'
post_list_url = 'http://localhost/wordpress/wp-admin/edit.php'
@easonhan007
easonhan007 / test_api.py
Created December 28, 2013 08:57
how to use python to test a json based api
import unittest, httplib, urllib, json
class ApiTestCase(unittest.TestCase):
def setUp(self):
self.conn = httplib.HTTPConnection('localhost', 5000)
def tearDown(self):
if self.conn is not None: self.conn.close()
def get(self, path='/'):
@easonhan007
easonhan007 / test_http.py
Created December 28, 2013 08:30
how to use python to send request via get and post
import httplib, json, urllib
# get
conn = httplib.HTTPConnection('localhost', 5000)
conn.request('GET', '/')
r1 = conn.getresponse()
print r1.status, r1.reason
data = r1.read()
print json.loads(data)
@easonhan007
easonhan007 / public_function.rb
Created October 19, 2013 07:23
public_function.rb
#encoding: utf-8
def login(browser, user_name, password)
login_url = 'http://localhost/wordpress/wp-login.php'
browser.goto login_url
browser.text_field(:id, 'user_login').set user_name
browser.text_field(:id, 'user_pass').set password
browser.button(:id, 'wp-submit').click
end