Posts

Showing posts from 2015

Convert String to Date by using map function in MongoDb

Convert String to Date  by using map function in MongoDb db.getCollection('trackings').find({"created_date": /^Fri Dec 11 2015.*/})       .map(         function(tracking) {           db.getCollection('trackings').update({ "_id": tracking._id},            {             $set: {                 "created_date": new Date(tracking.created_date)             }           },            {             multi: false           }       );      return [tracking.created_date]     }    );

Specific Field Update by Use Map Function

Rails Resque gem 'resque-status' bundle 1. ) app/workers/transcoder.rb class Transcoder include Resque::Plugins::Status @queue = :transcoder def perform puts "transcoder starting..." end end 2.) config/initializers/resque.rb require 'redis' require 'resque/status_server' $redis = Redis.new RS=Resque::Plugins::Status Resque::Plugins::Status::Hash.expire_in = (48 * 60 * 60) # 2 days in seconds 3.) lib/resque.rake require 'bundler/setup' Bundler.require(:default) # require 'nish-news' require 'resque/tasks' task "resque:setup" do ENV['QUEUE'] = '*' Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } end 4. ) Procfile web: bundle exec rails s -p 3000 worker1: bundle exec rake environment resque:work QUEUE='transcoder' and foreman start https://gist.github.com/muratatak77/bbe743e379add276cf59cc

Moment JS - Some date functions

exports.getDateByRange = function(req, options) { var start_date = req.param('start_date'); var end_date = req.param('end_date'); var date_type = req.param('date_type') || "yesterday_revenue"; if (date_type == "yesterday_revenue") { options.start_date = moment().subtract(1, 'day').startOf('day')._d; options.end_date = moment().subtract(1, 'day').startOf('day').add({ hour: 23, minute: 59 })._d; } else if (date_type == "week_to_date_revenue") { options.start_date = moment().startOf('week')._d; options.end_date = moment()._d; } else if (date_type == "month_to_date_revenue") { options.start_date = moment().startOf('month')._d; options.end_date = moment()._d; } else if (date_type == "quarter_to_date_revenue") { options.start_date = moment().startOf('quarter')._d; options.end_date

Passing current scope to an AngularJS Service

var app = angular.module('as2App'); app.factory('AlertService', function($timeout) { var _scope = {}; //constructor function alertService(scope) { this._scope = scope; this._scope['show_alert'] = false; this._scope['alerts'] = []; } alertService.prototype._addAlert = function(type, message) { this._scope['alerts'].push({ type: type, msg: message }); this._onShow(this._scope); } alertService.prototype._onShow = function(_scope) { this._scope['show_alert'] = true; $timeout(function() { alertService.prototype._hideMe(_scope); }, 2000); } alertService.prototype._hideMe = function(_scope) { _scope['show_alert'] = false; _scope['alerts'].splice(0, 1); } return alertService; }); //########### SERVICES ############## //########### CNTROLLER ############## var app = angular.module('as2App'); app.controller

Node JS - Redis All Page Caghing. XML return using redis hmset() and hgetall()

var full_url = req.protocol + '://' + req.get('host') + req.originalUrl; console.log("====== full_url : " , full_url); client.hgetall("full_url_hash", function (err, result_hash_object) { if ( result_hash_object != null && result_hash_object[full_url] != null && ( utils.undefined_check(result_hash_object ) != "" ) && ( utils.undefined_check( result_hash_object[full_url] ) != "" ) ){ console.log("full_url_hash vast cache find. Return xml page directly sending: " , full_url); res.set('Content-Type', 'text/xml'); res.send(result_hash_object[full_url] ); } else { //some workers and process and var hmset_url = client.hmset("full_url_hash", full_url, vast3_xml); if (hmset_url){ console.log("full_url