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 / 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',],
# 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
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').
@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
$ 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 / 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
@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 / isEmail.js
Created July 29, 2015 09:18
Check if string is an email.
function isEmail(email){
// http://www.w3.org/TR/html-markup/input.email.html
var emailReg = /^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/
return emailReg.test(email);
}
@makmac213
makmac213 / Odesk Api Callback URL Workaround (Django)
Last active August 29, 2015 14:20
Odesk Api Callback URL Workaround (Django)
class OdeskView(View):
class LinkAccount(View):
def get(self, request, *args, **kwargs):
client = odesk.Client(settings.ODESK_API_KEY,
settings.ODESK_API_SECRET)
url = client.auth.get_authorize_url()
# need to store request token and request token secret
# so that callback url will not raise exception
@makmac213
makmac213 / toc.html
Created October 6, 2014 15:57
TOC generator based from https://github.com/matthewkastor/html-table-of-contents. Only changed function to accept a string id of the element to be parsed.
<html>
<head>
<style type="text/css">
#toc .h1 {
font-size: 20px;
font-weight: bold;
text-indent: .25in;
}