Skip to content

Instantly share code, notes, and snippets.

@wilig
wilig / oai_server.py
Last active December 17, 2015 09:19 — forked from veriojon/oai_server.py
#from lxml import etree
from flask import Flask, request, Response, render_template, abort
from oaipmh import server, metadata
from oai_auth import auth_info, ip_check_init, ip_to_inst, set_auth, get_ip
import logging
import re
import ss_server
def getServer():
@wilig
wilig / asset.py
Created April 10, 2013 17:11
New controllers look like this
@restrict(internal_access=True)
def index(request):
params = request.params
account = request.account
project, asset_group = _find_project_and_asset_group(request.db,
request.matchdict)
res = Asset.search_by_project(account, project, asset_group, params)
if params.get("with_meta", False) == "true":
return extjs.configure_asset_panel(account, project, res)
else:
@wilig
wilig / gist:3940455
Created October 23, 2012 18:14
Python Import Speed Tests
# Wanted to test the penalty for using imports inside functions.
import timeit
def t1():
return 2 * 2
timeit.timeit("t1()", setup="from __main__ import t1")
#> 0.14718103408813477
@wilig
wilig / gist:847903
Created February 28, 2011 19:52 — forked from veriojon/gist:847897
var ExcelSuccessDialog = Ext.extend(Ext.Window, {
constructor: function(config) {
this.importsuccessForm = new Ext.FormPanel({
frame: true,
bodyStyle: 'padding: 10px 10px 0 10px;',
labelWidth: 50,
defaults: { anchor: '95%', allowBlank: false, msgTarget: 'side'},
items: [{
xtype: 'displayfield',
itemID: 'numnew',
this.publishRecordAction = new Ext.Action({
text: 'Publish',
disabled: true,
handler: function() {
if(this.getSelectedRecords().length > 0) {
var params = new Object();
params.asset_ids = this.getSelectedRecords().map(function(r) { return r.id; });
Ext.Ajax.request({
url: Imata.config.asset_publish_url(1, "publish"),
method: 'POST',
@wilig
wilig / gist:674728
Created November 12, 2010 21:35 — forked from veriojon/gist:674700
from sharedshelf.tests import *
from sharedshelf.lib import imatacache
class TestImataCache(TestCase):
def test_adding_value_to_cache(self):
cache = imatacache.ImataCache()
myvalue = 'bar'
key = cache.add(myvalue)
self.assertEqual(myvalue, cache.get(key))
test_init_file = "/".join(__file__.split('/')[:-3])+"/test.ini"
if not os.path.isfile(test_init_file):
print "Expected "+test_init_file+" to be present."
exit(-1)
SetupCommand('setup-app').run([test_init_file])
@classmethod
def create_from_dict(cls, project, profile_id, data_dict, asset_group=None):
"""Takes a dict with field_definition ids mapped to values and returns a new asset"""
asset = Asset(profile_id)
asset.update_from_dict(data_dict)
asset.project = project
# for fd in project.field_definitions:
# if fd.id in data_dict.keys():
# asset.set_field_value(fd, data_dict[fd.id])
return asset
# Lisp like toy in Python
# (c) William Groppe, 2010
import re
import collections
SHOW_REDUCTIONS = False
OP_BEGIN = "("
OP_END = ")"
def tuplify(ws):
out = dict()
for r in range(0, ws.get_highest_row()):
for c in range(0, ws.get_highest_column()):
# openpyxl uses 1,1 as origin we expect 0,0
out[(r,c)] = ws.cell(row=r+1, column=c+1).value
return out
def check_if_xlxs(filename):
from openpyxl.reader.excel import load_workbook