Skip to content

Instantly share code, notes, and snippets.

View archatas's full-sized avatar

Aidas Bendoraitis archatas

View GitHub Profile
@archatas
archatas / add_css_dynamically.js
Last active August 31, 2016 11:07
Add CSS rules dynamically
/**
* Add CSS rules dynamically
* Example:
* dyn_css_rule("#menu li:hover", "color: red")
*/
window.dyn_css_rule = function(sSelector, sCssText) {
try {
var aSS = document.styleSheets;
var i;
for (i=aSS.length-1; i>=0; i--) {
import os
from fabric.api import env, run, prompt, local, get
from fabric.state import output
env.environment = ""
env.hosts = ["example.com"]
env.user = "admin"
env.full = False
output['running'] = False
@archatas
archatas / backup_db.sh
Last active February 6, 2017 21:07
Bash script to save database backups for every day of the week in files like 1-Monday.sql, 2-Tuesday.sql, etc. This should be executed daily as a cron job.
#! /usr/bin/env bash
SECONDS=0
PROJECT_PATH=/home/example
CRON_LOG_FILE=${PROJECT_PATH}/logs/backup_db.log
BACKUP_PATH=${PROJECT_PATH}/db_backups/$(LC_ALL=en_US.UTF-8 date +"%w-%A").sql
USER=dbusername
DATABASE=dbname
PASS=dbpassword
EXCLUDED_TABLES=(
@archatas
archatas / requests_fix.py
Created August 31, 2016 11:06
Fixing SSL certificate issues in requests library
# In case of SSL errors in Python requests library:
# (myenv)$ pip install certifi
# Then add the following to your Django settings:
import os, certifi
os.environ['REQUESTS_CA_BUNDLE'] = certifi.where()
@archatas
archatas / admin.py
Last active December 14, 2016 01:11
Django administration inlines for inlines
# -*- coding: UTF-8 -*-
from django.contrib import admin
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.text import force_text
from .models import Painter, Picture, Review
def get_picture_preview(obj):
if obj.pk: # if object has already been saved and has a primary key, show picture preview
@archatas
archatas / cleanup.sh
Created February 6, 2017 21:15
Django management commands scheduled and with logging
#!/usr/bin/env bash
SECONDS=0
PROJECT_PATH=/home/myproject
CRON_LOG_FILE=${PROJECT_PATH}/logs/cleanup.log
echo "Cleaning up the database" > ${CRON_LOG_FILE}
date >> ${CRON_LOG_FILE}
cd ${PROJECT_PATH}
source bin/activate
@archatas
archatas / nano_configuration.md
Created February 6, 2017 22:06
Instructions how to configure nano for more user friendliness

Why nano?

Nano is a simple and intuitive editor preinstalled on many Unix-based computers. All the necessary keyboard shortcuts are presented all the time in the footer of this program, so you don't get lost when you need to edit a file in the shell.

Make sure that you have syntax highlighting configuration files

Check for \*.nanorc files at one of the following directories:

@archatas
archatas / StairCaseBuilder.cs
Last active June 5, 2021 16:24
Build a spiral staircase to the sky in Unity3d.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/*
Attach this script to an empty object positioned at where you want to have the bottom center of the staircase.
Drag a prefab of a step of the staircase to the "Step Prefab" field.
The prefab of a step could simply be a cube with position scale to (2.5, 0.2, 2.5).
*/
@archatas
archatas / base.py
Last active April 6, 2017 23:06
Random unique string ID mixin for Django models
# -*- coding: UTF-8 -*-
from __future__ import unicode_literals
import shortuuid
from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _
RANDOM_UNIQUE_ID_LENGTH = getattr(settings, "RANDOM_UNIQUE_ID_LENGTH", 12)
@archatas
archatas / postgres-cheatsheet.md
Created April 27, 2017 15:46 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

If run with -E flag, it will describe the underlaying queries of the \ commands (cool for learning!).

Most \d commands support additional param of __schema__.name__ and accept wildcards like *.*