Monday, May 13, 2019

MySql Quey for Rank According to marks

SET @rownum := 0;
SELECT rank, student_marks FROM (
                    SELECT @rownum := @rownum + 1 AS rank, student_marks, student_Id
                    FROM student ORDER BY student_marks DESC
                    ) as result WHERE student_Id=3;


SELECT
 s1.student_name, COUNT(DISTINCT s2.student_marks) AS rank
FROM
  student s1 JOIN student s2 ON (s1.student_marks <= s2.student_marks)
GROUP BY s1.student_Id;

SELECT
  student_Id, student_name, student_marks,
  @prev := @curr,
  @curr := student_marks,
  @rank := IF(@prev = @curr, @rank, @rank+1) AS rank
FROM
  student,
  (SELECT @curr := null, @prev := null, @rank := 0) sel1
ORDER BY student_marks DESC;

Django :: Disable Delete Action


Django :: Disable Delete Action :-

site-packages/django/contrib/admin/options.py :-

class BaseModelAdmin(six.with_metaclass(RenameBaseModelAdminMethods)):
   
     def has_delete_permission(self, request, obj=None):

           return False  # Add this line for diable Delete Action

sites.py :-

class AdminSite(object):

   def __init__(self, name='admin', app_name='admin'):
       #self._actions = {'delete_selected': actions.delete_selected} # Comment this line
        self._actions = {} # add this line

Setup Git Server

Reference :- http://www.jeramysingleton.com/installing-gitolite/ & http://www.jeramysingleton.com/installing-gitolite/
https://github.com/sitaramc/gitolite

Setting up a gitolite server in Ubuntu:-

Run Below cmd on Server:-
sudo apt-get install git

sudo adduser \
  --system \
  --shell /bin/bash \
  --gecos 'git version control' \
  --group \
  --disabled-password \
  --home /home/git \
  git

sudo su git #su - git

cd ~

mkdir ~/bin

git clone git://github.com/sitaramc/gitolite

gitolite/install -ln ~/bin

ls ~/bin

Run below cmd on local machine :-

ssh-keygen or ssh-keygen -C "saurabh"


cp .ssh/id_rsa.pub saurabh.pub

scp saurabh.pub git@gitserver:/home/git

Server :-
export PATH=/home/git/bin:$PATH

gitolite setup -pk saurabh.pub

local System :-
git clone git@gitserver:gitolite-admin

#For Alias

less ~/.ssh/config

Host alias
   Hostname gitserver
    User git
    IdentityFile ~/.ssh/saurabh

##########################

ssh git@gitserver help


svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt


git svn clone http://192.168.1.7/cbs_img --trunk=.  --authors-file=users.txt  -s cbs_img


cd cbs_img

#git init
git remote add origin git@gitserver:cbs_img.git

git push origin --all


git svn rebase

git svn dcommit

git pull origin master

git svn dcommit

# for change into svn
git commit -am 'Adding git-svn instructions to the README'

git svn dcommit


####
git update-ref refs/heads/master refs/remotes/git-svn

git config svn.authorsfile users.txt

git svn clone http://192.168.1.7/cbs_pwa --trunk=.  --authors-file=users.txt  -s cbs_pwa --username=saurabh


############# Integrating Jenkins with Gitolite ##################
Ref Url :- https://wiki.jenkins.io/display/JENKINS/Gitolite

cd /var/lib/jenkins
/var/lib/jenkins$ sudo -u jenkins ssh-keygen
sudo -u jenkins cat .ssh/id_rsa.pub
~/gitolite-admin$ vim keydir/jenkins.pub


12:04:37 (master) ~/gitolite-admin$ vim conf/gitolite.conf
@development_team = bob carol ted alice

repo gitolite-admin
    RW+     =   hesco

repo myproject
    RW+     =   hesco
    RW      =   @development_team
    R       =   jenkins

git add keydir/jenkins.pub conf/gitolite.conf

git commit keydir/jenkins.pub conf/gitolite.conf

git push origin

/var/lib/jenkins/workspace/myproject$ sudo -u jenkins git clone git@gitserver:myproject

/var/lib/jenkins/workspace$ sudo -u jenkins rmdir myproject


sudo apt install -f # for install dependency

