Skip to content

Instantly share code, notes, and snippets.

View aruseni's full-sized avatar
🟢
Lead Python Software Engineer

aruseni

🟢
Lead Python Software Engineer
View GitHub Profile
# -*- coding: utf-8 -*-
def transliterate(string):
capital_letters = {u'А': u'A',
u'Б': u'B',
u'В': u'V',
u'Г': u'G',
u'Д': u'D',
u'Е': u'E',
# -*- coding: utf-8 -*-
import re
def transliterate(string):
capital_letters = {u'А': u'A',
u'Б': u'B',
u'В': u'V',
u'Г': u'G',
# -*- coding: utf-8 -*-
def transliterate(string):
capital_letters = {u'А': u'A',
u'Б': u'B',
u'В': u'V',
u'Г': u'G',
u'Д': u'D',
u'Е': u'E',
These strings are not present in any other template or Python file, so you just put them here in order to make the makemessages management command keep them in the translation file.
{% load i18n %}
{% trans "Some string you want to keep in the django.po translation file" %}
{% trans "So makemessages won't comment it out each time you run it" %}
{% trans "This template does not have to be used anywhere, putting it in your templates directory is enough" %}
@aruseni
aruseni / deep_get.py
Created April 4, 2019 09:32
Gets a value following the specified path, if such value exists
def deep_get(dictionary, keys, default=None):
"""
Gets a value following the specified path, if it exists.
The keys are dot-separated.
Example:
deep_get({'most_visited': {'url': 'https://test.com/'}}, 'most_visited.url')
"""
@aruseni
aruseni / replace_text_nodes.py
Created September 19, 2018 14:47
A Python script that replaces all text nodes inside a `template` element with [TXT], used with Vue templates
import argparse
parser = argparse.ArgumentParser(description='Replace text nodes')
parser.add_argument('file', type=str)
args = parser.parse_args()
html = open(args.file).read()
def replace(content):
@aruseni
aruseni / motd.sh
Created April 14, 2014 01:35
/etc/profile.d/motd.sh — a simple script for displaying dynamic messages shown on login
# No need to redisplay it on sudo su and in screen sessions
if [ "$(id -u)" != "0" ] && [[ ! $TERMCAP =~ screen ]]; then
/etc/motd.tcl
fi
@aruseni
aruseni / admin.py
Last active October 19, 2017 18:00
Substituting Django User model
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.utils.translation import ugettext_lazy as _
from .forms import UserChangeForm, UserCreationForm
from .models import User
@aruseni
aruseni / get_credentials.py
Created April 23, 2014 19:19
Requirements: BeautifulSoup. progressbar
import sys
import httplib2
import urllib
import hashlib
import re
import itertools
from BeautifulSoup import BeautifulSoup
import progressbar
@aruseni
aruseni / fields.py
Created February 8, 2017 16:23
This is a TextField-based field with TextInput widget. This can be used instead of a CharField whenever you do not want to restrict the length of the content at the DB level (see http://stackoverflow.com/questions/4848964/postgresql-difference-between-text-and-varchar-character-varying for more info).
from django.db import models
from django import forms
class TextInputTextField(models.TextField):
def formfield(self, **kwargs):
kwargs.update({
"widget": forms.TextInput
})