postgresql - Querying non-ASCII rows from Postgres - Database Administrators Stack Exchange
SELECT
t, regexp_replace(t, '([^[:ascii:]])', '[\1]', 'g') AS t_marked
FROM
t
WHERE
t ~ '[^[:ascii:]]' ;
postgres  sql  regex  unicode  ascii  query 
24 days ago
latex - Pandoc markdown page break - Stack Overflow
--- Return a block element causing a page break in the given format.
local function newpage(format)
if format == 'docx' then
local pagebreak = '<w:p><w:r><w:br w:type="page"/></w:r></w:p>'
return pandoc.RawBlock('openxml', pagebreak)
elseif format:match 'html.*' then
return pandoc.RawBlock('html', '<div style=""></div>')
elseif format:match '(la)?tex' then
return pandoc.RawBlock('tex', '\\newpage{}')
elseif format:match 'epub' then
local pagebreak = '<p style="page-break-after: always;"> </p>'
return pandoc.RawBlock('html', pagebreak)
else
-- fall back to insert a form feed character
return pandoc.Para{pandoc.Str '\f'}
end
end

-- Filter function called on each RawBlock element.
function RawBlock (el)
-- check that the block is TeX or LaTeX and contains only \newpage or
-- \newpage{} if el.format:match '(la)?tex' and content:match
-- '\\newpage(%{%})?' then
if el.text:match '\\newpage' then
-- use format-specific pagebreak marker. FORMAT is set by pandoc to
-- the targeted output format.
return newpage(FORMAT)
end
-- otherwise, leave the block unchanged
return nil
end
pandoc  markdown  word  output  page  break  filter  lua 
28 days ago
[Python-Dev] python 3 niggle: None < 1 raises TypeError
None is special in Python and has always (and intentionally) sorted
before any other object. In data processing and elsewhere in Python
programming, it's used to signal: no value available.

Python 3 breaks this notion by always raising an exception when
using None in an ordered comparison, making it pretty much useless
for the above purpose.

Yes, there are ways around this, but none of them are intuitive.

Here's a particularly nasty case:

>>> l = [(1, None), (2, None)]
>>> l.sort()
>>> l
[(1, None), (2, None)]

>>> l = [(1, None), (2, None), (3, 4)]
>>> l.sort()
>>> l
[(1, None), (2, None), (3, 4)]

>>> l = [(1, None), (2, None), (3, 4), (2, 3)]
>>> l.sort()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unorderable types: int() < NoneType()
python  python3  none  sort  unorderable 
5 weeks ago
Example of using django-sorting, django-filter and django-pagination together · GitHub
{% load pagination_tags %}
{% load sorting_tags %}

{% block body %}

{% autosort filter.qs as sorted_objects %}
{% autopaginate sorted_objects 10 as object_list %}

{% for object in object_list %}
{{ object }}
{% endfor %}

{% paginate %}

{% endblock %}

{% block sidebar %}
<div class="filter">
<h2>Sort by</h2>
<ul>
<li>{% anchor firstfield "First Field" %}</li>
<li>{% anchor otherfield "Other Field" %}</li>
</ul>
<form action="" method="get" class="filter">
{{ filter.form.as_p }}
</form>
</div>
{% endblock %}
django  django-pagination  django-filter  django-sorting  sort  filter  paginate  example  python3 
5 weeks ago
Software Folklore ― Andreas Zwinkau
Software Folklore
Sometimes bugs have symptoms beyond belief. This is a collection of such stories from around the web
stories  bug  debugging  software  byzantine  failure 
6 weeks ago
A familiar HTTP Service Framework — responder 1.0.4 documentation
Features¶
A pleasant API, with a single import statement.
Class-based views without inheritence.
ASGI framework, the future of Python web services.
The ability to mount any ASGI / WSGI app at a subroute.
f-string syntax route declaration.
Mutable response object, passed into each view. No need to return anything.
Background tasks, spawned off in a ThreadPoolExecutor.
GraphQL (with GraphiQL) support!
OpenAPI schema generation, with interactive documentation!
Single-page webapp support!
python  programming  web  framework  api  requests 
6 weeks ago
up/README.md at master · akavel/up
up is the Ultimate Plumber, a tool for writing Linux pipes in a terminal-based UI interactively, with instant live preview of command results.

