Skip to content

Instantly share code, notes, and snippets.

View aanastasiou's full-sized avatar

Athanasios Anastasiou aanastasiou

View GitHub Profile
@aanastasiou
aanastasiou / flask_deform_simpleSort.py
Created May 11, 2012 12:21
Using Pylon's Deform with Flask
"""A very simple example to show what is required to get the excellent deform module from the Pylon's project to work with Flask.
DeForm is a Pylon's module capable of automatically creating HTML forms that conform to a schema of classes defined in Python through the Colander module. The transformation between Schema<-->Form data is handled by another module called Peppercorn. More information about how these three modules work together can be found at: http://docs.pylonsproject.org/projects/deform/en/latest/?awesome
Although DeForm is a Pylon's project, it can also operate as a stand-alone module. This Gist contains all the necessary changes to objects provided by Flask so that DeForm can serialize and deserialize data posted through a Flask.Request.
The basic thing that this gist is trying to demonstrate is how to derive from a Flask.Request object in order to change the data type of the Flask.Request.form object that stores the data posted by the client to the server. By default, Flask uses a MultiDict i
@aanastasiou
aanastasiou / README.MD
Created July 28, 2013 18:32
Generate a Cypher query to store a Python Networkx directed graph

Exporting a Networkx graph as a Cypher query

This little project defines a function that can be used to construct a Cypher query which when executed against a Neo4j database server will store the graph to the server.

Background

  • A Graph is an abstract mathematical model composed of Nodes connected through Edges that can be used to describe complex systems composed of a set of parts (corresponding to nodes) and their connections (corresponding to edges).
  • Examples of graphs are road networks (junctions connected via roads), electronic circuit networks (components and their connections) and others
  • Networkx is an excellent Python module for manipulating such Graph objects of any kind.
  • Neo4j is a graph database. It uses the Graph as a data model to store such objects to a data store.
@aanastasiou
aanastasiou / contract_edges.py
Last active March 26, 2024 17:18 — forked from Zulko/nx_merge_nodes.py
Networkx Edge Contraction
#Edge contraction as per http://en.wikipedia.org/wiki/Edge_contraction
def contract_edges(G,nodes, new_node, attr_dict=None, **attr):
'''Contracts the edges of the nodes in the set "nodes" '''
#Add the node with its attributes
G.add_node(new_node, attr_dict, **attr)
#Create the set of the edges that are to be contracted
cntr_edge_set = G.edges(nodes, data = True)
#Add edges from new_node to all target nodes in the set of edges that are to be contracted
#Possibly also checking that edge attributes are preserved and not overwritten,
@aanastasiou
aanastasiou / main.py
Created July 29, 2015 10:15
Use pynq to query graph data from networkx.
#@author:Athanasios Anastasiou
#@date: Wed Jul 29 10:44:08 2015
import networkx #Graph module
import pynq #LINQ for Python module
from matplotlib import pyplot as plt #Fancy drawing stuff
import random #The standard oamdrn module
from collections import namedtuple #A named tuple to make pynq think it's going over a collection of classes.
#SETUP THE SCHEMA
#Notice the notion of references back to the original schema inspired by the property graph model (https://github.com/tinkerpop/blueprints/wiki/Property-Graph-Model)
@aanastasiou
aanastasiou / getEnvelopeModels.py
Last active March 18, 2022 18:07
Detect the upper and lower "envelopes" of a time series.
'''Athanasios Anastasiou 13/12/2015
A simple function to get the "upper" and "lower" values envelope
from a time series'''
from numpy import array, sign, zeros
from scipy.interpolate import interp1d
from matplotlib.pyplot import plot,show,hold,grid, xlabel, ylabel, title, figure
def getEnvelopeModels(aTimeSeries, rejectCloserThan = 0):
'''Fits models to the upper and lower envelope peaks and troughs.
@aanastasiou
aanastasiou / main.py
Created June 19, 2017 20:49
bibtex to JSONResume conversion
'''Athanasios Anastasiou June 2017
Reads a bib file and exports the 'publications' entry to be attached to some jsonResume file'''
import pybtex.database
import sys
import json
def formatEntry(anEntry):
'''Returns a dictionary with the required entries by the jsonresume schema'''
pubTitle = anEntry.fields['journal'] if 'journal' in anEntry.fields.keys() else anEntry.fields['booktitle'] if 'booktitle' in anEntry.fields.keys() else "";
return {"name":anEntry.fields['title'].replace("{","").replace("}","").replace("\&amp;","\&"),
@aanastasiou
aanastasiou / README.md
Created February 13, 2018 11:24
Create a "vectors only" Spacy model
  1. Use GloVe to produce vector data

    • This will produce the vectors.txt and vectors.bin data
  2. Use main.py to produce a new "vectors only" spacy model by using en_core_web_md as the base

  3. Once this finishes, run spacy package inDir outDir with inDir, outDir set to ModelInputDir, WhateverOutputDir respectively.

    • This step will create a package that can be readily used by spacy.
  4. From within WhateverOutputDir, execute pip install -e ./ to install the model as a module.

@aanastasiou
aanastasiou / appmodels.py
Last active October 25, 2023 13:21
Using neomodel with Flask
import neomodel
class Item(neomodel.StructuredNode):
__primarykey__ = "name"
name = neomodel.StringProperty(unique_index=True)
@aanastasiou
aanastasiou / __init__.py
Last active January 9, 2019 10:05
Short term solution to using Neomodel 3.3.0 with Flask.
"""
This is a module that is supposed to be describing the whole datamodel of an application.
NOTE: The directory structure that is implied here is:
src/
app_models/
__init__.py (THIS FILE)
main.py
"""
@aanastasiou
aanastasiou / indicative_output.md
Last active November 1, 2019 21:31
Convex polygon smoothing via DFT

Examples

Square

Smoothed Square

Freeform

Smoothed Freeform