Skip to content

Instantly share code, notes, and snippets.

@mdamien
mdamien / example.py
Created September 15, 2016 22:57
test for window with no event capture
#!/usr/bin/env python
import cairo
from gi.repository import Gdk, Gtk
def main():
win = Gtk.Window()
win.connect('destroy', lambda w: Gtk.main_quit())
win.set_default_size(450, 550)
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 50, 50)
@mdamien
mdamien / TODO.md
Last active March 19, 2019 10:41
html templating with python (now http://github.com/mdamien/lys)
  • django integration example
  • auto-converter from HTML and Django Templates (and other templating languages)
  • self-closing tags (br, img,..)
  • special attributes (class, is,..)
  • custom anchor point for children
  • support escaped string (markdown rendered, javascript,...)

other ideas:

  • use beautifulsoup to store the node ? nice querying, prettify,..
@mdamien
mdamien / django_deep_seralization.py
Created July 19, 2016 15:38
django deep serialization
# override the default to use timestamps for date instead of ISO
class TimestampJSONEncoder(DjangoJSONEncoder):
def default(self, o):
if isinstance(o, datetime.datetime):
return int(o.strftime("%s"))
return super().default(o)
# if foreign key was prefected, serialize object with foreign key value directly
class ForeignKeyIncludeSerializer(PythonSerializer):
@mdamien
mdamien / report.py
Last active June 23, 2016 10:36
Freeswitch + Sentry
import re
import subprocess
import datetime
import sys
import pickle
from raven import Client
client = Client('your_thing', context='')
SERVER_NAME = subprocess.check_output('hostname')

DOES POWER REALLY CORRUPT?

An argument about whether powerful people behave better or worse than others is shaking the world of experimental psychology. Matthew Sweet investigates

MATTHEW SWEET | MAY 3RD 2016

Cycling one morning over the East Bay Hills, Professor Dacher Keltner had a near-death experience. “I was riding my bike to school,” he recalls, “and I came to a four-way intersection. I had the right of way, and this black Mercedes just barrelled through.” With two feet to spare before impact, the driver slammed on his brakes. “He seemed both surprised and contemptuous, as if I was in his more important way.” Keltner’s first response was a mixture of anger and relief: no Berkeley psychology professor with surfer-dude hair had been smeared over the Californian tarmac that day. His second was more academic. Was there, he wondered, a measurable difference between the behaviour of Mercedes owners and those of other cars? Cars that didn’t cost twice the average annual income of an American middle-cl

{
"changed":true,
"cmd":"wp search-replace nuitdebout.fr nuitdebout.dev 'wpdb_*_options' wp_blogs --path=/var/www/nuitdebout",
"delta":"0:00:00.523046",
"end":"2016-05-15 18:26:07.757994",
"failed":true,
"rc":255,
"start":"2016-05-15 18:26:07.234948",
"stderr":"PHP Warning: include_once(/var/www/nuitdebout/wp-content/plugins/advanced-custom-fields/acf.php): failed to open stream: No such file or directory in /var/www/nuitdebout/wp-content/themes/nuitdebout/functions.php on line 14\nPHP Stack trace:\nPHP 1. {main}() /usr/local/bin/wp:0\nPHP 2. include() /usr/local/bin/wp:4\nPHP 3. include() phar:///usr/local/bin/wp/php/boot-phar.php:5\nPHP 4. WP_CLI\\Runner->start() phar:///usr/local/bin/wp/php/wp-cli.php:21\nPHP 5. WP_CLI\\Runner->load_wordpress() phar:///usr/local/bin/wp/php/WP_CLI/Runner.php:755\nPHP 6. require() phar:///usr/local/bin/wp/php/WP_CLI/Runner.php:807\nPHP 7. include() phar:///usr/local/bin/wp/php/wp-settings-cli.php:387\nPHP Warning: include_once(): Faile
{
"cache_update_time":0,
"cache_updated":false,
"changed":false,
"failed":true,
"msg":"'/usr/bin/apt-get -y -o \"Dpkg::Options::=--force-confdef\" -o \"Dpkg::Options::=--force-confold\" install 'nginx'' failed: E: Sub-process /usr/bin/dpkg returned an error code (1)\n",
"stderr":"E: Sub-process /usr/bin/dpkg returned an error code (1)\n",
"stdout":"Reading package lists...\nBuilding dependency tree...\nReading state information...\nThe following extra packages will be installed:\n libgd3 libvpx1 libxpm4 libxslt1.1 nginx-common nginx-full\nSuggested packages:\n libgd-tools fcgiwrap nginx-doc ssl-cert\nThe following NEW packages will be installed:\n libgd3 libvpx1 libxpm4 libxslt1.1 nginx nginx-common nginx-full\n0 upgraded, 7 newly installed, 0 to remove and 68 not upgraded.\nNeed to get 1615 kB of archives.\nAfter this operation, 4328 kB of additional disk space will be used.\nGet:1 http://security.debian.org/ jessie/updates/main libgd3 amd64 2.1.0-5+deb8u1 [147 kB]\nGet:2 http://sec
@mdamien
mdamien / selectize-plugin-edit.js
Created May 9, 2016 14:54
double click to edit for selectize
import Selectize from 'selectize';
// https://gist.github.com/bolasblack/1e099fa2055c846106ac
Selectize.define('editable_tag', () => {
this._createItemWhenInputBlur = function() {
if (this.$control_input.val() && this.editingTag) {
this.createItem(null, false);
this.editingTag = false;
return this.editingTag;
}
import Selectize from 'selectize';
// https://gist.github.com/mdamien/a0f2bd91750a2d45c8ab
function copyToClipboard(text) {
const el = document.createElement('textarea');
el.style.position = 'absolute';
el.style.left = '-9999px';
el.setAttribute('readonly', '');
el.value = text;
{
"aggregateRating.properties.ratingCount": "22",
"aggregateRating.properties.ratingValue": "1.6818181818181819",
"autogen": "false",
"available_on_android": "false",
"by_google": "false",
"canonical": "true",
"category": "7_productivity",
"container": "CHROME",
"ext_id": "fbcbacllniphpeoblhnelengbdndhoof",