Skip to content

Instantly share code, notes, and snippets.

from django.http import HttpResponseRedirect
from django.conf import settings
from re import compile
EXEMPT_URLS = [compile(settings.LOGIN_URL.lstrip('/'))]
if hasattr(settings, 'LOGIN_EXEMPT_URLS'):
EXEMPT_URLS += [compile(expr) for expr in settings.LOGIN_EXEMPT_URLS]
class LoginRequiredMiddleware:
"""
@nrabinowitz
nrabinowitz / progsvc.php
Created August 6, 2011 04:19
Mock PHP service for timemap.js progressive loading
<?
// get timestamps
$start = strtotime($_GET['start']);
$end = strtotime($_GET['end']);
$cb = $_GET['callback'];
// start data
echo "$cb([";
@bkono
bkono / spin-js-example.html
Created August 21, 2011 19:27
spin.js example
<!doctype html>
<head>
<title>Hi</title>
<style>
#spin {
background: #333;
color: white;
float: left;
width: 200px;
height: 200px;
@maraujop
maraujop / forms.py
Created February 15, 2012 19:04
django-crispy-forms bootstrap form example
# -*- coding: utf-8 -*-
from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Div, Submit, HTML, Button, Row, Field
from crispy_forms.bootstrap import AppendedText, PrependedText, FormActions
class MessageForm(forms.Form):
text_input = forms.CharField()
@suhailvs
suhailvs / Openshift27.md
Last active August 29, 2015 13:56
Openshift python -2.7, django-1.6 example

Steps to create in OPENSHIFT

  1. Create a Python27 app in Openshift

create a python2.7 application in openshift

if you still don't uploaded the ssh publickey to openshift, then doit:

@0xdevalias
0xdevalias / HackMeSomeUnicoins.md
Last active August 29, 2015 13:57
A quick little hack to automagically mine unicoins (stackoverflow.com April Fools 2014) <3 /dev/alias (www.devalias.net)

First, go to stackoverflow.com then define this in your Javascript console:

var hackMeSomeUnicoins = function(myFkey) {
  console.log("Ok, let's hack you some shiny unicoins! <3 /dev/alias (www.devalias.net)")
  console.log("The powers that be say you can only mine a rock every 10sec, so we do it every 11sec to be sure.")
  window.setInterval(function(){
    $.get( "http://stackoverflow.com/unicoin/rock", function( data ) {
      var rockId = data.rock;
      $.post( "http://stackoverflow.com/unicoin/mine?rock=" + rockId, { fkey: myFkey })
 .done(function( data ) {

Much nicer solution can be used for any stackexchange sites::: First, go to stackoverflow.com(or any other stackexchange sites) then define this in your Javascript console(Press F12):

function minec(){ 
  $.getJSON('/unicoin/rock',function(data) {
    setTimeout(function(){
      $.post('/unicoin/mine?rock='+data.rock,{fkey:StackExchange.options.user.fkey})
      .done(function( data ) {
        console.log(data);

});

@JamesMessinger
JamesMessinger / IndexedDB101.js
Last active April 4, 2024 02:00
Very Simple IndexedDB Example
// This works on all devices/browsers, and uses IndexedDBShim as a final fallback
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
// Open (or create) the database
var open = indexedDB.open("MyDatabase", 1);
// Create the schema
open.onupgradeneeded = function() {
var db = open.result;
var store = db.createObjectStore("MyObjectStore", {keyPath: "id"});
@subfuzion
subfuzion / curl.md
Last active April 23, 2024 14:44
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@AtulKsol
AtulKsol / psql-error-fix.md
Last active April 10, 2024 07:41
Solution of psql: FATAL: Peer authentication failed for user “postgres” (or any user)

psql: FATAL: Peer authentication failed for user “postgres” (or any user)

The connection failed because by default psql connects over UNIX sockets using peer authentication, that requires the current UNIX user to have the same user name as psql. So you will have to create the UNIX user postgres and then login as postgres or use sudo -u postgres psql database-name for accessing the database (and psql should not ask for a password).

If you cannot or do not want to create the UNIX user, like if you just want to connect to your database for ad hoc queries, forcing a socket connection using psql --host=localhost --dbname=database-name --username=postgres (as pointed out by @meyerson answer) will solve your immediate problem.

But if you intend to force password authentication over Unix sockets instead of the peer method, try changing the following pg_hba.conf* line:

from