Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀

Renato Gama renatoargh

🚀
View GitHub Profile
@renatoargh
renatoargh / config.yml
Created Feb 12, 2021 — forked from sjparkinson/config.yml
Deploy a Fastly service using Terraform and CircleCI 2.0.
View config.yml
version: 2
jobs:
validate_terraform:
docker:
- image: hashicorp/terraform
steps:
- checkout
- run:
name: Validate Terraform Formatting
View classgen.js
const className = 'StateId'
const interfaceName = 'StateIdInterface'
const data = ` state: string;
value: string;
isActive: boolean;
toJSON(): { [key: string]: any };`
const members = data
.replace(/\n/g, '')
.split(';')
View cache.ts
interface ObjectInterface {
[key: string]: any;
}
function initCache<T>(obj: any): T {
const cache = {};
return new Proxy(obj, {
get(target: ObjectInterface, methodKey: string) {
const originalMethod = target[methodKey];
View cache.ts
interface ObjectInterface {
[key: string]: any;
}
function initCache<T>(obj: any): T {
const cache = {};
return new Proxy(obj, {
get(target: ObjectInterface, methodKey: string) {
const originalMethod = target[methodKey];
@renatoargh
renatoargh / pglogical
Created Jul 8, 2019 — forked from ratnakri/pglogical
short tutorial to setup replication using pglogical
View pglogical
Edit /var/lib/postgres/data/postgresql.conf:
# change IP on subscriber
listen_addresses = '*'
wal_level = logical
shared_preload_libraries = 'pglogical'
max_worker_processes = 16
max_wal_senders = 16
max_replication_slots = 16
track_commit_timestamp = on
View initial_expected_usage.js
const validator = new Validator('http://example.com/swagger.yaml')
await validator.init()
validator.validate('UserCreated', payload)
@renatoargh
renatoargh / small-query-builder.js
Last active Jun 7, 2019
A small query builder to help not writing SQL insert by hand
View small-query-builder.js
const withQuotes = (value, quote = '\'') => {
if (typeof value === 'undefined') {
return 'null'
}
if (value === null) {
return 'null'
}
return `${quote}${value}${quote}`
View pg_notify.js
// CREATE TABLE realtime_table (id serial primary key, title varchar, year varchar, producer varchar);
// CREATE FUNCTION notify_trigger() RETURNS trigger AS $$
// DECLARE
// BEGIN
// PERFORM pg_notify('watch_realtime_table', row_to_json(NEW)::text);
// RETURN new;
// END;
// $$ LANGUAGE plpgsql;
// CREATE TRIGGER watch_realtime_table_trigger AFTER INSERT ON realtime_table
@renatoargh
renatoargh / prefixed-sum.js
Created Oct 28, 2018
sum: O(n), get sum of segment: O(1)
View prefixed-sum.js
function prefixedSum(array) {
const sum = new Array(array.length + 1)
sum[0] = 0
for(let k = 1; k < sum.length; k++) {
sum[k] = (sum[k - 1] || 0) + array[k - 1]
}
return sum
}