/var/lib/jenkins/secrets/initialAdminPassword # jenkins admin pwd




rsync -avzh --cvs-exclude /var/lib/jenkins/workspace/newcommunity_dev/ community@192.168.20.140:/home/product/community/saurabh/.


sudo su jenkins

sshpass -p "Devtest12" rsync -avzh --cvs-exclude /var/lib/jenkins/workspace/newcommunity_dev/ community@192.168.20.140:/home/product/community/saurabh/.


**************************************Git-web****************
https://gist.github.com/peter279k/6ac3a8a8ef2e1f24a48679713af50969



###################################33
cd REPONAME
git init
git add .
git commit -m 'initial commit' -a
git remote add origin git@gitserver:.git
git push origin master:refs/heads/master
git push --set-upstream origin master

Mysql :: Delete Duplicate Records

# Delete Duplicate Tag


Topic Table :-
id primary key
topic_slug
topic_name

Tag Table:-
id primary key
tag_slug (not unique)
tag_name

Topic Tag Table (Relation table):-
id primary key
topic_id (Foreign key)
tag_id (Foreign key)
topic_id,tag_id key (not unique)

Due to non unique duplicate records occur , Now we have to remove duplicate records, So Mysql query :-

select min(id),group_concat(id) from tag t2 group by slug having count(slug) > 1;

create table temp_tag as select t1.id as t1_tag_id,t2.id as t2_tag_id FROM  tag t1, tag t2 WHERE t1.id < t2.id AND t1.slug = t2.slug;

update tag,temp_tag set tag_id = t1_tag_id where t2_tag_id = tag_id;

DELETE t2 FROM tag t1, tag t2 WHERE t1.id < t2.id AND t1.slug = t2.slug;

drop table temp_tag;

FCM (Firebase Cloud Messaging) :: User not receive offline message

              FCM (Firebase Cloud Messaging) ::  User not receive offline message 
When we move from GCM (Google Cloud Messaging) to FCM (Firebase Cloud Messaging) . During Testing we find out there is an issue in FCM i.e User not receive offline message . FCM API HTTP Response code is 200 :-

{"multicast_id":********,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"******"}]}

Then , I report this issue to https://firebase.google.com/support  by filling necessary Details on there support URL :- https://support.google.com/firebase/contact/support?page=/fcm/delivery/diagnose/web/data .

During meantime I was checked by manipulating API Params . Then I find out adding time_to_live with some value for example 2419200 #four weeks its working fine . 

Same I communicate to @kat (firebase-help@google.com Support team) because it is bug from FCM . As per FCM document :- https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-plain-text it is optional and the default value is 4 weeks.
Below mail send by google (firebase-help@google.com) :-

Hi Saurabh, 

Thanks for the update. Happy to hear that adding time_to_live helped fix the issue.

This sounds like a bug, though. As you've noted from our documentation, requests that don't contain this field default to the maximum period of four weeks.

...
Regards, 
Kat


In Node Server we send notification by using below code :-


var request = require('request'); // npm i request                
if (TTL) {
                        TTL = 2419200; // Default TTL is four weeks.
 }      
// Before Background notificatin fix
//var postData ='{"data":{"title":"'+title+'","body":"'+body+'","icon":"'+ImageIcon+'","click_action":"'+weburl+'","requireInteraction":true,"tag":"'+Math.random()+'"},"to":"'+endpoint+'"}'; 

 var postData ='{"data":{"title":"'+title+'","body":"'+body+'","icon":"'+ImageIcon+'","click_action":"'+weburl+'","requireInteraction":true,"tag":"'+Math.random()+'"},"to":"'+endpoint+'","priority":10,"time_to_live": '+TTL+'}';
              var url = 'https://fcm.googleapis.com/fcm/send';
                var options = {
                        method: 'post',
                        body: JSON.parse(postData),
                        json: true,
                        url: url,
                        headers: {'content-type' : 'application/json',
                        'Authorization':'key=*********,'Urgency':'high'}
                }
                request(options, function (err, res, body) {
                        if (err) {
                                console.error('error posting json: ', err)
                                throw err
                        }
                                //console.log(res);
                        var headers = res.headers;
                        var statusCode = res.statusCode;