Skip to content

Instantly share code, notes, and snippets.

View DanisHack's full-sized avatar
:octocat:

Muhammad Danish DanisHack

:octocat:
View GitHub Profile
@DanisHack
DanisHack / app.js
Last active August 16, 2023 10:40
Rendering angularjs app using ejs from node server and how to use a JS variable which is passed to ejs template for angular app.
//@server in express js file
var data = {};
data.title = "My First APP";
data.arr=[{x:1, y:1}, {x:2, y:2}, {x:3, y:4}];
res.render('/ejsFile', data);
@DanisHack
DanisHack / d3.js
Created February 17, 2014 08:54
Angular directive to draw bar graph using D3
angular.module('d3', [])
.factory('d3Service', ['$document', '$window', '$q', '$rootScope',
function($document, $window, $q, $rootScope) {
var d = $q.defer(),
d3service = {
d3: function() { return d.promise; }
};
function onScriptLoad() {
// Load client in the browser
$rootScope.$apply(function() { d.resolve($window.d3); });
@DanisHack
DanisHack / app.js
Created April 19, 2014 18:19
Adding CORS support in expressjs app
var express = require('express')
, routes = require('./modules/analytics/routes')
, http = require('http')
, path = require('path');
@DanisHack
DanisHack / mongoDB_backup.sh
Last active August 29, 2015 14:02
Automating MongoDB dump using cron job and saving on s3 using s3cmd
#!/bin/bash
#Force file syncronization and lock writes
mongo admin --eval "printjson(db.fsyncLock())"
MONGODUMP_PATH="/usr/bin/mongodump"
MONGO_HOST="server_ip" #replace with your server ip
MONGO_PORT="27017"
USER_NAME="myDB"
PASSWORD="password"
@DanisHack
DanisHack / getBatch.js
Created June 9, 2014 12:28
Google Analytics Api--getting data in batches in Node (using express)
exports.AnalyticsDataBatchRequest = function(profileId, startDate, endDate, callback){
var r1 = gapi.mainclient.analytics.data.ga.get({
'ids': 'ga:' + profileId,
'start-date': startDate,
'end-date': endDate,
'metrics': 'ga:pageviews'
,'dimensions': 'ga:source, ga:keyword, ga:pagePath'
});
@DanisHack
DanisHack / mergeObjects.js
Created June 9, 2014 12:34
Merging two objects in javascript
var aggregateData = function(wb, rb){
for(var k in rb) { //
if(Object.prototype.toString.call(rb[k]) == '[object Object]'){
if(wb.hasOwnProperty(k)){
var ob1 = wb[k];
var ob2 = rb[k];
@DanisHack
DanisHack / sqs.js
Created June 9, 2014 12:41
general SQS service for Node app using aws-lib (nodejs library for aws)
var aws = require ('aws-lib');
var options ={
"path": "", // your queue path you can aws management console to find it
"version": "", // version-- its a date
};
sqs = aws.createSQSClient(awsKey, awsPrivateKey, options);
@DanisHack
DanisHack / directiveLearnings.txt
Created June 12, 2014 04:02
Angular Directive Learning
Directive Learnings:
*) Make the changes in the compile function, not link function if
You want to change the template.
*) If, however, you want to change the instances, make change in link function.
- Above 2 Mostly relevant for ng-repeat -
*) No scope available in compile function
@DanisHack
DanisHack / blog.txt
Last active August 29, 2015 14:02
Blogs I read
http://howtonode.org/
http://highscalability.com/
http://blog.mongodb.org/
http://blog.libtorrent.org/
@DanisHack
DanisHack / articles.txt
Last active August 29, 2015 14:02
Great articles
Cloud: http://highscalability.com/blog/2014/6/5/cloud-architecture-revolution.html
AngularJS Directive: http://www.ng-newsletter.com/posts/directives.html
http://tutorials.jenkov.com/angularjs/custom-directives.html