Skip to content

Instantly share code, notes, and snippets.

@nagyv
nagyv / file1.js
Created February 11, 2012 14:07
Module definition with Node.JS
(function() {
// Save a reference to the global object.
var root = this;
/* do stuff */
root.public_method = function() {};
}).call(this);
@nagyv
nagyv / app.js
Created February 15, 2012 23:47 — forked from tbranyen/app.js
backbone.js sub routing
/* Pretend app setup stuff is here */
/* Kick off app */
jQuery(function($) {
var Gallery = app.module("gallery");
app.Router = Backbone.Router.extend({
routes: {
"add": "main_add"
@nagyv
nagyv / file1.js
Created March 9, 2012 18:07
Using backbone-valiadtion
var backbone_validation = require('backbone-validation');
backbone_validation(app, '/libs/backbone-validation.js');
// and access the browser side validation with
// <script src="/libs/backbone-validation.js"></script>
@nagyv
nagyv / file1.js
Created March 11, 2012 22:46
Connecting to mongodb using a mongodb:// uri
var Db = require('mongodb').Db;
//...
options.noOpen = true;
myDb = Db.connect(mongouri, options);
// or
options.noOpen = false;
@nagyv
nagyv / file1.js
Created March 17, 2012 16:48
Creating JSON request browser with Tobi
var tobi = require('tobi'),
browser = tobi.createBrowser(8000, "localhost");
json_browser = (function(){
var json_header = {headers:
{
"Accept": "application/json",
"X-Requested-With": "XMLHttpRequest"
}
};
@nagyv
nagyv / mongoose-test.js
Created April 4, 2012 13:37
The simplest Mongoose app to run
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;
var myS = new Schema({
name: {type: String, required: true}
});
var My = mongoose.model('My', myS);
var my = new My({'name': 'bika'});
@nagyv
nagyv / gist:2538496
Created April 29, 2012 07:10
Testing mongoose pre-save with async
var mongoose = require('mongoose'),
async = require('async'),
Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;
var MyS = new Schema({
feeling: String
});
MyS.pre('save', function(done){
async.parallel([
@nagyv
nagyv / fields.py
Created May 22, 2012 10:53
Google Protobuffer field for Django
''' A model field to store and retrieve Google Protocol Buffer objects easily.
Uses the BlobField available on GAE for storage.
Usage:
myfield = ProtobufField(protoclass=MyProtocolClass)
where MyProtocolClass is a protocol descriptor class generated from a .proto file.
The field is supposed to store only the given kind of protocol messages.
@nagyv
nagyv / middleware.py
Created October 29, 2012 09:32
Django facebook connect middleware w/ facepy
import logging
import facepy as facebook
from django.conf import settings
from django.contrib.auth.signals import user_logged_in
from django.db import models
from django.contrib.auth import logout
from django.contrib.auth.models import User
class FBAuthMiddleware(object):
def __init__(self):
@nagyv
nagyv / goaccess.py
Created May 6, 2014 15:37
A python script for downloading and processing Amazon S3 logs using goaccess
#!/bin/python
import os
from boto.s3.connection import S3Connection
import subprocess
from datetime import datetime, date
import argparse
import tempfile
import json
parser = argparse.ArgumentParser(description="Downloads logs from S3, and parses them with goaccess.")