Skip to content

Instantly share code, notes, and snippets.

View thebapi's full-sized avatar

Sajib Sarkar thebapi

View GitHub Profile
/*
Delete Events of Incident Events
*/
with results as (select * from
incident_events WHERE
incident_events.incident_id not in (
select incidents.id from incidents where incidents.id = incident_events.incident_id
))
/*
Delete event mentions
*/
with ev as (select * from
incident_events WHERE
incident_events.incident_id IN (select i.id
from incidents i
left join assets on asset_id = assets.id
@thebapi
thebapi / gist:52082364e16db024399d6335cfcbda69
Created December 6, 2021 12:18
last one month data for asset 203
SELECT *
FROM public.messages
WHERE time > (extract(epoch from NOW() - INTERVAL '1 MONTH') * 1000)::bigint
and asset_uuid = 'f52143cb-1cb6-45f7-98b6-4fbe537cd0da'
select users.* , ARRAY_AGG(auth.roles.name) as roles
from users
left join auth.permissions on auth.permissions.subject_id = users.id
left join auth.roles on auth.roles.id = auth.permissions.role_id
group by users.id
select users.* , auth.roles.name as role
from users
@thebapi
thebapi / gist:08db3361287233d1d7fd6c6d8612a9bc
Created May 11, 2021 13:30
Arduino Port issue fix for mac
Install the driver by the following commands:
brew tap adrianmihalko/ch340g-ch34g-ch34x-mac-os-x-driver https://github.com/adrianmihalko/ch340g-ch34g-ch34x-mac-os-x-driver
brew cask install wch-ch34x-usb-serial-driver
details https://github.com/adrianmihalko/ch340g-ch34g-ch34x-mac-os-x-driver
select *
from "incidents" inner join "assets" on "assets"."id" = "incidents"."asset_id"
inner join "zones" on "zones"."id" = "assets"."zone_id"
inner join "sites" on "sites"."id" = "zones"."site_id" inner join "system_checks" on "system_checks"."site_id" = "sites"."id"
where "incidents"."created_at" >= "system_checks"."from_date" and "incidents"."created_at" <= "system_checks"."to_date" and "system_checks"."id" = '235' and "incidents"."status"
not in ('waiting', 'elapsed')
@thebapi
thebapi / gist:9b6342da907de7db5c2a824764171181
Created December 25, 2020 18:18
gyp: No Xcode or CLT version detected!
Solution 1
$ sudo xcode-select --reset
Solution 2
$ xcode-select --print-path
$ sudo rm -r -f /Library/Developer/CommandLineTools
QUEUE_NAME=SEMATICS_QUEUE node playground.js
CREATE OR REPLACE FUNCTION calculate_performance_metric(value double precision DEFAULT 0, optimal_low double precision DEFAULT 0, optimal_high double precision DEFAULT 0, alarm_low double precision DEFAULT 0, alarm_high double precision DEFAULT 0) RETURNS device_performance_metric
LANGUAGE plpgsql
STABLE
AS $$
DECLARE
optimal_below_low_count smallint DEFAULT 0;
optimal_count smallint DEFAULT 0;
optimal_above_high_count smallint DEFAULT 0;
incident_below_low_count smallint DEFAULT 0;
incident_above_high_count smallint DEFAULT 0;
@thebapi
thebapi / gist:83bb30a1adf66b4711af9cfb8dae9e0a
Last active March 20, 2020 12:28
regex for mongo objecid key value object
should match this like string
"_id"\s:\sObjectId\("\w+"\),
/\*\s\d+\s\*/. sjould match /* 13 */ like string