Skip to content

Instantly share code, notes, and snippets.

Avatar

Hussain hussainb

  • India, Pune
View GitHub Profile
@hussainb
hussainb / google-drive.js
Created Dec 24, 2017 — forked from MrToph/google-drive.js
Google Drive API v3 fetch
View google-drive.js
import GoogleSignIn from 'react-native-google-sign-in'
const url = 'https://www.googleapis.com/drive/v3'
const uploadUrl = 'https://www.googleapis.com/upload/drive/v3'
const boundaryString = 'foo_bar_baz' // can be anything unique, needed for multipart upload https://developers.google.com/drive/v3/web/multipart-upload
let apiToken = null
View angularCacheService.js
/*Usage:
return cacheService({ // Replace the $http() with cacheService
url: serviceBase.serviceBaseUri + '/GetSeriesTeam',
method: 'POST', // Works for POST only currently
methodName: 'GetSeriesTeam', // Optional, but recommended if different services use same post object properties.
data: params
}, 10).then(function(response) { // The 10 specifies time duration to cache this object in memory
return response.data;
})*/
View Sails-Protect-Blueprints.md

I am keeping this as a reference to https://github.com/balderdashy/sails/issues/352

Working with SailsJS v0.10-rc5: I am trying to keep the magic of blueprint controllers while at the same time protecting some model attributes from being changed by users on the default routes. I.e.: prevent access to the is_admin attribute on regular CRUD routes and implement a promote action or something similar on the UserController which makes the neccessary checks.

In order to do this, I came up with the following policy in combination with a small addition to the model definitions:

// file: api/policies/protectedAttributes.js

/**
View beforeBlueprint.js
/**
* beforeBlueprint
*
* @module :: Policy
* @description :: Simple policy to enable hooks into the model which can act upon req, res objects.
* @docs :: http://sailsjs.org/#!documentation/policies
*
*/
var actionUtil = require( 'sails/lib/hooks/blueprints/actionUtil' );
View beforeCreate.js
/**
* beforeCreate
*
* @module :: Policy
* @description :: Simple policy to inject the user creating a record into the records values.
* Assumes req.user && req.user.id to be set when a user is logged in.
* @docs :: http://sailsjs.org/#!documentation/policies
*
*/
@hussainb
hussainb / India_State_City
Created Sep 21, 2014
JSON collection of Indian States and their cities
View India_State_City
[
{
"state": "Andra Pradesh",
"cities": [
"Adilabad",
"Adoni",
"Amadalavalasa",
"Amalapuram",
"Anakapalle",
"Anantapur",
@hussainb
hussainb / removeItem
Last active Aug 29, 2015
Remove Item From Array
View removeItem
function removeItem (array,toRemove){
var newArray = [];
for(var i=0;i<array.length;i++){
if(array[i]!=toRemove){
newArray.push(array[i]);
}
}
return newArray;
}
@hussainb
hussainb / DaLe
Last active Aug 29, 2015
Damerau Levenshtein Algorithm for nodeJs or stand-alone javascript
View DaLe
/***********USAGE***********/
//
// var DaLe = require('DaLe');
// var distance = DaLe("string","strign");
// console.log(distance);
// outputs : 1 ;
//
/***************************/
You can’t perform that action at this time.