Skip to content

Instantly share code, notes, and snippets.

@kvnn
kvnn / DJANGO_get_next_or_prev
Created April 4, 2012 16:33
Django: Get next or previous item of a Queryset
''' Useage ''''
# Declare our item
store = Store.objects.get(pk=pk)
# Define our models
stores = Store.objects.all()
# Ask for the next item
new_store = get_next_or_prev(stores, store, 'next')
# If there is a next item
if new_store:
# Replace our item with the next one
@kvnn
kvnn / DJANGO_maiden_fields
Created April 4, 2012 16:39
Django: Make all text and password inputs show their label within their field, and blank when a user clicks on them.
'''
This is a coffeescript file that when loaded will,
for all text and password inputs:
1. remove field label using .prev('label')
2. insert the label's text into the value of the field input
3. blank the field input when a user focuses on the field
maiden_text = (e) ->
'''
from compressor.filters import CompilerFilter
class CoffeeCompilerFinder(staticfiles.finders.AppDirectoriesFinder):
"""
A quick hacked up staticfiles-finder that will automatically recompile .coffee files to .js and serve the .js file
It will respond to a request for /foo/bar/baz.js and if the coffee-file with the same name in that same dir is newer then
then js-file requested then the js-file will be recompiled.
I did this to not have to manually recompile my scripts or use the watcher and still be compatible with require.js
without have to change the code once i deploy with compiled js-files. it depends on django-compressor at the moment
but if you dont use that its just a small class to lift out from it.
@kvnn
kvnn / imagesLoaded caching
Created July 25, 2012 03:35
An example of imagesLoaded's cache behavior
/*
* An example of imagesLoaded's cache behavior
* see http://jsfiddle.net/FVLbn/2/
*/
var imgUrls = ['http://3.bp.blogspot.com/-K07eebumZmc/TvN1SmVvZvI/AAAAAAAACUI/TtxP5n9aL4w/s1600/strenco_steam_robot_1.jpg', 'http://www.warcrafthuntersunion.com/wp-content/uploads/2011/07/robot1.jpg','http://4.bp.blogspot.com/-il7IWW4_nyA/T5qojE8_FYI/AAAAAAAAC7M/D7mQZVkA4a8/s1600/nod32robot.png', 'http://neuronmnit.org/wp-content/uploads/2011/08/1312290130-21.jpg']
var images,
image1 = $('<img />').attr('src', imgUrls[0]),
@kvnn
kvnn / git hook to ensure requirements and pip are synced
Created July 25, 2012 15:42
git hook to ensure requirements.txt and pip freeze are synced
# This hasn't been tested. I found it here: http://news.ycombinator.com/item?id=4290203
[hooks]
pretxncommit.pip = bash -c "diff -u requirements.txt <(source env/bin/activate &&
@kvnn
kvnn / youtube-helper.js
Created August 17, 2012 15:07 — forked from ddesilva/youtube-helper.js
Require.js Module for the YouTube Iframe API
define(["require", "exports"], function (require, exports) {
exports.YouTubeHelper = function (settings) {
// MEMBERS & DEFAULTS #################################################################################################################################################
var documentRef;
var originURL = ""; // for cross site checks
var targetContainer;
var target;
var parentContainer; // used for adding popups back into the original spot
@kvnn
kvnn / pusher-private-channel-auth-with-aws-lambda-and-gateway.md
Last active February 12, 2017 19:12
Integrating authentication for Pusher private-channels using a Lambda function & an API Gateway endpoint, using JSONP

Pusher private-channel authentication using AWS Lambda w/ Gateway API

Author: kvnn // @kevinriggen // kriggen@gmail.com

Pusher private-channels require authentication [i].

Lambda functions [ii] are a good candidate for doing the computation that determines whether a user is authenticated for a private channel, or not.

An API Gateway resource [iii] is necessary to receive the Pusher client's request & send it to the Lambda function, then send the Lambda function's response back

Keybase proof

I hereby claim:

  • I am kvnn on github.
  • I am kvnn (https://keybase.io/kvnn) on keybase.
  • I have a public key ASDW92CSGzTGiBV6BEFOSs9uwc1SzTUnYfGWT3DWJd3GAwo

To claim this, I am signing this object: