Skip to content

Instantly share code, notes, and snippets.

View peterlie's full-sized avatar

Peter Lieberwirth peterlie

View GitHub Profile
@peterlie
peterlie / goback.py
Created January 20, 2017 20:21
in confirm-form flow, go back to original referer once complete - snippets
# webapp2/AppEngine
# in get method:
context = {
'goback_url': self.request.referer,
'info': the_info,
'maybe': Yes
}
# render the confirm form
@peterlie
peterlie / example.js
Last active November 27, 2015 19:57
JSON.stringify example using Django template
/*jslint browser: true*/
(function ($) {
'use strict';
$(document).ready(function () {
if ($('#rawJson').length) {
var rj = $('#rawJson').text();
$('#fmtJson').html(JSON.stringify(JSON.parse(rj), null, 4));
}
@peterlie
peterlie / Cheatsheet.md
Last active August 29, 2015 14:27 — forked from hofmannsven/README.md
Git Cheatsheet
@peterlie
peterlie / http_response.py
Created May 22, 2015 02:19
Python HTTP responses
# Table mapping response codes to messages; entries have the
# form {code: (shortmessage, longmessage)}.
# this is within: BaseHTTPServer.BaseHTTPRequestHandler.responses
# thanks to https://docs.python.org/2/howto/urllib2.html
responses = {
100: ('Continue', 'Request received, please continue'),
101: ('Switching Protocols',
'Switching to new protocol; obey Upgrade header'),
200: ('OK', 'Request fulfilled, document follows'),
@peterlie
peterlie / block.js
Created November 20, 2014 02:12
Very simple Node example of using Blockchain's data API
'use strict';
var http = require('http');
// blockchain.info/latestblock
var options = {
host: 'blockchain.info',
path: '/latestblock'
};
var callback = function(response) {
@peterlie
peterlie / git-remove-lots.md
Last active August 29, 2015 14:06
git magic (for me anyway)

If you have to remove lots of deleted files:

$git rm $(git ls-files --deleted)
@peterlie
peterlie / notify.js
Created August 28, 2014 15:21
django, bootstrap, growl, oh my. thanks to @mouse0270
!function( $ ) {
'use strict';
$(document).ready(function() {
/* https://github.com/mouse0270/bootstrap-growl */
/*jshint multistr: true */
if ($('.alert').length) {
$('.alert').each( function() {
@peterlie
peterlie / gist:1657593
Created January 22, 2012 16:29 — forked from pamelafox/gist:1261016
Sending JS errors to server
window.onerror = function(message, url, line_num) {
// Standard error information
var error = '\n JS Error: ' + message + ' from ' + url + ':' + line_num;
error += '\n URL: ' + document.URL;
// User agent info, using https://github.com/caseyohara/user-agent
var user_agent = new UserAgent();
error += '\n Browser: ' + user_agent.browser_name + ' ' + user_agent.browser_version + ' | OS: ' + user_agent.os + ' | Platform: ' + user_agent.platform;