Skip to content

Instantly share code, notes, and snippets.

View markgajdosik's full-sized avatar

Mark Gajdosik markgajdosik

  • Reading, United Kingdom
View GitHub Profile
CREATE OR REPLACE VIEW "joined_batches_fieldmapperview_290" AS
SELECT T1_1.id AS id,
T1_1.added AS added,
T1_1.updated AS updated,
T1_1.notes AS notes,
T1_1.uid AS uid,
T1_1.relates_to_id AS relates_to_id,
T1_1.role_id AS role_id,
T1_1.row AS row,
T1_1.fields || coalesce(T1_2.fields, '{}'::JSONB) || coalesce(T1_3.fields, '{}'::JSONB) AS fields
async def import_regular_records(
self, role: VOSSRole, direction: Optional[str]):
"""Using list API, imports records for a non-relation role.
:param role: Selected role to import records for.
:param direction: Hierarchy traversal direction or `None` if the
default traversal behaviour is required.
"""
if direction == 'default':
direction = None
@markgajdosik
markgajdosik / less_crazy.py
Created October 11, 2017 16:21
Less Crazy
l = [1, 2, 3, 4, 6, 7, 8, 10, 12]
ranges, last = [], None
for i in l:
if last is None or i - last > 1:
ranges.append([i, i])
else:
ranges[-1][1] = i
last = i
WITH table_join AS (
SELECT rowdex, "value", field_id FROM cucm_csv_batrepeatingfield
WHERE batdata_id = 10 AND role = 'phone' AND
((field_id = 327 AND value ILIKE '%US%') OR
(field_id = 295 AND value ILIKE '%10000%') OR
(field_id = 220 AND value ILIKE '%Cu1%'))),
sort_join AS (
SELECT s0.rowdex, "Directory Number", "Route Partition" FROM
(SELECT DISTINCT table_join.rowdex, table_join.value as "Directory Number" FROM table_join WHERE table_join.field_id = 295) AS s0 FULL OUTER JOIN
(SELECT DISTINCT table_join.rowdex, table_join.value as "Route Partition" FROM table_join WHERE table_join.field_id = 220) AS s1 ON s0.rowdex = s1.rowdex)
WITH table_join AS (
SELECT row, value, field_id FROM cucm_csv_batentity
WHERE batdata_id = 10 AND role = 'phone' AND ((field_id = 2 AND value = 'Cisco 6921') OR (field_id = 1))),
add_table_join AS (
SELECT row, value, field_id from cucm_csv_batadditional
WHERE batdata_id = 10 AND role = 'phone' AND ((field_id = 2 AND value != '') OR (field_id = 1 AND value != ''))),
add_sort_join AS (
SELECT a0.row, "Import Notes", "Import Date" FROM
(SELECT DISTINCT add_table_join.row, add_table_join.value as "Import Notes" FROM add_table_join WHERE add_table_join.field_id = 2) AS a0 INNER JOIN
(SELECT DISTINCT add_table_join.row, add_table_join.value as "Import Date" FROM add_table_join WHERE add_table_join.field_id = 1) AS a1 ON a0.row = a1.row),
cursor.execute(textwrap.dedent('''
DROP TABLE IF EXISTS repeating;
CREATE TEMPORARY TABLE repeating ON COMMIT DROP
AS SELECT
{bat}.row, {cucm}.used_for, {bat}.field_id, {bat}.index
FROM {bat} INNER JOIN {cucm} ON
{cucm}.system_type = %s AND
{bat}.field_id = {cucm}.id
WHERE {bat}.row IN %s AND {cucm}.used_for IN %s {index}
'''))
@markgajdosik
markgajdosik / update_returning.py
Last active September 11, 2016 03:04
Update-returning support for Django 1.8. Based on: https://github.com/kanu/django-update-returning
"""
Implements manager with "UPDATE .. RETURNING" clause support. Columns following
the "RETURNING" clause may be provided using `values_list()` method. If not
specified, the update statement will yield full records.
Queries executed with use of `UpdateReturningManager` or
`UpdateReturningDefaultManager` return a generator allowing easy iterating over
the returned entries.
Based on https://github.com/kanu/django-update-returning, with modifications to
def save_configuration():
'''
Saves program configuration in the `config` module to a JSON file specified
via `config.general.CONFIG_PATH`. The function will skip any configuration
directives not listed in the provided `_ADJUSTABLE` lists.
'''
log.info('Saving program configuration.')
configuration = {}
# Get all section classes in the `config` module.
sections = inspect.getmembers(config, inspect.isclass)
Apr 10 09:38:05 mtcdp user.info kernel: usb 1-1: USB disconnect, address 100
Apr 10 09:38:08 mtcdp user.info kernel: usb 1-1: new full speed USB device using at91_ohci and address 101
Apr 10 09:38:13 mtcdp user.err kernel: usb 1-1: device not accepting address 101, error -62
Apr 10 09:38:13 mtcdp user.err kernel: hub 1-0:1.0: unable to enumerate USB device on port 1
Apr 10 09:38:14 mtcdp user.info kernel: usb 1-1: new full speed USB device using at91_ohci and address 103
Apr 10 09:38:14 mtcdp user.info kernel: usb 1-1: New USB device found, idVendor=1bc7, idProduct=0021
Apr 10 09:38:14 mtcdp user.info kernel: usb 1-1: New USB device strings: Mfr=18, Product=19, SerialNumber=20
Apr 10 09:38:14 mtcdp user.info kernel: usb 1-1: Product: Telit Wireless Module
Apr 10 09:38:14 mtcdp user.info kernel: usb 1-1: Manufacturer: Telit wireless solutions
Apr 10 09:38:14 mtcdp user.info kernel: usb 1-1: SerialNumber: 351579051972428