Skip to content

Instantly share code, notes, and snippets.

@lovevn
lovevn / simple_gridfs_server.py
Created December 9, 2012 18:42 — forked from artisonian/simple_gridfs_server.py
A simple GridFS server built with Flask
from flask import Flask, request, redirect, url_for, make_response, abort
from werkzeug import secure_filename
from pymongo import MongoClient
from bson.objectid import ObjectId
from gridfs import GridFS
from gridfs.errors import NoFile
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
DB = MongoClient().pdfs
FS = GridFS(DB)
@lovevn
lovevn / our_setup_script.js
Created December 11, 2012 03:48 — forked from shussekaido/our_setup_script.js
MongoDB M102 week6 file
db = db.getSisterDB("config");
var mongosConn = db; // assume we connected to a mongos to get going
var res = null;
function check() {
printjson(res);
if( !res || !res.ok ) {
throw "check(): not ok, stopping";
@lovevn
lovevn / slugify
Created December 14, 2012 08:30
Generating Slugs for Vietnamese language
# this gist get from
#http://flask.pocoo.org/snippets/5/
import re
from unidecode import unidecode
_punct_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+')
def slugify(text, delim=u'-'):
"""Generates an ASCII-only slug."""
<!DOCTYPE html>
<html>
<head>
<title>Vietjet Air Crawlee</title>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js'></script>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.1.1/css/bootstrap-combined.min.css" rel="stylesheet">
</head>
<body>
<script>
window.onload = function() {
@lovevn
lovevn / gist:4324998
Created December 18, 2012 04:24
Good deal crawler Get from http://pastebin.com/QNFyu4sa
# -*- coding: utf-8 -*-
# Competitor Intelligence Agent
# License: Creative Commons CC BY-NC-SA
#
# By Michael Gradek, a proud Udacian
# Twitter: @MichaelGradek
#
# Competitor Intelligence Agent aims to collect and display a report with relevant information about Groupon.es, one of the largest Collective Buying sites in Spain (... and in the world!)
# For more information about Collective Buying please refer to: http://en.wikipedia.org/wiki/Group_buying
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" """
import json
from urllib2 import urlopen
from lxml.html import document_fromstring
from lxml.cssselect import CSSSelector as cs

Using Dropbox to Share Git Repositories

First, create a Git subfolder inside your Dropbox folder. Then you can share the individual projects inside that folder with whomever you want (or just use it for instant offsite backups).

From inside a Git project:

git clone --bare . ~/Dropbox/Git/gitproject.git
git remote add dropbox ~/Dropbox/Git/gitproject.git

When you're ready to push:

@lovevn
lovevn / crawler.py
Last active December 18, 2015 22:38 — forked from jmoiron/crawler.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Simple async crawler/callback queue based on gevent."""
import traceback
import logging
import httplib2
import gevent
@lovevn
lovevn / gist:7306704
Last active December 27, 2015 09:49
Python MVC Example
import sqlite3
class MVCModel:
def request(self, id):
# Would query database...
conn = sqlite3.connect('querydb')
c = conn.cursor()
results = c.execute('''select name from data where id = %d''' %id)
conn.commit()
from PIL import Image
import scipy
import scipy.cluster
from pprint import pprint
image = Image.open('logo_newsblur_512.png')
NUM_CLUSTERS = 15
# Convert image into array of values for each point.
ar = scipy.misc.fromimage(image)