Skip to content

Instantly share code, notes, and snippets.

@octaflop
octaflop / blog.js
Last active December 14, 2015 02:49
working example of hand-written async on a redis server
exports.list = function(req, cb) {
client.get(MODELSET_ID + ":blog:entries", function(err, blogLen) {
if (err) { console.log(err); }
var retList = [];
function done (retBlog) {
console.log("pushing id: " + retBlog.metadata._id);
retList.push(retBlog);
blogLen--;
if (blogLen <= 0) { cb(retList); }
@octaflop
octaflop / app.js
Created February 19, 2013 23:20
A lot of room for improvement, but this is the engine powering: https://legionofevil.org and it uses nginx + websockets + ssl without any patches! here's the nginx conf: https://gist.github.com/octaflop/4991052
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require("socket.io").listen(server);
var redis = require('redis'),
db = redis.createClient();
// Socket.io configuration
io.configure(function () {
io.enable('browser client etag');
# The upstream server doesn't need a prefix! no need for wss:// or http:// because nginx will upgrade to http1.1 in the config below
upstream yeomanserver {
server localhost:3000;
}
server {
listen 443;
server_name legionofevil.org;
root html;
@octaflop
octaflop / blog.js
Last active December 13, 2015 23:18
exports.get = function(req, cb) {
if (req.params.id) {
var id = req.params.id;
var ret = {};
var len = 4; // The number of calls we'll be making
function callback() {
--len || cb(ret);
}
client.hgetall(MODELSET_ID + ":blog:entry:" + id, function(err, reply) {
@octaflop
octaflop / models_blog.js
Last active December 13, 2015 22:08
Wrapping my head around async in expressjs
var redis = require("redis"),
client = redis.createClient();
var MODELSET_ID = "cogblog.v.0.0.0_"
function pad(n) {
return n<10 ? '0'+n : n
}
function add_blog_entry(id) {
@octaflop
octaflop / beautiful_trees.py
Last active December 12, 2015 05:08
beautiful_trees.py fetchs Vancouver's open tree data and downloads all varieties of trees it can from wikipedia infoboxes.
# coding: utf-8
import urllib2
from urllib2 import HTTPError
from StringIO import StringIO as stio
from bs4 import BeautifulSoup
import zipfile
import pprint
import simplejson
def robot():
@octaflop
octaflop / joyhikedbtest.py
Created November 10, 2012 01:44
flask integration testing with postgresql and sqlalchemy
import joyhikeserve as j
from joyhikeserve.db.testdatabase import init_db, drop_db
import unittest
import fixtures
from BeautifulSoup import BeautifulSoup as bs
appurl = "/api/%s"
header = { "content-type": "application/json" }
@octaflop
octaflop / dbtests.py
Created November 10, 2012 01:38
Flask sqlalchemy declarative db configuration
import someapp as j
from someapp.db.database import init_db, drop_db
import unittest
import fixtures
from BeautifulSoup import BeautifulSoup as bs
appurl = "/api/%s"
header = { "content-type": "application/json" }
@octaflop
octaflop / fail.sh
Created November 8, 2012 20:30
Flask-Login Usage Testing
======================================================================
FAIL: test_login (__main__.JoyHikeDBCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "dbtests.py", line 68, in test_login
assert "logged in as" in rv.data
AssertionError
======================================================================
FAIL: test_logout (__main__.JoyHikeDBCase)
@octaflop
octaflop / s2prod.markdown
Created May 26, 2012 18:05
Some notes about going from services to product

Don't do hourly billing!