Skip to content

Instantly share code, notes, and snippets.

import hashlib
import hmac
def bazaar_voice_token(encoding_key, parameters):
secret = bytes(encoding_key, 'utf-8')
message = bytes(parameters, 'utf-8')
hash = hmac.new(secret, message, hashlib.sha256)
return hash.hexdigest() + message.hex()
@triplec1988
triplec1988 / httpStatusCheck.rb
Last active August 29, 2015 13:56
A small ruby script to run as a cron job on an Ubuntu server. This will check the HTTP status of any of the URIs you put in the sites array. If the status code does not return 200, an error will be logged and you'll receive an email.
#!/usr/bin/env ruby
require 'net/http'
require 'net/smtp'
require 'logger'
# Set up logging
file = File.open('/path/to/the/logs/http_response.log', File::WRONLY | File::APPEND)
log = Logger.new(file)
message = <<EOF
@triplec1988
triplec1988 / link_tweet.py
Created October 17, 2013 16:29
Twitter Regex matching: This method will match hashtags and @mentions in a tweet object obtained from the twitter API and replace them with linked <a> tags. This allows you to take text from a tweet, link the appropriate entities, and then inject it into HTML. You can also see demos here: @mentions -- http://regex101.com/r/mE9qQ9 #hashtags -- ht…
@triplec1988
triplec1988 / currency.py
Created August 1, 2013 19:04
The documentation on creating, and subsequently using, custom Django template filters is pretty terrible. This Gist explains how to structure, create and then use custom filters in your Django applications. To create a custom filter, first create a directory called templatetags within your application directory such that: my_project ==> my_app =…
import locale
from django.template import Library
register = Library()
@register.filter(name='currency')
def currency(value):
try:
@triplec1988
triplec1988 / backends.py
Created June 29, 2013 13:50
This is a step by step guide for authenticating and saving users in Django using Foursquare and OAuth without having to use a large library like django-social. This can also be used as a guide for implementing other third party applications (i.e. Instagram, Twitter, etc) as your Django authentication and user creation source. STEP ONE: Register …
from django.contrib.auth.models import User
from django.contrib.auth.backends import ModelBackend
class FoursquareBackend(ModelBackend):
def authenticate(self, username=None, password=None):
try:
user = User.objects.get(username=username)
return user
except User.DoesNotExist:
@triplec1988
triplec1988 / pinterest_soup.py
Last active July 29, 2017 06:31
It's annoying that Pinterest doesn't have a Public API right now, obviously making working with their data much more difficult. This is a Python method I wrote using BeautifulSoup that scrapes a user's Pinterest Pins page, looking for the pin with the most repins, and returns a small list of data to be manipulated: pin_url, image_url, descriptio…
'''
Copyright 2013 Pontiflex, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
'''