Skip to content

Instantly share code, notes, and snippets.

View JustOnce's full-sized avatar
💭
Getting things done

Denis Nikanorov JustOnce

💭
Getting things done
View GitHub Profile
@JustOnce
JustOnce / class.py
Created April 26, 2018 20:26
Openpyxl copy worksheet to another
@staticmethod
def copy_range(ws_source, ws_target, source_range, target_start):
start_col, start_row, _, _ = range_boundaries(target_start)
for row, row_cells in enumerate(ws_source[source_range], start_row):
for column, cell in enumerate(row_cells, start_col):
target_cell = ws_target.cell(row=row, column=column)
target_cell.value = cell.value
target_cell.font = cell.font
from health_web.utils import send_email
send_email('EMAIL TEST', 'TEST EMAIL', ['test@yandex.ru'])
@JustOnce
JustOnce / cors.py
Created June 12, 2016 19:54 — forked from miraculixx/cors.py
To enable CORS support in django-tastypie, use the following code snipet. Then create your tastypie resources as a subclass of BaseCorsResource.Basic code courtesy Daniel Conzalez of http://codeispoetry.me/index.php/make-your-django-tastypie-api-cross-domain/.I added documentation and the post_list method.
'''
Add CORS headers for tastypie APIs
Usage:
class MyModelResource(CORSModelResource):
...
class MyResource(CORSResource):
...
@JustOnce
JustOnce / gist:2b1f34c664bf48e3e6fd
Created November 23, 2015 22:22
How to fix Ubuntu/Debian apt-get 404 Not Found Package Repository Errors (Saucy, Raring, Quantal, Oneiric, Natty…)
Ubuntu End of Life Package Repository
If you’re using a normal version of Ubuntu such as Saucy, Raring, Quantal, Oneiric, Natty, Maverick, etc, you may have already (and will eventually) start getting “Failed to fetch 404 Not Found” errors when trying to run apt-get update , or even sometimes running apt-get install , but fear not, it is easy to fix, and here’s how…
Why am I getting this error?
Normal Ubuntu releases are supported for 9 months, whereas LTS (Long Term Support) releases are supported for 5 years. Once support is up for the version of Ubuntu you are using the repository is moved to another server and will no longer be available on the standard http://archive.ubuntu.com/ubuntu/dist/ location.
Ubuntu Release Details
The most simple solution would be to upgrade to a newer version:
from openpyxl.styles import Alignment, Font, Border, Side, PatternFill
from openpyxl.workbook import Workbook
from openpyxl import load_workbook, drawing
from lxml.html import document_fromstring, HTMLParser
# Value must be one of set(['hair', 'medium', 'dashDot', 'dotted', 'mediumDashDot', 'dashed',
# 'mediumDashed', 'mediumDashDotDot', 'dashDotDot', 'slantDashDot', 'double', None, 'thick', 'thin'])
_BORDER_STYLE = {
'0': None,
'1': 'thin',
@JustOnce
JustOnce / 1.html
Created May 2, 2015 12:12
html2excel
<table border="1">
<tr>
<td>1 </td>
<td>1 </td>
<td>1 </td>
<td align="center" rowspan="4">Thing</td>
<td>1 </td>
</tr>
<tr>
<td>2 </td>
@JustOnce
JustOnce / update.sh
Created April 6, 2015 12:37
Update static cache
find . -print -exec touch {} \;
@JustOnce
JustOnce / classes.py
Last active December 20, 2015 20:12
Crop image django model
from PIL import Image
class CropImageModel(CleanupFileModel):
class Meta:
abstract = True
def _get_crop_fields(self):
for field in self._meta.fields:
if isinstance(field, models.ImageField) and getattr(self, field.name + '_width', None) and \
If your network connection blocks both outbound TCP ports 25 and 587 but allows outgoing TCP port 465, you need your e-mail server to relay mail through a smarthost using SMTPS. Unfortunately, new versions of Postfix no longer natively support using an SMTPS smarthost. Gather the server name, username, and password for your SMTPS-enabled smarthost, then follow these directions for a quick fix.
In this example, I’m using the Comcast SMTP server as my smarthost — replace smtp.comcast.net:465 with the mail server you wish to use as a smarthost.
Install stunnel and Postfix with sudo apt-get install stunnel mailutils postfix
If you weren’t automatically prompted to configure Postfix, run sudo dpkg-reconfigure postfix to access the configuration wizard. Configure Postfix as a “Satellite system”. You must enter a valid domain name for “System mail name”, so use example.com. For “SMTP relay host”, enter [127.0.0.1]:10465
Enable stunnel automatic startup. Run sudo vim /etc/default/stunnel4 and change ENABLED=0 to EN
import os
from itertools import ifilter
from PIL import Image
from django.db import models
from django.db.transaction import atomic
class CleanupFileModel(models.Model):