Skip to content

Instantly share code, notes, and snippets.

View nickretallack's full-sized avatar

Nick Retallack nickretallack

View GitHub Profile
function grow_field(field){
var field = $(field)
setTimeout(function(){
var temp_field
if (field.hasClass('.note')) temp_field = $('.autogrow .note' )
else temp_field = $('.autogrow .title')
temp_field.text(field.val() + " MM")
field.css('height', temp_field.height())
})
}
def renderer(template, args, encoding=None):
return template + ": "+ args['body']
class Resource(resource.Resource):
@resource.child("foo")
def foo(self, request, segments):
method_name = "foo_"+request.method.lower()
if request.method == "HEAD" and not hasattr(self, method_name):
method_name = "foo_get"
@nickretallack
nickretallack / gist:3152807
Created July 20, 2012 19:43
npm fails to search
npm WARN Building the local index for the first time, please be patient
npm http GET https://registry.npmjs.org/-/all
npm http 200 https://registry.npmjs.org/-/all
npm ERR! Error: ENOENT, open '/home/nick/.npm/-/all/.cache.json'
npm ERR! { [Error: ENOENT, open '/home/nick/.npm/-/all/.cache.json']
npm ERR! errno: 34,
npm ERR! code: 'ENOENT',
npm ERR! path: '/home/nick/.npm/-/all/.cache.json' }
npm ERR! You may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
@nickretallack
nickretallack / virtual_repeat.coffee
Created November 14, 2012 02:04
Virtual Repeat Directive for AngularJS
module = angular.module 'ui.directive'
module.directive 'virtualRepeat', ->
transclude: true
compile: (element, attributes, linker) ->
(scope, element, attributes, controller) ->
expression = attributes.virtualRepeat
match = expression.match(/^\s*(.+)\s+in\s+(.*)\s*$/)
if not match then throw Error "Expected virtualRepeat in form of '_item_ in _collection_' but got '#{expression}'."
[throwaway, key, value] = match
@nickretallack
nickretallack / gist:4743271
Created February 9, 2013 00:52
Hacky little dialog box in Angular
<div ng-switch="!!$root.show_this_dialog">
<section ng-switch-when="true" class="overlay" centerline ng-click="$root.show_this_dialog = false">
<div class="dialog" ng-click="$event.stopPropagation()">
<header class="header">
<h1>I'm a Dialog</h2>
<a class="close" ng-click="$root.show_this_dialog = false">x</a>
</header>
</div>
</section>
</div>
@nickretallack
nickretallack / gist:5087584
Last active December 14, 2015 12:38
This has worked in the past, but no longer works. I'm attempting to do a rebase like the one described in git rebase --help as "git rebase --onto master next topic". Specifically, I'm trying to copy a range of commits from one branch onto another. Currently, I can't get git to do this. It appears to ignore --onto and --root, and just use the bar…
Nicholass-MacBook-Air-5:test-git nick$ git init
Initialized empty Git repository in /Users/nick/test-git/.git/
Nicholass-MacBook-Air-5:test-git nick$ touch file
Nicholass-MacBook-Air-5:test-git nick$ git add file
Nicholass-MacBook-Air-5:test-git nick$ git commit -am "first commit"
[master (root-commit) dd1c9fd] first commit
0 files changed
create mode 100644 file
Nicholass-MacBook-Air-5:test-git nick$ git checkout -b branch1
Switched to a new branch 'branch1'
@nickretallack
nickretallack / README
Last active December 28, 2015 19:48
Demonstrates a bug in Flask-Sqlalchemy where form rules breaks on relationships that do not already have at least one member.
Requirements: Postgresql, Flask-Admin, Flask-Sqlalchemy
How to run it:
createdb inline_bug
psql inline_bug -af schema.sql
python app.py
Go to /admin and try to edit the servers. One will work, one will not.
@nickretallack
nickretallack / echo.txt
Created December 6, 2013 18:59
Flask-Admin + Flask-Security = way too many queries to render a blank page.
2013-12-06 10:56:05,034 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)
2013-12-06 10:56:05,035 INFO sqlalchemy.engine.base.Engine SELECT users.id AS users_id, users.email AS users_email, users.password AS users_password, users.active AS users_active, users.confirmed_at AS users_confirmed_at, users.last_login_at AS users_last_login_at, users.current_login_at AS users_current_login_at, users.last_login_ip AS users_last_login_ip, users.current_login_ip AS users_current_login_ip, users.login_count AS users_login_count, users.first_name AS users_first_name, users.last_name AS users_last_name
FROM users
WHERE users.id = %(id_1)s
LIMIT %(param_1)s
2013-12-06 10:56:05,035 INFO sqlalchemy.engine.base.Engine {'id_1': u'bada4c26-7571-4f96-9d46-5ae511eed682', 'param_1': 1}
2013-12-06 10:56:05,037 INFO sqlalchemy.engine.base.Engine SELECT roles.id AS roles_id, roles.name AS roles_name, roles.description AS roles_description
FROM roles, roles_users
WHERE %(param_1)s = roles_users.user_id AND roles.id = roles_users.ro
@nickretallack
nickretallack / wtforms_api.py
Created January 13, 2014 20:42
An attempt at re-using a wtform for both creation and updating of a record via an API that is allowed to omit fields from requests.
from flask.ext.wtf import Form
import wtforms as w
import wtforms.validators as wv
from flask import Flask, request, jsonify
app = Flask(__name__)
class MyForm(Form):
name = w.StringField(validators=[wv.DataRequired()])
@nickretallack
nickretallack / maybe_super.py
Last active January 3, 2016 05:08
This is useful if you're making mixins that each add a little something to the same set of functions, and there's no guaranteed that the base class has those functions defined, or perhaps there is no base class in common and you don't want to be bothered with thinking about method resolution order between your mixins.
def maybe_super(cls, self, method_name, base_value=None):
""" Call the super method if it exists.
Use it like this:
def some_method(self, *args, **kwargs):
result = maybe_super(MyClass, self, 'some_method')(*args, **kwargs)
"""
sup = super(cls, self)