Skip to content

Instantly share code, notes, and snippets.

@gabhi
gabhi / gist:9779334
Created March 26, 2014 09:08
array in php
$response = array();
@gabhi
gabhi / gist:9787003
Last active August 29, 2015 13:57
model hierarchy in mongodb
Model Tree Structures in MongoDB
URL :http://docs.mongodb.org/manual/tutorial/model-tree-structures/#model-tree-structures-with-materialized-paths
To model hierarchical or nested data relationships, you can use references to implement tree-like structures. The following Tree pattern examples model book categories that have hierarchical relationships.
Model Tree Structures with Child References
(link)
The Child References pattern stores each tree node in a document; in addition to the tree node, document stores in an array the id(s) of the node’s children.
@gabhi
gabhi / gist:9802312
Created March 27, 2014 07:39
Constants in angular
//first in main controller
var myApp = angular.module('starter.controllers', []);
myApp.constant('mySettings', {
apiUri: '/api/foo',
nsUri: 'mySite/foo.xsd',
nsPrefix: 's'
});
@gabhi
gabhi / gist:9802327
Last active August 29, 2015 13:57
Email link in angular
//in the controller
getEmail = function() {
var email = {
firstName: "Abhijit",
lastName: "Gaikwad",
address: "[email protected]",
subject: "Something interesting",
body: "Hey there, i m testing sending email in angular"
};
@gabhi
gabhi / gist:9802681
Created March 27, 2014 08:10
angular encode url
//in the mail controller
var myApp = angular.module('starter.controllers', []);
myApp.filter('escape', function() {
return window.escape;
});
@gabhi
gabhi / gist:9804443
Created March 27, 2014 10:20
php 404 post error on angular
//add following to the controller
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
@gabhi
gabhi / gist:9827207
Created March 28, 2014 07:28
angular http get example
$http({
url: user.details_path,
method: "GET",
params: {user_id: user.id}
});
@gabhi
gabhi / gist:9844106
Created March 28, 2014 22:15
Expressjs or nodejs allow cross domain access
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
@gabhi
gabhi / gist:9951276
Last active August 29, 2015 13:58
Array Permutations
public static List<ArrayList<Integer>> arrayCombinations(int[] inputArr) {
List<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
result.add(new ArrayList<Integer>());
for (int i = 0; i < inputArr.length; i++) {
ArrayList<ArrayList<Integer>> current = new ArrayList<ArrayList<Integer>>();
for (ArrayList<Integer> local : result) {
@gabhi
gabhi / gist:9951338
Created April 3, 2014 09:30
Slice arrays in Java
Arrays.copyOfRange(oldArray, startIndex, endIndex);