Skip to content

Instantly share code, notes, and snippets.

View danriti's full-sized avatar

Dan Riti danriti

View GitHub Profile
@danriti
danriti / README.md
Last active October 13, 2015 09:47
Git Deployment Post Receive

Instructions

Put your ssh key on the server:

$ ssh-copy-id username@remote-server.org

On the server, create a bare git repo:

$ mkdir website.git
@danriti
danriti / decorator.py
Created July 21, 2012 17:28
Django - Restrict access to a view to only active and authenticated users
from django.contrib.auth.decorators import user_passes_test, login_required
active_required = user_passes_test(lambda u: u.is_active,
login_url='/profile/not_active')
def active_and_login_required(view_func):
decorated_view_func = login_required(active_required(view_func))
return decorated_view_func
@danriti
danriti / hipchat.sh
Last active May 21, 2022 23:13
HipChat - Send a message to a room using cURL
# Build Passes
curl -d "room_id=ourRoom&from=BuildBot&message=Build+Status:+Passing&color=green" https://api.hipchat.com/v1/rooms/message?auth_token=AUTH_TOKEN_HERE&format=json
# Build Fails
curl -d "room_id=ourRoom&from=BuildBot&message=Build+Status:+Failing&color=red&notify=1" https://api.hipchat.com/v1/rooms/message?auth_token=AUTH_TOKEN_HERE&format=json
@danriti
danriti / gist:2869387
Created June 4, 2012 16:27
Generate user activation key for a Django user
"""
The activation key for the ``UserProfile`` will be a
SHA1 hash, generated from a combination of the ``User``'s
email and a random salt.
"""
salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
email = user.email
if isinstance(email, unicode):
@danriti
danriti / twitter_api.py
Created January 24, 2012 03:16
Twitter API Access
#!/usr/bin/python
import simplejson as json
import oauth2 as oauth
# Create your consumer with the proper key/secret.
consumer = oauth.Consumer(key="YOUR_CONSUMER_KEY",
secret="YOUR_CONSUMER_SECRET")
@danriti
danriti / database.py
Created January 16, 2012 00:33
Python + MySQLdb + Unicode
#!/usr/bin/python
# -*- coding: utf-8 -*-
import MySQLdb as mysql
def QueryDatabase(query, values):
"""Function to query a MySQL database and return the results of the
query."""
# Initialize variables and return values.