The main goal of the Ultimate Plumber is to help interactively and incrementally explore textual data in Linux, by making it easier to quickly build complex pipelines, thanks to a fast feedback loop. This is achieved by boosting any typical Linux text-processing utils such as grep, sort, cut, paste, awk, wc, perl, etc., etc., by providing a quick, interactive, scrollable preview of their results
cli  tools  linux  bash 
6 weeks ago
ServiceNow Design System
Use like this

<span class="icon-vcr-right" style="font-size:13px;"></span>
servicenow  icon  style  glyph  set  library 
8 weeks ago
Discrepancy in original headers and playback headers (bytes vs. strs) · Issue #122 · betamaxpy/betamax · GitHub
I'm getting an error from Betamax when it tries to record header values that are bytes instead of native unicode strings (in python 3).

TypeError: b'xj8h' is not JSON serializable

This is a pull request that has some links to an example of a binary serializer that someone wrote. Also, coming in Betamax 0.9.0, there are some changes in the core library to allow binary serializers to specify that they deal in binary (bytes), not text (strings).
python  betamax  unicode  header  bytes  string  json  encode  serialize  serializer 
8 weeks ago
orm - Unique fields that allow nulls in Django - Stack Overflow
class CharNullField(models.CharField):

"""
Subclass of the CharField that allows empty strings to be stored as NULL.
"""

description = "CharField that stores NULL but returns ''."

def from_db_value(self, value, expression, connection, contex):
"""
Gets value right out of the db and changes it if its ``None``.
"""
if value is None:
return ''
else:
return value


def to_python(self, value):
"""
Gets value right out of the db or an instance, and changes it if its ``None``.
"""
if isinstance(value, models.CharField):
# If an instance, just return the instance.
return value
if value is None:
# If db has NULL, convert it to ''.
return ''

# Otherwise, just return the value.
return value

def get_prep_value(self, value):
"""
Catches value right before sending to db.
"""
if value == '':
# If Django tries to save an empty string, send the db None (NULL).
return None
else:
# Otherwise, just pass the value.
return value
django  char  null  field  blank  text  string  db  sql  none  custom  orm 
9 weeks ago
vimrc - Opening a vertical terminal in Vim 8.1 - Unix & Linux Stack Exchange
:vert term

:vertical works with any command that splits a window, for example:

:vert copen
:vert help vert
vim  vertical  split  bash  terminal  window 
10 weeks ago
Reading output of a command into an array in Bash - Stack Overflow
my_array=()
while IFS= read -r line; do
my_array+=( "$line" )
done < <( my_command )
bash  command  array  output 
11 weeks ago
pytz: The Fastest Footgun in the West
Article from 2018 explaining why we should be using dateutil.tz instead of pytz.
python  timezone  pytz  dateutil  dateutil.tz  utc 
11 weeks ago
stdout - Write lines to a file from less - Unix & Linux Stack Exchange
10Gmm1G|mcat > outfile.txt

(typed within less) seems to work as long as the input doesn't fit in one screen (in which case all the input ends up in outfile.txt for some reason).

10G brings you to line 10
mm sets the m mark there
1G (same as g in this case) brings you to line 1
|m pipe from the current line to mark m
cat > outfile.txt: that's piped to that command.
unix  less  write  lines  to  file  log 
11 weeks ago
PyPika - Python Query Builder — PyPika 0.15.5 documentation
PyPika is a Python API for building SQL queries. The motivation behind PyPika is to provide a simple interface for building SQL queries without limiting the flexibility of handwritten SQL. Designed with data analysis in mind, PyPika leverages the builder design pattern to construct queries to avoid messy string formatting and concatenation. It is also easily extended to take full advantage of specific features of SQL database vendors.
python  sql  orm  query  builder  pika 
11 weeks ago
The Most Diabolical Python Antipattern – Real Python
# The Python 3 version. It's a little less work.
import traceback

