Skip to content

Instantly share code, notes, and snippets.

View versae's full-sized avatar

Javier de la Rosa versae

View GitHub Profile
#/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
try:
import day2
except ImportError:
import dia2 as day2
class TestCase(unittest.TestCase):
@versae
versae / query_grammar.py
Last active December 15, 2015 14:29
Playing with Parsley to generate grammars on the fly to parse graph queries in a subset of Natural Language. The resulting structure can be transformed into Cypher or Gremlin with no much effort.
import parsley
from pprint import pprint
class Types(dict):
def __init__(self, *args, **kwargs):
super(Types, self).__init__(*args, **kwargs)
self.types = dict()
@versae
versae / is_vampire.py
Created November 8, 2012 07:09
Function is_vampire for CS2110
def is_vampire(row):
"""
Decides if the element given by row is a vampire or not
Analyzing the box plots, we see that the first and second columns,
height(cm) and weight(kg), don't give us much information.
However, the third, 4th, 5th and 6th, stake aversion, garlic aversion,
reflectance, and shiny, provide decissive information.
:param rom: A vector with measures
:return: A probability of being a vampier, between 0 and 1
@versae
versae / README.md
Created November 4, 2012 15:20
Global Profiling for Django using `hotshot`, including the result as HTML comments, even in XML and JSON responses.

Adapted from this: http://www.no-ack.org/2010/12/yet-another-profiling-middleware-for.html Settings:

  • PROFILE_MIDDLEWARE_SORT: A list of criteria according to which the profiler stats will be sorted. Equivalent to Stats.sort_stats.
  • PROFILE_MIDDLEWARE_RESTRICTIONS: A list of restrictions used to limit the profiler stats. Each restriction is either an integer (to select a count of lines) or a decimal fraction between 0.0 and 1.0 inclusive (to select a percentage of lines), or a regular expression (to pattern match the standard name that is printed). Equivalent to the arguments passed to Stats.print_stats.
  • PROFILE_MIDDLEWARE_STRIP_DIRS: If set to True, removes all leading path information from filenames in the profiler stats. Equivalent to Stats.strip_dirs.
  • PROFILE_MIDDLEWARE_JSON: Enabl
@versae
versae / neighbors.py
Created October 21, 2012 00:18
Neighbors function : problematic
def find_neighbors(n, v, visited=set()):
"""
Finds a node's neighbors to n degrees of seperation.
Param n: degrees of seperation. n > 1
v: node id
Return: a list of neighbors to the nth degree with no duplicates or 'NoneType'
"""
neighbors = set(v.neighbors)
@versae
versae / gist:3908447
Created October 17, 2012 21:42
Return the nobmre of nodes for Gython scripting in Gephi
def nodes_length():
return len(g.nodes)
@versae
versae / traversals.py
Created February 26, 2012 16:32 — forked from theladyjaye/traversals.py
Neo4j REST Traversals Approximating embedded syntax for https://github.com/versae/neo4j-rest-client/
# http://docs.neo4j.org/chunked/snapshot/rest-api-traverse.html#rest-api-traversal-returning-nodes-below-a-certain-depth
try:
import simplejson as json
except ImportError:
import json
from neo4jrestclient import client
from neo4jrestclient.request import Request
from neo4jrestclient.request import NotFoundError
@versae
versae / fiber_image_signal.py
Created February 14, 2012 00:42
Signal to resize uploaded Fiber images as new thumbnailed images
from os import path
from StringIO import StringIO
from PIL import Image as PILImage
from django.core.files.base import ContentFile
from django.db.models.signals import post_save
from django.dispatch import receiver
from fiber.models import Image
@versae
versae / projectenv.conf
Last active September 30, 2015 05:48
Script to setup an account for cloned template virtual machines with Nginx and uWsgi
server {
listen 80;
#server_name yourdomain.com;
access_log /home/template/log/access.log;
error_log /home/template/log/error.log;
location /static/admin {
alias /home/template/.virtualenvs/projectenv/lib/python2.7/site-packages/django/contrib/admin/media/;
}
location /static {
@versae
versae / setup.sh
Created January 31, 2012 00:20
Setup script for virtual machines templates
#!/bin/bash
# Script to add a user to Linux system
# -------------------------------------------------------------------------
read -p "Enter username: " username
read -s -p "Enter password: " password
echo ""
sudo egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$username exists!"
exit 1