Skip to content

Instantly share code, notes, and snippets.

View lyschoening's full-sized avatar

Lars Schöning lyschoening

  • Copenhagen, Denmark
View GitHub Profile
import angular from 'angular';
function copy(source, target) {
Object.keys(source).forEach((key) => {
target[key] = source[key];
});
return target;
}
function fromCamelCase(string, separator = '_') {
@lyschoening
lyschoening / potion.js
Last active November 10, 2015 10:56
A helper class for dealing with JSON from Potion-based APIs in JavaScript
class Potion {
/**
*
* @param {function} fetch for GET requests to look up references
* @param {object} constructors a map of resource URIs to constructors, e.g. {'/type': Type}
* @param {function} defaultConstructor an optional fallback for other types
* @param {string} prefix an optional API prefix
* @param {object} cache an optional cache object with get(string), put(string, object) and remove(string) methods
*/
#!/usr/bin/env python
from base64 import b64decode
from flask import Flask, current_app
from flask_sqlalchemy import SQLAlchemy
from flask_presst import PresstApi, ModelResource
from flask_presst.principal import PrincipalResource
from flask_login import LoginManager, UserMixin, current_user, login_required, user_logged_in, user_logged_out
from flask_principal import UserNeed, RoleNeed, Principal, Identity, AnonymousIdentity, identity_changed, \
@lyschoening
lyschoening / AngularJS confirm button
Last active August 29, 2015 14:06
AngularJS directive for a two-click confirm button that resets state when it loses focus and can only be clicked once
<confirm-button confirm-text="Are you sure?">Delete Item</confirm-button>
<confirm-button confirm-icon="fa-trash" confirm-text="Confirm">Delete Item</confirm-button>
@lyschoening
lyschoening / angular.resources.coffee
Last active December 26, 2015 05:39
Nested Resources in Angular JS. Allows for embedding resources inside the JSON response of other collections as well as for cross-referencing between resources by their URI. See example file for usage (second file). Makes use of Object.defineProperty which requires IE8+
$resourceMinErr = angular.$$minErr('$resource')
angular.module('resources', [])
.provider 'Resource', () ->
provider = @
provider.prefix = '/api/v1'
provider.uriField = 'resource_uri'
class ResourceBase
@lyschoening
lyschoening / paginated_collection.js
Created December 2, 2011 10:51 — forked from takinbo/paginated_collection.js
Pagination with Backbone.js & django-tastypie
// includes bindings for fetching/fetched
var PaginatedCollection = Backbone.Collection.extend({
initialize: function() {
_.bindAll(this, 'parse', 'url', 'pageInfo', 'nextPage', 'previousPage', 'filtrate', 'sort_by');
typeof(options) != 'undefined' || (options = {});
typeof(this.limit) != 'undefined' || (this.limit = 20);
typeof(this.offset) != 'undefined' || (this.offset = 0);
typeof(this.filter_options) != 'undefined' || (this.filter_options = {});
typeof(this.sort_field) != 'undefined' || (this.sort_field = '');