This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Setup apache2 mysql php | |
$ sudo apt-get install tasksel | |
$ sudo tasksel install lamp-server | |
# python setup tools | |
$ sudo apt-get install python-setuptools | |
$ sudo apt-get install python-pip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = "Mark Allan B. Meriales" | |
# based from http://www.pythoncentral.io/watermark-images-python-2x/ | |
# mine uses a picture as a watermark | |
from PIL import Image, ImageEnhance | |
def add_watermark(image_file, logo_file, opacity=1): | |
img = Image.open(image_file).convert('RGB') | |
logo = Image.open(logo_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_google_time_zone(lat, lng): | |
ret = False | |
try: | |
api_url = 'https://maps.googleapis.com/maps/api/timezone/json' | |
payload = { | |
'location': '%s,%s' % (lat, lng), | |
'timestamp': int(time.time()), | |
'sensor': 'true', | |
} | |
response = requests.get(api_url, params=payload) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib, time, os | |
from subprocess import Popen, PIPE, check_call | |
from BeautifulSoup import BeautifulSoup | |
subscribers = [ | |
'0922xxxxxxx', | |
'0999xxxxxxx', | |
'0917xxxxxxx', | |
'0915xxxxxxx', | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class O: | |
""" | |
csv to class | |
o = O(['col_1_name','col_2_name',...]) | |
o.parse_row(row) | |
""" | |
def __init__(self, *args, **kwargs): | |
if len(args) == 1: | |
self.args = args[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# MAILSNAKE | |
from mailsnake import MailSnake | |
from mailsnake.exceptions import * | |
from django.conf import settings | |
ms = MailSnake(settings.MAILCHIMP_API_KEY) | |
val = ms.listSubscribe(id=settings.MAILCHIMP_LIST_ID, | |
email_address=email_address, | |
double_optin=False, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from django.conf import settings | |
from django.shortcuts import HttpResponse | |
from django.template import RequestContext | |
from bar.models import Bar | |
from foo.models import Foo | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the javascript # | |
""" | |
var position = -1; | |
$(function(e) { | |
$("#sortable").sortable({ | |
start: function(event, ui) { | |
position = ui.item.index(); | |
}, | |
stop: function(event, ui) { | |
//alert("New position: " + ui.item.index()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mark Allan B. Meriales | |
def ordinal_date_suffix(dt): | |
suffix = '' | |
num_date = int(dt.strftime('%d')) | |
if (num_date >= 4 and num_date <= 20) or (num_date >= 24 and num_date <= 30): | |
suffix = 'th' | |
else: | |
suffix = ['st','nd','rd'][(num_date % 10) - 1] |