Skip to content

Instantly share code, notes, and snippets.

View abhi5658's full-sized avatar
:shipit:
Go watch something else. This is not Facebook!

Abhishek Shah abhi5658

:shipit:
Go watch something else. This is not Facebook!
  • Postman | Airmeet | Simform
  • Bengaluru
View GitHub Profile
const express = require('express')
const app = express()
const crypto = require('crypto')
const secretKey = '<your secret key>'
const bodyParser = require('body-parser')
app.use('/webhooks', bodyParser.raw({ type: 'application/json' }))
app.use(bodyParser.json())
app.post('/webhooks/orders/create', async (req, res) => {
@vovimayhem
vovimayhem / dev.Dockerfile
Created August 18, 2017 00:02
PhantomJS on Alpine (Docker)
# 1: Use node 6 as base:
FROM node:6-alpine
# 2: Download+Install PhantomJS, as the npm package 'phantomjs-prebuilt' won't work on alpine!
# See https://github.com/dustinblackman/phantomized
RUN set -ex \
&& apk add --no-cache --virtual .build-deps ca-certificates openssl \
&& wget -qO- "https://github.com/dustinblackman/phantomized/releases/download/2.1.1/dockerized-phantomjs.tar.gz" | tar xz -C / \
&& npm install -g phantomjs \
&& apk del .build-deps
@zcaceres
zcaceres / Include-in-Sequelize.md
Last active July 27, 2024 13:21
using Include in sequelize

'Include' in Sequelize: The One Confusing Query That You Should Memorize

When querying your database in Sequelize, you'll often want data associated with a particular model which isn't in the model's table directly. This data is usually typically associated through join tables (e.g. a 'hasMany' or 'belongsToMany' association), or a foreign key (e.g. a 'hasOne' or 'belongsTo' association).

When you query, you'll receive just the rows you've looked for. With eager loading, you'll also get any associated data. For some reason, I can never remember the proper way to do eager loading when writing my Sequelize queries. I've seen others struggle with the same thing.

Eager loading is confusing because the 'include' that is uses has unfamiliar fields is set in an array rather than just an object.

So let's go through the one query that's worth memorizing to handle your eager loading.

The Basic Query

@phillip-haydon
phillip-haydon / jsonb_merge.sql
Created December 6, 2016 10:17
Deep Merge two jsonb documents in PostgreSQL
CREATE OR REPLACE FUNCTION jsonb_merge(left JSONB, right JSONB) RETURNS JSONB AS $$
var mergeJSON = function (target, add) {
function isObject(obj) {
if (typeof obj == "object") {
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
return true; // search for first object prop
}
}
@AloofBuddha
AloofBuddha / sequelize-belongs-to-example.js
Created September 29, 2016 15:15
An explanation of how to define a One-to-One relationship in Sequelize and different ways of create the linked objects
// Product Model definition, called 'product' and associated with table 'products'
var Product = this.sequelize.define('product', {
title: Sequelize.STRING
});
// User Model definition, called 'user' and associated with table 'users'
var User = this.sequelize.define('user', {
first_name: Sequelize.STRING,
last_name: Sequelize.STRING
});
@AloofBuddha
AloofBuddha / sequelize-cheat-sheet.md
Created September 26, 2016 14:28
Sequelize cheat sheet

Note: $> means command line input

Dependencies

Dependencies to use Sequelize $> npm install --save sequelize pg pg-hstore

Setup

Must create the DB first $> createdb my-music