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 / gist:cf8c0df8ca9c19ccd77b
Created August 6, 2015 10:57
Apache - Permanent redirect and browser caching
<VirtualHost *:80>
ServerName example.com
Redirect permanent / http://www.example.com/
</VirtualHost>
<VirtualHost *:80>
ServerName www.example.com
<Directory /home/ubuntu/public_html/example/example/>
@makmac213
makmac213 / django_notes.txt
Last active November 6, 2015 07:31
Some useful notes that I use most of the time
Django Compressor + Amazon S3
=============================
http://django-compressor.readthedocs.org/en/latest/
https://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html
$ pip install django_compressor
$ pip install django-storages boto
$ mongoexport -d dbname -c collectionname -v -o file.json
$ mongoimport -d dbname -c collectionname -v --file file.json -h 127.0.0.1 -p 27017
@makmac213
makmac213 / sitemap_status_crawler.py
Created March 10, 2016 18:38
Sitemap Status Crawler
import requests
from BeautifulSoup import BeautifulSoup
resp = requests.get('http://www.ofwguru.com/sitemap.xml')
soup = BeautifulSoup(resp.content)
urls = soup.findAll('url')
for url in urls:
loc = url.find('loc').string
from django.contrib.auth.models import User
from django.db.models import Count
qs = (User.objects.all().
extra(select={
'm': "EXTRACT(month FROM date_joined)",
'd': "EXTRACT(day FROM date_joined)",
'y': "EXTRACT(year FROM date_joined)",
}).
values('d', 'm', 'y').
# export script
# export_script.js
print("subject,sender,recipient,created")
db.collectionname.find({'subject':/for you/}).foreach(function(email){
print(email.subject+","+email.sender+","+email.recipient+","+email.created);
});
# then run this line
$ mongo tablename export_script.js > export_file.csv
@makmac213
makmac213 / hugotbot.py
Last active December 17, 2018 11:41
hugotbot.py
from nltk.chat.util import Chat, reflections
pairs = [
[
r"My name is (.*)",
['hello %1', '%1 mabuhay ka'],
],
[
r'hi',
['hello', 'kamusta', 'mabuhay',],
import json
import requests
from bottle import debug, request, route, run
def build_service_url(service_url, cid):
"""build the service url"""
service_url = '{0}/v3/conversations/{1}/activities/'.format(service_url, cid)
return service_url
import json
import requests
from bottle import debug, request, route, run
GRAPH_URL = "https://graph.facebook.com/v2.6"
VERIFY_TOKEN = 'YOUR_VERIFY_TOKEN'
PAGE_TOKEN = 'YOUR_PAGE_TOKEN'
def send_to_messenger(ctx):
0x119E2c5b180D8d2Bee8c2Fca42E9f4443A4D6fB2