def log_traceback(ex):
tb_lines = traceback.format_exception(ex.__class__, ex, ex.__traceback__)
tb_text = ''.join(tb_lines)
# I'll let you implement the ExceptionLogger class,
# and the timestamping.
exception_logger.log(tb_text)

try:
x = get_number()
except Exception as ex:
log_traceback(ex)
python  log  exception  traceback 
12 weeks ago
math-as-code
cheat-sheet for mathematical notation in code form
javascript  math  notation  explained  code 
12 weeks ago
Charles Dickens’Pets
But I think his strongest love, among animals, was for dogs. I find a delightful
anecdote told by him of a dog belonging to a lady whom he knew well, ”Of”, an
immense, black, good-humored, Newfoundland dog. He came from Oxford and
had lived all his life in a brewery. Instructions were given with him that if he were
let out every morning alone he would immediately find out the river, regularly taken
a swim and come gravely home again. This he did with the greatest punctuality, but
after a little while was observed to smell of beer. His owner was so sure that he
smelled of beer that she resolved to watch him. He was seen to come back from
his swim round the usual corner and to go up a fight of steps into a beer shop.
Being instantly followed, the beer shopkeeper is seen to take down a pot (pewter pot)
and is heard to say: ”Well, old chap, come up for your beer as usual, have you?”
Upon which he draws a pint and puts it down and the dog drinks it.
Being required to explain how this comes to pass the man says: ”Yes, ma´am.
I know he´s your dog, but I didn´t when he first came. He looked in, ma´am, as
a brickmaker might, and
he wagged his tail at the pots, and he giv a sniff round and conveyed to me as was
used to beer. So I draw´d him a drop, and he drunk it up. Next morning he came
again by the clock and I draw´d him a pint, and ever since he has took his pint reg´lar.”


Mamie Dickens: My Father as I recall Him
Chapter IV
E.P.Dutton & Co. New York 1897
charles  dickens  biography  mamie  newfoundland  dog  beer 
12 weeks ago
postgresql - Auto-truncating fields at max_length in Django CharFields - Stack Overflow
class TruncatingCharField(models.CharField):
def get_prep_value(self, value):
value = super(TruncatingCharField,self).get_prep_value(value)
if value:
return value[:self.max_length]
return value
django  truncate  field  database 
september 2018
GRAPPELLI ADMIN INTERFACE
Turn Django admin interface in to a CMS. Edit, add, and delete rows with a nice interface.
django  admin  interface  edit  cms 
september 2018
soap - Is there a way to provide an external WSDL file to a Python Suds client - Stack Overflow
Read wsdl from a local file, and then set the location that the service should query using `client.set_options(location=url)`
python  soap  suds  wsdl  file 
august 2018
Documentation – suds
Internet Archive Wayback Machine snapshot of the old Suds documentation that used to be hosted at https://fedorahosted.org/suds/wiki/Documentation
suds  python  documentation  wayback_machine  soap  archive 
august 2018
« earlier      
annoyances ansible apache api apple application async asyncio audio automation backup bash blog book branch browser bug cd celery certificate chart cheatsheet cli client code command commit computer config configuration convert copy css culture data database dead debian debug debugging deployment design development diff diy django docs documentation download drive driver editor education email environment error example fabric file filter firefox flask food format forum forwarding framework france fun function game games ghibli gif git github google graph guide hardware hg howto html html5 http import install internet ios java javascript key keyboard kids ldap library line linux list local log low_power_server mac make manager map markdown memory merge microsoft mock monitor multiple music network nginx odbc online openssl oracle osx package pandas path pc pdf performance phone pick_pack pip plsql plugin port postgres postscript programming puppet putty pytest python python3 query radio recipe redhat reference regex remote requests rest review science screen script scripting search security selenium server service setup shell shopping soap software sound sql ssd ssh ssl stream string subversion sudo svn syntax template terminal test testing text time tips tmux tool tools trace transfer troubleshooting tutorial twisted ubuntu unicode unix upgrade user utilities utility vagrant vba version vi video vim virtualenv vmware vpn web windows workflow xp

Copy this bookmark:



description:


tags: