Skip to content

Instantly share code, notes, and snippets.

Dan Riti danriti

Block or report user

Report or block danriti

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@danriti
danriti / database.py
Created Jan 16, 2012
Python + MySQLdb + Unicode
View database.py
#!/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.
@danriti
danriti / twitter_api.py
Created Jan 24, 2012
Twitter API Access
View twitter_api.py
#!/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 / gist:2869387
Created Jun 4, 2012
Generate user activation key for a Django user
View gist:2869387
"""
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 / hipchat.sh
Last active Feb 22, 2017
HipChat - Send a message to a room using cURL
View hipchat.sh
# 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 / decorator.py
Created Jul 21, 2012
Django - Restrict access to a view to only active and authenticated users
View decorator.py
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 / README.md
Last active Oct 13, 2015
Git Deployment Post Receive
View README.md

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
View fdups.py
# http://stackoverflow.com/questions/748675/finding-duplicate-files-and-removing-them/748908#748908
import sys
import os
import mmh3
CHUNK_SIZE = 1024*1024
def check_for_duplicates(paths):
@danriti
danriti / ffmpeg.sh
Last active Dec 17, 2015
FFMPEG FOR THE WIN!
View ffmpeg.sh
# List audio devices
ffmpeg -list_devices true -f dshow -i dummy
# Pipe audio from Line In to another computer (192.168.1.17)
ffmpeg -f dshow -i audio="Line In (High Definition Audio " -acodec libmp3lame -ab 320000 -f rtp rtp://192.168.1.17:1234
# Listen to audio on destination computer
ffplay rtp://192.168.1.17:1234
@danriti
danriti / md2html.sh
Created Jun 4, 2013
Convert markdown to HTML
View md2html.sh
#!/bin/bash
# http://johnmacfarlane.net/pandoc/demos.html
pandoc -s README.md -o README.html
You can’t perform that action at this time.