Skip to content

Instantly share code, notes, and snippets.

View hunt3ri's full-sized avatar

Iain Hunter hunt3ri

View GitHub Profile
@hunt3ri
hunt3ri / git-tag.sh
Created May 2, 2018 10:17
Tag git branch
# Tag Prod version
git tag -a v1.0 -m "v1.0 deployed to $ENV"
git push origin v1.0
@hunt3ri
hunt3ri / full_text_search.py
Last active June 27, 2017 22:19
Simple Python3 CLI for searching using Postgres and SQLAlchemy
import argparse
from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.dialects.postgresql import TSVECTOR
from sqlalchemy.orm import sessionmaker
# Create DB Session
engine = create_engine('postgresql://iain:password@localhost:5432/Real-World')
Session = sessionmaker(bind=engine)
session = Session()
@hunt3ri
hunt3ri / sports_articles.sql
Created May 29, 2017 22:16
Create sports article table
CREATE TABLE IF NOT EXISTS sports_articles(
id BIGSERIAL PRIMARY KEY,
title VARCHAR(100),
article VARCHAR(2000));
Insert into sports_articles (title, post) values('Francesco Totti brings down curtain on "something beautiful" at Roma', 'Francesco Totti tried to raise a smile. Striding out on to the Stadio Olimpico pitch for a farewell address at the end of his last-ever match for Roma, he shushed the home crowd and then teased that staying quiet “ought to be easy for you”.');
Insert into sports_articles (title, post) values('Brendan Rodgers pays tribute to Barcelona after Celtic are thrashed', 'Brendan Rodgers said that Barcelona “beat you up with the ball” on a night on which he likened the Camp Nou pitch to an ice-rink, the game whizzing past his helpless players. Celtic fell to a 7-0 defeat but their manager insisted that there was “no embarrassment” and that he could not have asked for any more from his team.');
Insert into sports_articles (title, post) values('Arsenal board expected to ru
@hunt3ri
hunt3ri / pg_restore_to_aws.sql
Last active May 23, 2017 22:54
Restore postgres db using pgrestore
pg_restore --host=<youHost>.eu-west-1.rds.amazonaws.com --port=5432 --username=<yourAdminUser> --password --dbname=<yourDB> /data-loader/dumpfile.dmp
@hunt3ri
hunt3ri / docker-commands.sh
Last active May 23, 2017 22:52
Build, run and connect postgres docker file
mkdir data-load
vi Dockerfile # Copy Docker commands listed above into your local Dockerfile
docker build -t postgres-db .
docker run -d -v /Users/iainhunter/dev/docker/postgres/data-load:/data-loader -p 5432:5432 postgres-db
docker ps
docker exec -it <imageId> bash
@hunt3ri
hunt3ri / Dockerfile
Created May 22, 2017 23:20
postgres dockerfile
FROM postgres
ENV POSTGRES_USER postgres
ENV POSTGRES_PASSWORD password
@hunt3ri
hunt3ri / manage.py
Created October 31, 2016 11:26
Add profiling to Python Flask app
@manager.command
def profile(length=500, profile_dir=None):
"""Start the application under the code profiler."""
from werkzeug.contrib.profiler import ProfilerMiddleware
application.wsgi_app = ProfilerMiddleware(application.wsgi_app, restrictions=[length], profile_dir=profile_dir,
sort_by=('time', 'calls'))
application.run()
@hunt3ri
hunt3ri / mongo-dock.sh
Last active January 12, 2016 22:50
Docker command to run mongo on OSX
docker run --name my-local-mongo -v mongo-data:/data/db -p 27017:27017 -d mongo
@hunt3ri
hunt3ri / hello-tornado.py
Created November 8, 2012 22:17
Tornado hello world
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, Python3")
application = tornado.web.Application([
(r"/", MainHandler),
])
@hunt3ri
hunt3ri / bash_profile.sh
Created November 8, 2012 22:09
Add pip3 to path
export PATH=/Library/Frameworks/Python.framework/Versions/3.3/bin:$PATH