Skip to content

Instantly share code, notes, and snippets.

@alexgarel
alexgarel / jslint_out_for_geany.py
Created October 17, 2013 07:05
Using Geany and launching jslint (with eg.node-jslint). This script parse jslint output and add line filename and line numbers and produce an output suitable for Geany (underlining errors and jumping to related line as you cilck on jslint ouput).
#!/usr/bin/env python3
"""
Jslint output reformater for Geany
When defining your compile command in geany use::
/path/to/jslint %f |/path/to/jslint_out_for_geany.py
"""
import re
@alexgarel
alexgarel / jshint_out_for_geany.py
Created October 17, 2013 07:07
Using Geany and launching jshint ? This script parse jshint output and add line filename and line numbers and produce an output suitable for Geany (underlining errors and jumping to related line as you cilck on jshint ouput).
#!/usr/bin/env python3
"""
Geany jshint output reformater
When defining your compile command in geany
just use /path/to/jshint %f |/path/to/reformat_jshint.py
"""
import re
import sys
@alexgarel
alexgarel / pyflakes_out_for_geany.py
Created October 17, 2013 07:41
Using Geany and launching pyflakes or pep8 ? This script parse pyflakes / pep8 output and add line filename and line numbers and produce an output suitable for Geany (underlining errors and jumping to related line as you cilck on ouput).
#!/usr/bin/env python3
"""
Geany pyflakes and pep8 output reformater
When defining your compile command in geany use::
/path/to/pyflakes %f 2>&1 |/path/to/pyflakes_out_for_geany.py
/path/to/pep8 %f |/path/to/pyflakes_out_for_geany.py
"""
import sys
@alexgarel
alexgarel / celery_test_util.py
Last active September 30, 2022 09:28
Helper for tests with celery, running tasks in main thread but keeping control on when (alternative to eager)
from functools import partial
from celery.app.task import Task
from celery.app.utils import find_app
class CeleryTestTask(object):
"""A context manager to patch task in order to queue delayed tasks
and eventually run them. This is for tests.
@alexgarel
alexgarel / fix_assets.py
Created September 25, 2015 21:19
Utility to fixe a not so broken joomla assets table. Provided all assets are there and parent_id is correct, it will recompute level, rgt and lft for all entries.
import argparse
import getpass
import sys
import mysql.connector
class AssetsFixer:
cols = ["id", "parent_id", "level", "lft", "rgt"]
@alexgarel
alexgarel / deliciouszotero.py
Created August 24, 2016 23:09
Transform a delicious export to a RIS file, that can be imported in Zotero
#!/usr/bin/env python3
"""Transform a delicious export to a RIS file, that can be imported in Zotero
You'll need lxml installed (python3-lxml)
"""
import datetime
import sys
from lxml import html
fname = sys.argv[1]
from collections import defaultdict
from six import string_types
from gensim.models import phrases
from gensim import utils
class Phrases(phrases.Phrases):
@alexgarel
alexgarel / np_arg_in.py
Created January 31, 2018 19:43
Filtering values from a list in a numpy array (somewhat like isin() of pandas)
import numpy as np
def np_arg_in(a, values, sorter=None):
"""find indices of `a` containing one of values
:param a: numpy array to search in
:param values: numpy array of values to search
:sorter: optional array of integer indices that sort array a into ascending order
"""
if not isinstance(values, np.ndarray):
@alexgarel
alexgarel / test-es6-querystring-ipv6.py
Created August 25, 2018 12:53
Test of ipv6 in ES6 QueryString
# in the shell
# running ES6::
#
# $ docker pull docker.elastic.co/elasticsearch/elasticsearch:6.4.0
# $ docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.4.0
# in a new widow, install elasticsearch_dsl in a new virtualenv::
#
# $ cd /tmp/

Keybase proof

I hereby claim:

  • I am alexgarel on github.
  • I am alexg (https://keybase.io/alexg) on keybase.
  • I have a public key ASBsywNBkJDreBeDtsJ-PVDh0JpstGl1UWyHkhsBeEMHJwo

To claim this, I am signing this object: