Skip to content

Instantly share code, notes, and snippets.

View 1nstinct's full-sized avatar

Yurii Siedin 1nstinct

View GitHub Profile
SELECT
(SELECT
TOP 1 u.*
FROM
actionDetail d
LEFT JOIN actionLog l ON l.actionId = d.actionId
LEFT JOIN users u ON l.userId = u.userId
WHERE d.actionId = @actionId
FOR JSON PATH) AS userData,
(SELECT
@1nstinct
1nstinct / custom JSON.parse function for parsing variable in any type without error
Last active February 26, 2016 10:56
JS code example for custom JSON parser for parsing string if you exactly don't know that string in "like json" format.
var Parse = function(string) {
try {
var object = JSON.parse(string);
if(typeof(object) == 'object' || typeof(object) == 'array')
return object; // return converted object
if(typeof(object) == 'number')
return string; // return number string
} catch (err) {
@1nstinct
1nstinct / migration_script.js
Last active February 2, 2016 09:43
NodeJs+MongoDB+Migrations
/*
This script uses https://github.com/tj/node-migrate module for NodeJs
Installing:
1. npm install -g grunt-cli
2. npm install grunt --save-dev
3. npm install migrate -g
Running from console:
1. migrate create migration_script
@1nstinct
1nstinct / 1.blade.php
Created January 18, 2016 13:30
blade php example
<html>
<head>
@section('css')
@show
</head>
<body class="desktop-detected pace-done">
<div id="content-wrap">
@section('content')
<p>Main content</p>
@show
@1nstinct
1nstinct / or.js
Last active June 13, 2016 07:06
sails-hook-parametized-policies N policies
/**
* Ability to check any count of policies in OR ordering
* @author Yuriy Syedin <[email protected]>
* @returns {Function}
*/
module.exports = function () {
var makeFakeForbidden = function (policies, p, req, res, next) {
if (!policies[p + 1]) return res; // if there is no next policy, that should be verified - leave result as it is
var customRes = {}; // init empty response object
@1nstinct
1nstinct / ImageController.js
Last active March 14, 2018 08:37
nodejs sails gridfs upload, view, delete image/file
/**
* ImageController
*
* @description :: Server-side logic for managing Images
* @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers
*/
module.exports = {
uploadImage: function(req, res) {
req.file('image').upload({