Skip to content

Instantly share code, notes, and snippets.

View makmac213's full-sized avatar

Mark Allan B. Meriales makmac213

View GitHub Profile
@makmac213
makmac213 / .footer
Last active August 29, 2015 14:06
Keep you feet always on the ground.
@makmac213
makmac213 / AWS Instance Setup Guide
Last active October 27, 2017 08:14
AWS Instance Setup Guide
# 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
__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)
@makmac213
makmac213 / gist:10852009
Created April 16, 2014 10:54
get_google_time_zone
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)
@makmac213
makmac213 / mtgsalvation.py
Created January 16, 2014 13:38
Check for new spoilers and send sms alert to subscribers
import urllib, time, os
from subprocess import Popen, PIPE, check_call
from BeautifulSoup import BeautifulSoup
subscribers = [
'0922xxxxxxx',
'0999xxxxxxx',
'0917xxxxxxx',
'0915xxxxxxx',
]
@makmac213
makmac213 / class O
Last active December 26, 2015 12:09
csv to class obj
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]
@makmac213
makmac213 / Mailchimp subscription
Last active December 25, 2015 06:19
Mailchimp subscribe to list
# 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,
@makmac213
makmac213 / Ala Pinterest
Created October 10, 2013 06:03
For random multiple classes query (ala pinterest)
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
# 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());
@makmac213
makmac213 / ordinal_date_suffix.py
Last active December 16, 2015 21:39
returns the date with ordinal suffix
# 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]