Skip to content

Instantly share code, notes, and snippets.

View nsisodiya's full-sized avatar

Narendra Sisodiya nsisodiya

View GitHub Profile
@nsisodiya
nsisodiya / 1.js
Last active August 29, 2015 14:08
Code for JavaSCript Presentation
var o = {
id: 34,
name: "Narendra",
tags: ["js", "html5"],
work: {
type: "developer",
language: "JavaScript",
}
};
@nsisodiya
nsisodiya / loop.js
Created November 29, 2014 09:27
Bye Bye for loop
Number.prototype.times = function(callback){
for(var i=0; i< this; i++){
callback(i);
}
};
(5).times(function(i){
console.log(i);
});
function addEvents(module){
if (module.events !== undefined) {
_.each(module.events, function(handler, key) {
var arr = key.split(" ");
var method = arr.shift();
var hash = arr.join(" ");
if (hash === "") {
module.$$.on(method, function(e) {
try {
module[handler].call(module, e, e.target, e.target.dataset);
initSlideshow(
document.getElementbyId("myDiv"),
{
"title": "Cat Slideshow",
"images": [
{
"caption": "Time to Prayer",
"path": "images/200_cute_cat_praying-1920x1200.jpg"
},
{
@nsisodiya
nsisodiya / addProperty.js
Last active August 29, 2015 14:11
addProperty
//@nsisodiya
//MIT
function addProperty(obj, prop, getCallback, setCallback){
var v;
Object.defineProperty(obj, prop, {
enumerable: true,
configurable: true,
get: function() {
getCallback(v);
return v;
@nsisodiya
nsisodiya / KharchaController.js
Created December 31, 2014 05:57
Sails js - UserId based filtering !!
// ./api/controllers/KharchaController.js
module.exports = {
filter: function (req, res) {
console.log(req.session.user.auth.id);
Kharcha.find().where({
userId:req.session.user.auth.id
}).exec(function(err, data) {
if (err) return next(err);
res.json(data);
//Destroy One Record
delete /:modelIdentity/:id
* /:modelIdentity/destroy/:id
//Find One Record
get /:modelIdentity/:id
@nsisodiya
nsisodiya / Gruntfile.js
Created January 4, 2015 04:52
grunt-http-server config for cors
"http-server": {
dev: {
root: "src",
port: 8080,
host: "127.0.0.1",
cache: -1,
showDir: true,
autoIndex: true,
ext: "html",
runInBackground: true,
@nsisodiya
nsisodiya / a.js
Created January 10, 2015 15:43
Express.js + 404 For DataRequest, Index for Unknown Path
app.use('*', function (req, res, next) {
console.log("Generic Req");
console.log(req.baseUrl);
if(req.baseUrl.indexOf("/data/") === 0){
//Data Request !!
next();
}else{
//View Request
res.render('index', {});
@nsisodiya
nsisodiya / a.js
Last active August 29, 2015 14:15
Multi-way-Index of Array in JavaScript
var students = [{
name:"A",
id:"aaa",
subject:"Math"
},{
name:"B",
id:"bbb",
subject:"Math"
},{
name:"C",