Skip to content

Instantly share code, notes, and snippets.

View exhuma's full-sized avatar
🐢
Slowly advancing on hobby projects

Michel Albert exhuma

🐢
Slowly advancing on hobby projects
View GitHub Profile
@exhuma
exhuma / Main.java
Created May 15, 2015 15:04
"Flowing" RecyclerView
public class LostMobile extends Activity {
// [... snip ...]
mMainRecycler = (RecyclerView) findViewById(R.id.mainList);
mMainRecycler.setHasFixedSize(true);
mMainRecycler.setLayoutManager(new LinearLayoutManager(this));
mMainListAdapter = new MyAdapter(this, remoteMap);
// [... snip ...]
mMainRecycler.setAdapter(mMainListAdapter);
@exhuma
exhuma / tester.py
Created September 12, 2014 20:30
Cluster Tester
from __future__ import print_function
from difflib import SequenceMatcher
def mean(numbers):
"""
Returns the arithmetic mean of a numeric list.
see: http://mail.python.org/pipermail/python-list/2004-December/294990.html
"""
return float(sum(numbers)) / float(len(numbers))
@exhuma
exhuma / README.rst
Last active August 29, 2015 14:01
Closure RTE as part of a larger Component.

README

This example shows the use of a richtext-editor component as part of another, larger component.

The Problem

While the component shows up properly, the rendered IFRAME does not take up the full width of the editor. A wild guess is that the IFRAME is rendered before the width is available.

@exhuma
exhuma / idioms.rst
Last active August 29, 2015 13:55
Useful Python Idioms/caveats you might find useful if coming from another language.
┌─[10:15:19] michel@PC12-331
└─~/tmp› cat fabfile.py
import fabric.api as fab
fab.env.roledefs['staging'] = ['bbs-evolution.ipsw.dt.ept.lu']
fab.env.roledefs['prod'] = ['bbs-arbiter.ipsw.dt.ept.lu']
@fab.task
@exhuma
exhuma / colourised_log_example.py
Last active September 1, 2017 12:04
Simple python log formatter for colourised terminal output.
"""
Example for a colourised logging output.
This example uses "blessings" to handle console escape sequences. ``blessings``
itself is a very harmless package in that it does not have any external
dependencies. And it's code-base is very clean and small.
The example extends the core logging formatter (logging.Formatter) and
colourises the complete line. This takes advantage of any upstream updates
related to logging. When writing this against Python 2.7, the parent code
@exhuma
exhuma / example.py
Created December 11, 2013 08:33
Python urllib HTTPS request with proxies
HTTP_PROXY = {
"http": 'http://proxy.host:8888',
"https": 'http://proxy.host:8888'
}
def create(self, stanza, passwd):
'''
send xml data to ripe
return True on succes or HTTPError on error
@exhuma
exhuma / client.bash
Created November 11, 2013 10:50
URL decoding in Flask
clear && curl http://localhost:5000/foo+bar
curl http://localhost:5000/foo%20bar
class RepresentableBase(object):
"""
This class can be used by ``declarative_base``, to add an automatic
``__repr__`` method to *all* subclasses of ``Base``. This ``__repr__`` will
represent values as::
ClassName(pkey_1=value_1, pkey_2=value_2, ..., pkey_n=value_n)
where ``pkey_1..pkey_n`` are the primary key columns of the mapped table
with the corresponding values.
@exhuma
exhuma / gist:5875917
Created June 27, 2013 12:02
Redmine query aimed at the "my page" route.
-- The following query conbines the task due-date with the priority and sorts with the combined value.
SELECT id, project_id, subject, due_date, status_id,priority_id,author_id, priority_id * EXTRACT(EPOCH FROM AGE(due_date))
FROM issues
WHERE assigned_to_id=3 OR
author_id=3 AND
status_id IN (SELECT id FROM issue_statuses WHERE NOT is_closed)
ORDER BY (priority_id * EXTRACT(EPOCH FROM AGE(due_date))) DESC NULLS LAST,
priority_id DESC;