Skip to content

Instantly share code, notes, and snippets.

View gpstmp's full-sized avatar

Peter Gerasimenko gpstmp

  • Russia, Taganrog
View GitHub Profile
@gpstmp
gpstmp / client-side-pseudo-code.js
Last active November 1, 2018 15:23
AngularJS: combine REST with Socket.IO
'use strict';
angular.module('app.api.entities.task', ['app.api.rest.task'])
.factory('Task', ['$rootScope', '$q', 'TaskApi', 'Socket', function($rootScope, $q, TaskApi, Socket) {
// here we use a simple in memory cache in order to keep actual data
// you can make it in any other way
var cache = {};
var initObject = function(data) {
if (cache[data._id]) {
@gpstmp
gpstmp / client-side-pseudo-code.js
Created March 31, 2014 19:36
AngularJS: combine REST with Socket.IO
'use strict';
angular.module('app.api.entities.task', ['app.api.rest.task'])
.factory('Task', ['$rootScope', '$q', 'TaskApi', 'Socket', function($rootScope, $q, TaskApi, Socket) {
// here we use a simple in memory cache in order to keep actual data
// you can make it in any other way
var cache = {};
var initObject = function(data) {
if (cache[data._id]) {
@gpstmp
gpstmp / report-images.sql
Last active March 23, 2016 12:21
Data structure for image editor
CREATE TABLE job (
id SERIAL PRIMARY KEY,
alias VARCHAR(20)
);
CREATE TABLE container (
id SERIAL PRIMARY KEY,
job INT REFERENCES job(id) ON DELETE CASCADE NOT NULL,
index INT NOT NULL, -- keep the order of containers
name VARCHAR(100)
@gpstmp
gpstmp / test_sequelize_migration.js
Last active July 23, 2020 07:31
Manage short urls on db level (postgres, sequelize)
// initial idea is taken here https://blog.andyet.com/2016/02/23/generating-shortids-in-postgres/
// this version is more general as we can pass the name of the column while setting up the trigger
// can be even more general if we pass the number of random bytes as the second argument (different length of short urls)
module.exports = {
up: async (queryInterface, Sequelize) => [
await queryInterface.sequelize.query('CREATE EXTENSION IF NOT EXISTS pgcrypto;'),
await queryInterface.sequelize.query('CREATE EXTENSION IF NOT EXISTS hstore;'),
await queryInterface.sequelize.query(`
-- Create a trigger function that takes no arguments.
-- Trigger functions automatically have OLD, NEW records