Skip to content

Instantly share code, notes, and snippets.

@nonZero
nonZero / index.js
Created June 7, 2016 15:16
simple jquery manipulations
console.log("start");
$("li").click(function () {
console.log("click event start");
$(this).slideUp(1000).css('background', 'orange');
$("<li>1234</li>").appendTo($("ul:last"));
console.log("click event end");
});
console.log("end");
@nonZero
nonZero / order.html
Created June 2, 2016 07:59
simple js order form
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<ul id="dishes">
<li data-id="123">asdsadsadada</li>
@nonZero
nonZero / mongo_demo.py
Last active May 24, 2016 08:28
insert many posts as documents and query by publish date
import random
import datetime
import collections
import pymongo
client = pymongo.MongoClient()
db = client.get_database('udi123')
@nonZero
nonZero / puzzle.py
Created May 23, 2016 09:27
pillow + argparse example
#!/usr/bin/env python3
import random
from PIL import Image
def main(source, target, cols, rows):
im = Image.open(source)
print("Original image size: {}x{}".format(*im.size))
w, h = im.size
from pprint import pprint
import pymongo
client = pymongo.MongoClient()
db = client.get_database('socialagg')
# db = client['socialagg']
pages = db.get_collection('pages')
from pprint import pprint
import pymongo
client = pymongo.MongoClient()
db = client.get_database('socialagg')
# db = client['socialagg']
pages = db.get_collection('pages')
@nonZero
nonZero / connect.py
Last active May 22, 2016 13:18
get access token
import requests
import secrets
URL = "https://graph.facebook.com/oauth/access_token"
r = requests.get(URL, {
'client_id': secrets.APP_ID,
'client_secret': secrets.APP_SECRET,
'grant_type': 'client_credentials',
@nonZero
nonZero / server.py
Created May 21, 2016 06:51
Basic bottle server with debug and reloading
from bottle import route, run, template
@route('/hello/<name>')
def index(name):
return template('<b>Hello {{name}}</b>!', name=name)
if __name__ == "__main__":
run(debug=True, reloader=True)
# http://wsgi.tutorial.codepoint.net/environment-dictionary
# =================================================================
# THE WSGI APPLICATION
# =================================================================
def simple_app(environ, start_response):
status = '200 OK'
response_headers = [
('Content-type', 'text/plain'),
@nonZero
nonZero / views.py
Created March 1, 2016 10:49
read markdown with metadata from one file with multiple items
SEP_RE = re.compile(r'\n+-{5,}\n+')
def read_file(name):
with (pathlib.Path(__file__).parent / 'content' / '{}.md'.format(
name)).open() as f:
return f.read()
def get_item(txt):
md = markdown.Markdown(extensions=['markdown.extensions.meta'])
html = md.convert(txt)