This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_mongo(db=[]): | |
""" | |
This function employs a good ol` gotcha with using mutable objects as a default value for an argument to cache | |
the database object. | |
If the `db` arg is an empty list, populate it with the object. | |
Every other call to this function will skip the if clause and return the cached `db` object. | |
Win. | |
""" | |
if db == []: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_login_form(): | |
""" | |
Generates a traditional login form, bootstrap-styled. | |
DEV USE: Look at this function to figure out how to generate | |
forms | |
:return form_skeleton_obj: | |
""" | |
form = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from email.mime.multipart import MIMEMultipart | |
from email.mime.text import MIMEText | |
import smtplib | |
from threading import Thread | |
from base_cfg import STMP_SERVER_HOST, SMTP_PASSWD, SMTP_USERNAME, FROM_EMAIL_NAME, FROM_EMAIL_ADDR | |
class Mail: | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) Join the Javelin Google+ community at https://plus.google.com/communities/106470412179443137104 | |
2) Go to https://play.google.com/apps/testing/com.nubelacorp.javelin and accept being a beta tester | |
3) Wait about an hour, and check Google Play for a new update |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import random | |
from BeautifulSoup import BeautifulSoup | |
from base.util import generate_uuid | |
from homepage.app import homepage_db | |
from homepage.model import UnsplashImage | |
from homepage_cfg import EXPIRE_UNSPLASH_DAYS, UNSPLASH_IMAGE_DIR | |
import os | |
import requests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from BeautifulSoup import BeautifulSoup | |
import requests | |
FILE_NAME = "result.txt" | |
BASE_URL = "http://www.propertyguru.com.sg/" | |
URL = "http://www.propertyguru.com.sg/singapore-property-listing/property-for-rent/%d?property_type=H" \ | |
"&property_type_code[]=HDB&minprice=1500&maxprice=2500&minsize=1000&distance=0.5¢er_lat=1" \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import randint | |
import numpy as np | |
from pylearn2.datasets.dense_design_matrix import DenseDesignMatrix | |
from pylearn2.models import mlp | |
from pylearn2.termination_criteria import EpochCounter | |
from pylearn2.training_algorithms import sgd | |
import theano | |
def gen_xor_data(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This trains a simple 2-layered MLP for classifying handwritten digits (MNIST dataset) | |
For this script to work, you need to have a ./mnist folder that contains the MNIST dataset. | |
The dataset can be downloaded using the script in the following pylearn2 folder: | |
<workspace>/pylearn2/pylearn2/scripts/datasets/download_mnist.py | |
After training the model (neural network containing layers), it will save trained model to disk. | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import struct | |
import numpy as np | |
from pylearn2.utils import serial | |
import theano | |
def read_mnist_images(): | |
path = "mnist/" | |
label_path = path + 't10k-images-idx3-ubyte' | |
dtype = 'float32' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sign requests using: | |
// https://tools.ietf.org/html/draft-cavage-http-signatures-09 | |
import hmacSHA256 from 'crypto-js/hmac-sha256'; | |
import sha256 from 'crypto-js/sha256'; | |
import Base64 from 'crypto-js/enc-base64'; | |
// Signed string be MUST be built from headers in this specific order | |
const SIGNATURE_HEADERS = [ | |
"(request-target)", "host", "accept", "content-type", "x-original-length", |
OlderNewer