Skip to content

Instantly share code, notes, and snippets.

View oxalorg's full-sized avatar
:shipit:
Always Be Coding

Mitesh oxalorg

:shipit:
Always Be Coding
View GitHub Profile
@ryanpitts
ryanpitts / gist:1304725
Created October 21, 2011 19:34
GROUP BY and Select MAX from each group in Django, 2 queries
'''
given a Model with:
category = models.CharField(max_length=32, choices=CATEGORY_CHOICES)
pubdate = models.DateTimeField(default=datetime.now)
<other fields>
Fetch the item from each category with the latest pubdate.
'''
@bclinkinbeard
bclinkinbeard / release.sh
Created November 1, 2011 20:22
Bash script to automate the Git Flow tag/release process
#!/bin/bash
# current Git branch
branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
# v1.0.0, v1.5.2, etc.
versionLabel=v$1
# establish branch and tag name variables
devBranch=develop
@jamescasbon
jamescasbon / template.py
Created December 11, 2011 16:37
Pure python templates using with statement
"""
A really stupid python template language inspired by coffeekup, markaby.
Do not use this code, it will ruin your day. A byproduct of insomnia.
TL;DR
-----
This module defines a template language that allows us to do:
d = Doc()
@sanchitgangwar
sanchitgangwar / snake.py
Created March 22, 2012 12:38
Snakes Game using Python
# SNAKES GAME
# Use ARROW KEYS to play, SPACE BAR for pausing/resuming and Esc Key for exiting
import curses
from curses import KEY_RIGHT, KEY_LEFT, KEY_UP, KEY_DOWN
from random import randint
curses.initscr()
win = curses.newwin(20, 60, 0, 0)
@paulhodge
paulhodge / gist:2770949
Created May 22, 2012 18:57
vim: open a file using the date as filename
" type :L to open a file at ~/notes/log/<current date>
fun! OpenLog()
let fname = strftime("%Y_%m_%d")
exe ":e ~/notes/log/" . fname
endfun
command L call OpenLog()
@lost-theory
lost-theory / gist:3005268
Created June 27, 2012 16:35
consume JSON REST API blueprint inside flask app
from flask import Flask, jsonify, Blueprint, current_app
import json
## REST api ###################################################################
api = Blueprint('api', __name__)
@api.route("/users")
def users():
return jsonify(users=[
@mjul
mjul / application.py
Created December 10, 2014 12:36
Configure a Python Flask application to use the associated Amazon RDS Postgres (or MySQL) database when running on Elastic Beanstalk (inside Docker).
driver = 'mysql+pymysql://'
driver = 'postgresql+psycopg2://'
app.config['SQLALCHEMY_DATABASE_URI'] = driver \
+ os.environ['RDS_USERNAME'] + ':' + os.environ['RDS_PASSWORD'] \
+'@' + os.environ['RDS_HOSTNAME'] + ':' + os.environ['RDS_PORT'] \
+ '/' + os.environ['RDS_DB_NAME']
@dmn001
dmn001 / market_history_json_parse.py
Last active June 27, 2016 11:48
parse sold item date, name and price
import json
from bs4 import BeautifulSoup
import re
of = open("all_output.txt", "wb")
for file_num in range(1,102):
filename = "%03d.json" % file_num
print filename
@pwm
pwm / openresty
Last active March 3, 2023 22:39
openresty init script
#!/bin/bash
#
# chkconfig: 2345 55 25
# description: Openresty
# processname: nginx
# config: /usr/local/openresty/nginx/conf/nginx.conf
# pidfile: /usr/local/openresty/nginx/logs/nginx.pid
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network $named $syslog $time
@zkendall
zkendall / ansible-dynamic-to-static.py
Last active October 9, 2018 17:23
Script to convert the output of Ansible's ec2 dynamic inventory to a flat static inventory.
#!/usr/bin/env python
'''
This script converts the output of Ansible's dynamic ec2.py to a flatly formmated static inventory file.
Before running this script run `python ./ec2.py --refresh-cache > ec2-dynamic.json`
See: http://docs.ansible.com/ansible/ec2_module.html
'''