Skip to content

Instantly share code, notes, and snippets.

View everilae's full-sized avatar

Ilja Everilä everilae

View GitHub Profile
@everilae
everilae / gist:3495968
Created August 28, 2012 07:49
An ugly Bootstrap AMD wrapper for Require.js optimizer
/* onBuildRead hooks before optimizations, which is what we need in order to
* fake Bootstrap having define() call
*/
onBuildRead: function (name, path, contents) {
var jqueryVar = 'jqueryModule';
var wrapperHead = "define('" + name + "', ['jquery'], ";
var wrapperTail = ");";
if (name === "bootstrap") {
console.log("Wrapping bootstrap in " + wrapperHead + "..." + wrapperTail);
@everilae
everilae / threadedgenerator.py
Last active March 26, 2024 18:49
Threaded generator wrapper for Python
# A simple generator wrapper, not sure if it's good for anything at all.
# With basic python threading
from threading import Thread
try:
from queue import Queue
except ImportError:
from Queue import Queue
@everilae
everilae / gist:76e584e611ae9ffec2ea
Created May 16, 2014 11:51
PostgreSQL PL/pgSQL array_foreach
create function array_foreach(text, anyarray) returns anyarray as $$
declare
funcname alias for $1;
vals alias for $2;
results alias for $0;
begin
execute format('select array_agg(s.t) from (select %I(unnest($1))) as s(t)', funcname) into results using vals;
return results;
end;
$$ language plpgsql;
@everilae
everilae / custom.py
Last active August 29, 2015 14:03
An attempt at aggregate FILTER clauses for SQLAlchemy
import itertools
from sqlalchemy import util, and_, case
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql import ColumnElement
from sqlalchemy.sql.elements import ClauseList, _clone
from sqlalchemy.sql.functions import FunctionElement
class AggregateFilter(ColumnElement):
"""Represent a FILTER clause.
@everilae
everilae / jsoncolumn.py
Created March 27, 2015 10:01
JsonColumn for working with SQLAlchemy JSON and JSONB columns
class JsonColumn(object):
"""
Descriptor class for accessing values from `JSONB` columns.
**In Expressions**:
As class attribute the descriptor resolves the class property
pointing to prepared `JSONB` element using the ``'column'`` value's
:attr:`key` attribute. It then uses the element's item accessor with the
``*keys`` and returns it :attr:`astext`, if not ``'astext'`` is True.
@everilae
everilae / ctris.c
Created April 2, 2015 12:55
tcc -run ctris.c | aplay -r8000
static const char m[] = {
24,24,18,19,
21,21,19,18,
16,16,16,19,
24,24,21,19,
18,18,18,19,
21,21,24,24,
19,19,16,16,
0,0,0,0,
@everilae
everilae / mq.erl
Last active August 29, 2015 14:19
Learning Erlang, simple task queue
-module(mq).
-export([
start/0, disp_status/1, get_status/1, add_task/2, add_simple_worker/2,
add_worker/2, send_ack/1, echo_worker/0
]).
-spec start() -> pid().
%% @doc Spawn new queue and return process id.
start() ->
spawn(fun loop/0).
@everilae
everilae / selectinto.py
Created May 25, 2015 15:19
SQLAlchemy SelectInto ORM query support thingie idea test
from sqlalchemy.sql.selectable import HasPrefixes
from sqlalchemy.sql.base import Executable
from sqlalchemy.sql.elements import ClauseElement
from sqlalchemy.ext.compiler import compiles
from sqlalchemy import Table, MetaData
class SelectInto(HasPrefixes, Executable, ClauseElement):
def __init__(self,
@everilae
everilae / argsfor.py
Created July 28, 2015 12:38
Create argparse.ArgumentParser for given function and apply parsed arguments
import inspect
import argparse
def _helpfor(param):
if param.annotation is not inspect.Parameter.empty:
if isinstance(param.annotation, type):
return param.annotation.__name__
return str(param.annotation)
return param.name
@everilae
everilae / sqlite_json.py
Last active April 4, 2020 02:24
Hacky JSON support for SQLAlchemy SQLite dialect, if https://www.sqlite.org/json1.html extension is available.
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.dialects import plugins
from sqlalchemy.dialects.mysql.json import JSONIndexType, JSONPathType
from sqlalchemy.engine import CreateEnginePlugin
from sqlalchemy.sql.elements import BinaryExpression
from sqlalchemy.sql import sqltypes
from sqlalchemy.sql.operators import \
json_getitem_op, \
json_path_getitem_op