Skip to content

Instantly share code, notes, and snippets.

@Alexx-G
Alexx-G / mountdb.sh
Created August 20, 2014 08:46
Mount/Umount mysql databases into ramdisk
#!/bin/sh
#stop mysql service
service mysql stop
#mount ramdisk
mkdir -p /tmp/db_ramdisk
mount -t tmpfs -o size=512M tmpfs /tmp/db_ramdisk
#create back-up
function searchBox() {
var box = $("#box");
if (box.length > 0) {
var elements = box.find("span");
var lvl = box.attr("class");
for(var i = 0; i < elements.length - 1; i++) {
if($(elements[i]).attr("style") != $(elements[i + 1]).attr("style")) {
$(elements[i]).click();
if(lvl == box.attr("class")) {
$(elements[i + 1]).click();
@Alexx-G
Alexx-G / postgreSQL_configuration.rst
Last active August 29, 2015 14:14
PostgreSQL configuration tutorial

Install PostgreSQL

  1. Install dependencies

    sudo apt-get install libpq-dev python-dev

    Note: If you're using python3, then use python-dev for python 3.

  2. Install PostgreSQL
@Alexx-G
Alexx-G / .gitignore
Created March 10, 2015 11:20
My gitignore file for django projects
# Python
*.py[cod]
venv/
__pycache__/
# Packages
dist/
lib/
lib64/
@Alexx-G
Alexx-G / serializers.py
Last active August 18, 2022 00:28
Mixin for creating serializers with configurable fields (for the django rest framework).
"""
Some helper serializer mixins.
Helps to reuse serializers for different purposes.
"""
import logging
from rest_framework import serializers
LOGGER = logging.getLogger(__name__)
@Alexx-G
Alexx-G / settings.py
Last active August 29, 2015 14:19
Simple django logging configuration
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(levelname)s | %(asctime)s | %(name)s:%(funcName)s | %(process)d | %(thread)d | %(message)s'
},
'simple': {
'format': '%(levelname)s | %(name)s | %(message)s'
},
@Alexx-G
Alexx-G / django-startproject.sh
Last active August 29, 2015 14:23
A bash script for easier setup of the new django project.
#!/bin/bash
read -p "Project's folder (press Enter to install in current folder): " project_folder </dev/tty ;
read -p "Project name (required - letters, numbers underscore): " project_name </dev/tty ;
if [ -n "$project_folder" ]; then
mkdir $project_folder; cd $project_folder;
fi
@Alexx-G
Alexx-G / middlewares.py
Last active October 12, 2018 09:30
A Django middleware for logging exceptions.
# -*- coding: utf8 -*-
from __future__ import unicode_literals
import logging
import sys
import traceback
LOGGER = logging.getLogger(__name__)
@Alexx-G
Alexx-G / login.html
Last active January 24, 2022 14:30
Login redirect with user friendly alerts
{% for message in messages %}
{# Login redirect alert.#}
{# We have to display only the last message. Other are irelevant, but must be iterated #}
{% if 'login_required' in message.tags and forloop.last %}
<div class="alert alert-info alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
{{ message }}
</div>
@Alexx-G
Alexx-G / deployment.log
Created February 18, 2016 22:40
Heroku-like deployments on dedicated servers using git-deploy
emote: HEAD is now at e766da0 Move confirmed booking rendering in the same view.
remote: files changed: 5
remote: ============================================
remote: Exporting needed config variables (from .env)
remote: ============================================
remote: ============================================
remote: Installing nodejs dependencies
remote: ============================================
....
remote: [00:25:56] Using gulpfile /var/www/bakimli/gulpfile.js