Skip to content

Instantly share code, notes, and snippets.

@g-cassie
g-cassie / gist:ff54a3d29bc8358892be
Created September 29, 2014 21:08
Using pdf.js in an Ember View
/**
* @class pdfView
* @extends {Ember.View}
*/
var PDFView = Ember.View.extend({
tagName: 'canvas',
/**
* Url to pdf file.
* @property src
* @type {string}
//Model
number: Ember.computed(function(){
var cid = this.get('CID'),
promise;
promise = this.get('deal').then(function(deal){
var num = deal.get('contentNumbering')[cid];
return num ? num + '.' : '';
});
return DS.PromiseObject.create({promise: promise});
@g-cassie
g-cassie / forms-user.js
Last active August 29, 2015 14:24
Sketch of Ember Class Based Forms API
import forms from 'cb-forms';
export default forms.Form.extend({
fields: {
username: forms.CharField.create({
userStore: Ember.inject.service(),
maxLength: 10,
minLength: 2,
validate(value){
@g-cassie
g-cassie / fields.py
Last active August 29, 2015 14:24
Django Rest Framework Custom Field - Embedded on read / Primary Key on write
from __future__ import unicode_literals
from django.core.exceptions import ObjectDoesNotExist
from rest_framework.relations import RelatedField
class EmbeddedPrimaryKeyRelatedField(RelatedField):
default_error_messages = {
'required': 'This field is required.',
'does_not_exist': "Invalid pk '{pk_value}' - object does not exist.",
'incorrect_type': 'Incorrect type. Expected pk value, received '
@g-cassie
g-cassie / models.py
Created August 20, 2015 14:12
This is how we are handling complex permissions right now (this is actually a grossly simplified version). The main problem is permissions logic is split between multiple places. It would be nice to consolidate all permissions logic in permissions.py. Additionally it would be nice to make this more composable so you can have AdminPermission and …
class Organization(models.Model):
name = models.CharField()
class Project(models.Model):
name = models.CharField()
users = models.ManyToManyField('User', related_name='users', through='UserProjectPermission')
organization = models.ForeignKey(Organization)
# this uses the models setout in this gist: https://gist.github.com/g-cassie/6b9b0f29371677f48659
from projects.models import Project, User, UserProjectAccess
class UserProjectChildProfile(permissions.Profile):
# ProjectChild refers to any model that has a ForeignKey to Project
def __init__(self, request):
self.user = request.user
def get_queryset_filters(self, request, queryset):
from firm.precedents.corporate.agreements import StartupShareholdersAgreement
from firm.precedents.corporate.mixins import DragAlongMixin, RightOfRefusalMixin
from jursidictions import Delaware
from votes import super_majority
from legal_entities import Corporation, Individual
# First lets create some parties to be part of our agreement
john = Individual(name='John Smith', jurisdiction=UK)
sam = Individual(name='Sam Smith', jurisdiction=Delaware)
@g-cassie
g-cassie / application.controller.js
Last active December 2, 2015 18:38
Advent of Code Day 2 - Ember Solver
import Ember from 'ember';
const BoxToWrap = Ember.Object.extend({
length: 0,
height: 0,
width: 0,
sides: Ember.computed('length', 'width', 'height', function(){
const dims = ['length', 'width', 'height'];
const sides = [];
import md5
def find_key(secret):
"""
>>> find_key('abcdef')
609043
>>> find_key('pqrstuv')
1048970
"""
// my-addon/templates/components/addon-componenent.hbs
We are going to render a component here:
{{component selectedComponent}}
// my-app/components/app-component.js
Ember.Component.extend({
// using ember inspect myService === undefined when using the application template below
myService: Ember.inject.service()
});