Skip to content

Instantly share code, notes, and snippets.

@smailq
smailq / crontab
Last active November 3, 2016 16:09
# Pull new code from repository, build docker image, and start new container with new image
*/5 * * * * cd /home/ec2-user/myproject; make pull 2>&1 >> /home/ec2-user/deployment.log
@smailq
smailq / post-merge
Last active November 3, 2016 16:08
Build and run newly built image
#!/bin/bash
# Get current git sha
GIT_COMMIT=$(git rev-parse HEAD)
# Build docker image, then stop exisitng container, then run new container
make build; make stop; make run;
# Report to Slack about deployment
curl -s -X POST --data-urlencode 'payload={"channel": "#dev-ops", "username": "Staging Server", "text": "Commit '$GIT_COMMIT' has been pushed to http://some-project-home.com", "icon_emoji": ":floppy_disk:"}' https://hooks.slack.com/[slack-hook-url]
@smailq
smailq / Makefile
Created October 17, 2016 19:01
Simple Makefile for maintaining a Docker image
# Get git commit SHA
GIT_COMMIT = $(shell git rev-parse HEAD)
# Build docker image
build:
docker build -f Dockerfile -t someorg/myproject:$(GIT_COMMIT) .
# Run docker image, exposing port 80 of container image to port 80 of the host
run:
docker run --name myproject -p 80:80 -d someorg/myproject:$(GIT_COMMIT)
@smailq
smailq / Dockerfile
Last active March 12, 2019 23:06
Docker image for Nginx + php-fpm + composer managed with Supervisord
# Dockerfile for Nnginx + PHP + Composer
#
# Installs Nginx and PHP from official sources.
# Runs nginx and php with supervisord.
#
# Various configuration files are placed under : docker_support_files/
#
# Source files in :
# public - Public facing files (nginx root for static files)
# src - PHP source files
@smailq
smailq / Not_good.coffee
Created January 22, 2013 23:54
Variables defined in for-loops are accessible from callbacks for `exec` function, however, contents of those variables change as the loop progresses and updates the variable.
exec = require('child_process').exec
some_list = [1,2,3]
for i in some_list
exec "ls", (err, stdout, stderr) ->
console.log i
# The result is NOT always
#
@smailq
smailq / gist:4599943
Created January 22, 2013 23:39
Terminate existing connections to postgresql.
SELECT pg_terminate_backend(pg_stat_activity.procpid) FROM pg_stat_activity WHERE datname = '';
@smailq
smailq / summerize.py
Last active December 10, 2015 00:49
Create a summary (Name, High Concept, Company URL, Angellist URL) from results of Angel.co's Startup API.
"""
Create a summary (Name, High Concept, Company URL, Angellist URL) from results
of Angel.co's Startup API.
Reads all `*.json` from current directory and produces `summary.tsv` in the same directory.
Raw data is fetched from : https://api.angel.co/1/tags/1702/startups?page=1&per_page=50
Tag 1702 : Toronto
"""
// main.soy
{namespace main}
/**
* Header
* @param name Name of the person
*/
{template .header}