Skip to content

Instantly share code, notes, and snippets.

View fredrikbonander's full-sized avatar

Fredrik Bonander fredrikbonander

View GitHub Profile
<link rel="import" href="../core-animated-pages/core-animated-pages.html">
<link rel="import" href="../core-animated-pages/transitions/hero-transition.html">
<link rel="import" href="../core-animated-pages/transitions/cross-fade.html">
<link rel="import" href="../core-animated-pages/transitions/slide-down.html">
<link rel="import" href="../core-animated-pages/transitions/slide-up.html">
<link rel="import" href="../core-animated-pages/transitions/tile-cascade.html">
<polymer-element name="my-element">
<template>
@fredrikbonander
fredrikbonander / unit-testing-js.md
Created February 25, 2014 15:36
unit-testing-js

If you are unfamiliar with the concepts of TDD (test-driven-development) there's a vast sea of information about it. Just use your favourite search engine and jump in.

The concept it self is very simple. First write you tests then write code that will be tested.

In reality this is hard. It's hard because is like thinking backwards. It's hard because you might not always now what something need to do or how the specific API works. You need to experiment first. Do not fear, TDD and unit testing will help you. One of the most important things to know is that TDD is not a ruleset, it's a tool. And you'll soon find that your code is more decoupled and more awesome.

Setting up a testrunner for testing:

Before running your tests you need somewhere to run the tests. Here Karma is your friend. Karma is easily installed with npm:

@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'])
@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 / 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 / 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 / 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 / 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 / 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 / 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' %