Skip to content

Instantly share code, notes, and snippets.

View dibikhin's full-sized avatar

Roman Dibikhin dibikhin

  • Moscow, Russia
View GitHub Profile
@dibikhin
dibikhin / parse_fb_signed_request.js
Last active July 14, 2020 09:19
testing parsing fb signed requests
'use strict'
const crypto = require('crypto')
const secret1 = 'appsecret'
const payload1 = {
algorithm: 'HMAC-SHA256',
expires: 1291840400,
issued_at: 1291836800,
@dibikhin
dibikhin / build_friends_network.js
Created April 30, 2020 23:25
Build friends network
a = a.map(x => ({id: x.id, fids: x.friendsIds}))
data = {}
data.nodes = a.map(x => ({ id: x.id }))
data.links = a.reduce((acc, cur) => {
const links = cur.fids.map(x => ({ source: cur.id, target: x }))
return acc.concat(links)
}, [])
@dibikhin
dibikhin / asyncify.js
Last active June 10, 2020 11:13
Asyncify and wrap with catch
const handleErrors = (err) => { console.error(err); return null }
const wrap = (f) =>
(...args) =>
(
(
async () => f(...args)
)()
).catch(handleErrors)
// Read to end first, then solve one by one.
var express = require('express');
// #0. Load 'multer' here.
// #1. Use 'uploads' folder for multer's upload here.
var app = express();
@dibikhin
dibikhin / C# OPP
Last active August 29, 2015 14:09
Polymorphism & inheritance sample for LinqPad, http://www.linqpad.net
void Main()
{
IAreaComputable circle = new Сircle(5);
IAreaComputable square = new Square(5);
Quadrilateral rhombus = new Rhombus(5, 7);
circle.ComputeArea().Dump();
square.ComputeArea().Dump();
((IAreaComputable)rhombus).ComputeArea().Dump();
}
@dibikhin
dibikhin / Insert with Id output
Created November 12, 2014 13:07
T-SQL insert test returning Id of a new row
CREATE TABLE Customers
(
Id INT IDENTITY(1,1) NOT NULL,
Name NVARCHAR(255) NOT NULL
);
GO
SET IDENTITY_INSERT Customers OFF;