Skip to content

Instantly share code, notes, and snippets.

View sharoonthomas's full-sized avatar

Sharoon Thomas sharoonthomas

View GitHub Profile
diff --git a/emails/sale-confirmation-html.html b/emails/sale-confirmation-html.html
index 4a0ba5c..dfac4cb 100644
--- a/emails/sale-confirmation-html.html
+++ b/emails/sale-confirmation-html.html
@@ -8,6 +8,94 @@
{% endblock %}
</head>
<body>
+ {% block json_ld %}
+ <script type="application/ld+json">
@sharoonthomas
sharoonthomas / gist:19ed690b46f6162cc300
Created January 23, 2015 20:35
Python Unicode Dict CSV Reader
# -*- coding: utf-8 -*-
"""
unicode_dict_reader
:copyright: (C) 2013-2015 by Openlabs Technologies & Consulting (P) Limited
:license: BSD, see LICENSE for more details.
"""
import csv
class UnicodeDictReader(csv.DictReader):
def __init__(self, csvfile, *args, **kwargs):
<link rel="import" href="../core-scaffold/core-scaffold.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-menu/core-submenu.html">
<polymer-element name="my-element">
@sharoonthomas
sharoonthomas / gist:6e54065bafd57e6a4c51
Created January 31, 2015 12:41
Finding monday of a week
# Given a date find the monday and friday of the week
# This assumes that the week starts on sunday
import datetime
import calendar
from dateutil.relativedelta import relativedelta
def get_monday_in_week(date):
# Find the current week
current_week = date.isocalendar()[1]
delta = relativedelta(weeks=current_week-1, weekday=calendar.MONDAY)
@sharoonthomas
sharoonthomas / migrate_ups_module.py
Last active August 29, 2015 14:17
For the sake of consistency, the module ups was renamed to shipping_ups. Tryton's migration API does not provide a straightforward way to rename modules as its an exceptional case. This file gives you the code you need to make the migration
# -*- coding: utf-8 -*-
import os
import psycopg2
# Connect to tryton database with database uri.
#
# Example: postgres://tryton:tryton@localhost/production
conn = psycopg2.connect(os.environ.get('TRYTOND_DATABASE_URI'))
conn.set_client_encoding('UTF8')
#!/usr/bin/env bash
# This script assumes that ImageMagick is installed and the convert command is accessible via the $PATH variable
# Ensure that one argument has been passed in.
if [ ! "$#" -eq 1 ]
then
echo -e "This script requires one argument.\\ne.g. iOS_icon_maker.sh app_icon.png"
exit 1
fi
@sharoonthomas
sharoonthomas / gist:993335
Created May 26, 2011 15:09
Test for tryton dispatcher
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
import unittest
import threading
from functools import partial
from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT, \
install_module
class StringField(BaseField):
"""A unicode string field.
"""
def __init__(self, regex=None, max_length=None, min_length=None, **kwargs):
self.regex = re.compile(regex) if regex else None
self.max_length = max_length
self.min_length = min_length
super(StringField, self).__init__(**kwargs)
@sharoonthomas
sharoonthomas / gvs.js
Created September 26, 2011 12:04
Google visualisation.js
function drawVisualization() {
var data = new google.visualization.DataTable();
data.addRows(6);
data.addColumn('string', 'State');
data.addColumn('number', 'Customers');
data.setValue(0, 0, 'US-FL');
data.setValue(0, 1, 200);
data.setValue(1, 0, 'US-MN');
data.setValue(1, 1, 300);
data.setValue(2, 0, 'US-NJ');
@sharoonthomas
sharoonthomas / find.sh
Created December 8, 2011 12:37
Find and update git folders recursively
find . -mindepth 1 -maxdepth 1 -type d -exec sh -c "cd \"{}\" && python setup.py install" \;