Skip to content

Instantly share code, notes, and snippets.

View fredrikbonander's full-sized avatar

Fredrik Bonander fredrikbonander

View GitHub Profile
@fredrikbonander
fredrikbonander / angular-resource-mod.js
Created September 19, 2012 12:16
Added optional urlOption to resource constructor to support unencoded url:s
/**
* @license AngularJS v1.0.0rc12
* (c) 2010-2012 Google, Inc. http://angularjs.org
* License: MIT
*/
(function(window, angular, undefined) {
'use strict';
/**
* @ngdoc overview
#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'broken'
import os
import zipfile
import yaml
from shutil import copy2
@fredrikbonander
fredrikbonander / model.py
Created May 27, 2013 14:01
Ndb StringProperty validation
def _validate(self, value):
if isinstance(value, str):
# Decode from UTF-8 -- if this fails, we can't write it.
try:
value = unicode(value, 'utf-8')
except UnicodeError:
raise datastore_errors.BadValueError('Expected valid UTF-8, got %r' %
(value,))
elif not isinstance(value, unicode):
raise datastore_errors.BadValueError('Expected string, got %r' %
@fredrikbonander
fredrikbonander / model.py
Created May 29, 2013 12:05
Find first matching
>>> [n for n in xrange(19) if n > 10]
[11, 12, 13, 14, 15, 16, 17, 18]
>>> next(n for n in xrange(19) if n > 10)
11
>>>
@fredrikbonander
fredrikbonander / app.js
Created July 30, 2013 07:31
A simple service wrapping the $http api
// Example usage of http-service
(function (window) {
"use strict";
var angular = window.angular,
appModule = angular.module('app', ['httpService']);
appModule.controller('BaseCtrl', ['HttpService', function (HttpService) {
// Example GET, with query param, success and error callbacks
HttpService.get('/api/monkey', {
@fredrikbonander
fredrikbonander / gist:6285962
Created August 20, 2013 19:20
Fetch all Issue by assingment
## First fetch all assingments
qp = QueryParser({'assigned_to': [('=', account_id)]})
assignments = IssueAssignFactory.fetch(filters=qp.filters).resolve() # Do later, just for show
## Make new IssueAssignFactory.fetch that only fetch keys
# Alt 1
issues = ndb.get_multi([assignment.key().parent() for assignment in assignments])
# Alt 2, bad idea i think
qp = QueryParser({'key': [('=', [assignment.key().parent() for assignment in assignments])]})
@fredrikbonander
fredrikbonander / deploy.py
Last active December 21, 2015 14:19
Deploy script appengine with modules
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
import argparse
import os
import zipfile
import yaml
from subprocess import call
__author__ = 'broken'
@fredrikbonander
fredrikbonander / amd.js
Created December 4, 2013 15:09
bare angular VS amd
/** AMD **/
define([
'angular'
'common/security/constants'
], function (angular) {
'use strict';
angular.module('security.someModule', [
'security.constants'
])
@fredrikbonander
fredrikbonander / p_data.py
Last active January 3, 2016 10:49
Simple TZ implementation
from datetime import datetime, tzinfo, timedelta
class TZOffset(tzinfo):
def __init__(self, offset=0, *args, **kwds):
self.gmt_offset = offset
super(TZOffset, self).__init__(*args, **kwds)
def utcoffset(self, dt):
return timedelta(hours=self.gmt_offset) + self.dst(dt)
def tzname(self,dt):
return "GMT %s%s" % (('+' if self.gmt_offset > 0 else ''), self.gmt_offset)
@fredrikbonander
fredrikbonander / srv.py
Last active January 4, 2016 08:19
Flask fileupoad
import os
import uuid
from flask import Flask
from flask import jsonify
from flask import request
from flask import make_response
from werkzeug import secure_filename
UPLOAD_FOLDER = os.path.dirname(os.path.realpath(__file__))
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])