Notes

Dump/Restore Postgres DB to/from archive

Posted by Dan on Saturday the 18th of March, 2017

Dump a Postgres DB to a Gzip archive:

pg_dump db -U user | gzip > db.sql.gz

Restore dumped Gzip:

gunzip -c db.sql.gz | psql -U user db

Remove all files or directories except one

Posted by Dan on Thursday the 28th of April, 2016

To remove all directories except one specified:

ls | grep -v directory_name | xargs rm -rf

remove all files except one specified:

ls | grep -v file_name | xargs rm

Custom Django Project Template

Posted by Dan on Sunday the 13th of July, 2014

I have created a base Django project template to enable rapidly starting Django projects, it uses some basic features that I use frequently.

This base template includes:

  • Fabric deployment scripts
  • Bootstrap static files with less.js
  • Base templates
  • Nginx, Gunicorn and Supervisor templates for deployment
  • Multiple settings per environment

Usage

To create a project with this template:

Make a virtual environment activate it and install Django.

Start the project

1
django-admin.py startproject --template=https://github.com/dantium/django-project-template/archive/master.zip myproject 

Options

1
2
--git_path=https://github.com/user/project
--domain_name=myproject.com 

Virtualenv 1.7 changed default behavior

Posted by Dan on Saturday the 28th of January, 2012

The default behaviour of virtualenv has changed, 1.7 now creates your virtual environment with what was the --no-site-packages option as default.

To create an environment with global packages there is a new option:

1
virtualenv --system-site-packages ENV

Embedding Pictures from Google+ using jQuery

Posted by Dan on Saturday the 17th of December, 2011

Currently the Google+ API doesn't allow access to a users photo albums and images, however it is possible to access your images stored on Google+ using the Picasa web albums data API

I have written a simple jQuery plugin to get pictures from an album and display them in a simular style and effect to the albums on Google+, you can see a demo of this here and on the front page of my site you can view the jQuery plugin on github.

Install & Setup

Make sure you have at least jQuery 1.4.2.

Download the plugin from here and include the css and js file as below:

1
2
<link rel="stylesheet" href="style.css" type="text/css" media="screen, projection" />
<script type="text/javascript" src="pluspics.js"></script>

Run the following script to setup and run the gallery plugin.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<script type="text/javascript">
$(document).ready(function(){
	$('#container-id').plusPics({
		userId: 'your_user_id',
		albumId: 'your_album_id',
		numImages: 3,
		title: 'Images'
	});
});
</script>

Put an empty container div on the page where you want the gallery to display.

1
<div id="container-id"></div>

Loyalty Rewards Point System for Satchmo

Posted by Dan on Friday the 9th of December, 2011

I have created a module for Satchmo (an ecommerce system for Django) that deals with customer reward points. Customers can receive rewards for signing up and for purchasing products and are able to redeem their reward points when buying products.

You can view and download the source code from Github.

Features

  • Set sign-up points value.
  • Set percentage of points a customer will get from an order.
  • Set money value of points.
  • Allow for partial points payment on an order.
  • Customer points transaction history.

Install & Setup

  1. pip install -e git+git://github.com/dantium/satchmo-rewardpoints.git#egg=reward
  2. Add reward to your INSTALLED_APPS setting.
  3. Activate and change the available options in admin > edit site settings