Is this an anti-pattern to have a service have both APIs and listening to events?

I am planning to make a service which will have simple REST APIs and will have a database in backend. I also wanted to add a logic to listen to notifications emitted by other service and there is some business logic which will update the row in the database.

For updating the database row from Notifications, I can think of 2 approaches:

  1. Should I create a API which is kind of internal to just used by service and this listener process calls this API instead of directly updating the database?

  2. Listener process directly updates the service.

I can see some pros and cons of each approach. In Approach 1, we are adding a REST API unnecessarily which is never used by clients.

In Approach 2, we are giving one backside way to reach the database instead of all the requests coming from REST API.

Can someone help me here to tell if one of them is anti-pattern and which one is better to use?

Go to Source
Author: hatellaCollege

Slab SReclaimable memory can not be recycled?

CentOS Linux release 7.2.1511 (Core)

Linux version 3.10.0-514.26.2.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP TueJul 4 15:04:05 UTC 2017

/proc/meminfo:

MemTotal:       16267428 kB
MemFree:          237816 kB
MemAvailable:    7501712 kB
Buffers:           18076 kB
Cached:           745340 kB
SwapCached:            0 kB
Active:          5015316 kB
Inactive:         152100 kB
Active(anon):    4404088 kB
Inactive(anon):      972 kB
Active(file):     611228 kB
Inactive(file):   151128 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:              1928 kB
Writeback:             0 kB
AnonPages:       4404052 kB
Mapped:            36320 kB
Shmem:              1008 kB
Slab:           10579260 kB
SReclaimable:    6839864 kB
SUnreclaim:      3739396 kB
KernelStack:       19232 kB
PageTables:        25760 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     8133712 kB
Committed_AS:    7992196 kB
VmallocTotal:   34359738367 kB
VmallocUsed:       94920 kB
VmallocChunk:   34359635708 kB
HardwareCorrupted:     0 kB
AnonHugePages:   2297856 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:      161664 kB
DirectMap2M:    10323968 kB
DirectMap1G:     8388608 kB

slabtop:

 Active / Total Objects (% used)    : 18223363 / 42966058 (42.4%)
 Active / Total Slabs (% used)      : 1183671 / 1183671 (100.0%)
 Active / Total Caches (% used)     : 73 / 95 (76.8%)
 Active / Total Size (% used)       : 4513721.33K / 10427564.51K (43.3%)
 Minimum / Average / Maximum Object : 0.01K / 0.24K / 8.00K

  OBJS ACTIVE  USE OBJ SIZE  SLABS OBJ/SLAB CACHE SIZE NAME
6763716 6763212  99%    0.11K 187881       36    751524K sysfs_dir_cache
5604032 949314  16%    0.06K  87563       64    350252K kmalloc-64
4202094  67116   1%    0.04K  41197      102    164788K ext4_extent_status
3893484 2373049  60%    0.19K 185404       21    741616K dentry
3748191 1802716  48%    0.58K 138832       27   2221312K inode_cache
3251724 987321  30%    0.09K  77422       42    309688K kmalloc-96
2611301 1924963  73%    0.57K  93416       28   1494656K radix_tree_node
2590224 764829  29%    0.10K  66416       39    265664K buffer_head
2042465 284009  13%    0.05K  24029       85     96116K shared_policy_node
1802221 613054  34%    1.01K  58287       31   1865184K ext4_inode_cache
1263674 182269  14%    0.31K  50548       25    404384K nf_conntrack_ffffffff81aa0e80
1251789 210295  16%    0.19K  59609       21    238436K kmalloc-192
726016 686721  94%    0.03K   5672      128     22688K kmalloc-32
712992   9160   1%    0.50K  22281       32    356496K kmalloc-512
591360  43401   7%    0.12K  18480       32     73920K kmalloc-128
579564   4356   0%    0.11K  16099       36     64396K jbd2_journal_head
310514   4893   1%    2.00K  19576       16    626432K kmalloc-2048
183680 181248  98%    0.06K   2870       64     11480K kmem_cache_node
181936 180969  99%    0.25K   5686       32     45488K kmem_cache
130254   1632   1%    0.04K   1277      102      5108K Acpi-Namespace
 84512  19793  23%    1.00K   2641       32     84512K kmalloc-1024
 83312   2464   2%    0.25K   2608       32     20864K dquot
 80224  12022  14%    0.25K   2574       32     20592K kmalloc-256
 53538   2009   3%    1.94K   3347       16    107104K TCP
 39490  15690  39%    4.00K   5106        8    163392K kmalloc-4096
 28800    860   2%    1.56K   1440       20     46080K mm_struct
 23808  20992  88%    0.02K     93      256       372K kmalloc-16

To the problem:

I running some docker containers on this host, set mem limit about 13g(5g actually used). I want to start another java process, but killed by oom killer. SReclaimable of Slab can not be freed.

Things I tried

echo 3 > /proc/sys/vm/drop_caches

Go to Source
Author: nuaa_tiger

Backup and upgrade MongoDB databases

I have a web application using MongoDB (Version 2.6.12), hosted in a (Ubuntu 16.04) server of DigitalOcean.

I like to use Robo 3T to connect to the remote database and do simple queries.

Sometimes I backup the database with mongodump, and mostly rely on the weekly auto server snapshot provided by DigitalOcean.

Now, I need to undertake queries containing like $lookup, they told me that MongoDB Version 2.16.12 does not support that. So I need to seriously backup my database and use a more recent MongoDB. I still want to keep using Robo3T to do queries to production database (by preference) or backup database (if it is updated very often, e.g., every day).

I have several questions:

1) I would prefer to have a more regular auto-backup (e.g., every day) of the database. Which way is recommended? (Additionally, it seems that Atlas does NOT support Cloud Provider Snapshots for clusters served on DigitalOcean?)

2) If I buy a new server hosted on Azure and install MongoDB 4.2, and copy the whole database by mongodump to the new server, will it work?

Go to Source
Author: SoftTimur

How to add Multiple Section UICollectionViewCells in one view

I’m trying to build multiple section uicollectionview in the same view the first collection view working fine but when I added the second one the app crashed (lldb),
both are custom cells define a suprate classes i used if statement as showing in this Answer: https://stackoverflow.com/a/44692356/8386142?stw=2 the code is clear no errors it just crashed like there is something wrong with constraints (lldb)
here is the code that I used to build it the

import UIKit

struct areaCustomCellData {
    var lable: String
}

struct storesCustomCellData {
    var lable: String
}

class Search: UIViewController {

    let data = [
     areaCustomCellData(lable: "شرق النيل"),
     areaCustomCellData(lable: "بحري"),
     areaCustomCellData(lable: "امدرمان"),
     areaCustomCellData(lable: "الخرطوم"),
    ]

    let storesData = [
     storesCustomCellData(lable: "شرق النيل"),
     storesCustomCellData(lable: "بحري"),
     storesCustomCellData(lable: "امدرمان"),
     storesCustomCellData(lable: "الخرطوم"),
    ]

    let areaCView: UICollectionView = {
       let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .horizontal
       let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
        cv.translatesAutoresizingMaskIntoConstraints = false
        cv.register(customCell.self, forCellWithReuseIdentifier: "areaCell")
        cv.backgroundColor = UIColor(red: 245, green: 245, blue: 245, a: 1)
        cv.showsHorizontalScrollIndicator = false
       return cv
    }()

    let storesCView: UICollectionView = {
       let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .vertical
       let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
        cv.translatesAutoresizingMaskIntoConstraints = false
        cv.register(customCell2.self, forCellWithReuseIdentifier: "storesCell")
        cv.backgroundColor = UIColor(red: 245, green: 245, blue: 245, a: 1)
        cv.showsVerticalScrollIndicator = false
       return cv
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = UIColor(red: 245, green: 245, blue: 245, a: 1)
        view.addSubview(areaCView)
        view.addSubview(storesCView)

        storesCView.delegate = self
        storesCView.dataSource = self
        areaCView.delegate = self
        areaCView.dataSource = self

        setUpLayout()
        setUpNavBar()
        setUpSearchBar()

    }

    func setUpLayout(){
        areaCView.topAnchor.constraint(equalTo: view.topAnchor, constant: 120).isActive = true
        areaCView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
        areaCView.trailingAnchor.constraint(equalTo: view.trailingAnchor,constant: -20).isActive = true
        areaCView.heightAnchor.constraint(equalToConstant: 30).isActive = true

        storesCView.topAnchor.constraint(equalTo: view.topAnchor, constant: 500).isActive = true
        storesCView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
        storesCView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
        storesCView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true

    }

extension Search: UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        if indexPath.section == 0 {
           return CGSize(width: collectionView.frame.width/4, height: collectionView.frame.height)

        }else {
        return CGSize(width: collectionView.frame.width/4, height: collectionView.frame.height)
        }
    }

    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 2
    }

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return (section == 0) ? data.count : storesData.count
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt
        indexPath: IndexPath) -> UICollectionViewCell {
        if indexPath.section == 0 {
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "areaCell", for: indexPath) as! customCell
            cell.data = self.data[indexPath.row]
            cell.backgroundColor = UIColor.white
            cell.layer.cornerRadius = 10
            return cell

        }else{
            let cell2 = collectionView.dequeueReusableCell(withReuseIdentifier: "storesCell", for: indexPath) as! customCell2
            cell2.storesData = self.storesData[indexPath.row]
            cell2.backgroundColor = UIColor.white
            cell2.layer.cornerRadius = 10
            return cell2
        }


    }

}


class customCell: UICollectionViewCell {

    var data: areaCustomCellData? {
        didSet{
            guard let data = data else {return}

            areaLable.text = data.lable
        }
    }

    let areaLable: UILabel = {
       let lable = UILabel()
        lable.text = "الخرطوم"
        lable.font = .systemFont(ofSize: 12)
        lable.contentMode = .scaleAspectFit
        lable.clipsToBounds = true
        lable.textAlignment = .center
        lable.translatesAutoresizingMaskIntoConstraints = false
        return lable

    }()

    override init(frame: CGRect) {
        super.init(frame: frame)
        contentView.addSubview(areaLable)

        areaLable.topAnchor.constraint(equalTo: contentView.topAnchor).isActive = true
        areaLable.leadingAnchor.constraint(equalTo: contentView.leadingAnchor).isActive = true
        areaLable.trailingAnchor.constraint(equalTo: contentView.trailingAnchor).isActive = true
        areaLable.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

class customCell2: UICollectionViewCell {

    var storesData: storesCustomCellData? {
        didSet{
            guard let storesData = storesData else {return}

            storesLable.text = storesData.lable
        }
    }

    let storesLable: UILabel = {
       let lable = UILabel()
        lable.text = "الخرطوم"
        lable.font = .systemFont(ofSize: 12)
        lable.contentMode = .scaleAspectFit
        lable.clipsToBounds = true
        lable.textAlignment = .center
        lable.translatesAutoresizingMaskIntoConstraints = false
        return lable

    }()

    override init(frame: CGRect) {
        super.init(frame: frame)

        contentView.addSubview(storesLable)
        storesLable.topAnchor.constraint(equalTo: contentView.topAnchor).isActive = true
        storesLable.leadingAnchor.constraint(equalTo: contentView.leadingAnchor).isActive = true
        storesLable.trailingAnchor.constraint(equalTo: contentView.trailingAnchor).isActive = true
        storesLable.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

Go to Source
Author: mazenqp

How can I install more than one Desktop Environment in my Ubuntu without damaging the system?

How can I install more than one Desktop Environment in my Ubuntu without damaging the system? I want just to try those desktop. I know I can install them by sudo apt install kubuntu/xubuntu/lubuntu-desktop . But it will remove my existing Desktop Environment, right? I want that whenever I want to change the Desktop Environment, I will log out and log in to that. Is it possible to do that? Don’t say to download ISO image of Kubuntu, Xubuntu, Lubuntu as I want to see them in my current installation.

Go to Source
Author: Akib Azmain

Can’t install protoc-gen-grpc-web

I have downloaded a binary file from this page: https://github.com/grpc/grpc-web/releases/tag/1.0.7

and followed these steps:

sudo mv ~/Downloads/protoc-gen-grpc-web-1.0.7-linux-x86_64
/usr/local/bin/protoc-gen-grpc-web
$ chmod +x /usr/local/bin/protoc-gen-grpc-web

but it didn’t add up to PATH,full instructions here:
https://www.npmjs.com/package/grpc-web

Go to Source
Author: Aika Sat

Is this (explained in body) a possible attack vector when using haveibeenpwned API?

I’m currently working on understanding and contemplating to implement password strength validation for sign ups in my app, to include checking haveibeenpwned if entered password is compromised elsewhere.

I understand the process involves the site sending a partial hash of the password to HIBP and HIBP will respond whether it’s pwned.

I am also assuming that it is possible that HIBP stores logs of my API request and that it may contain information leading back to my app.

If HIBP gets hacked, and attacker gains access to the above hypothetical logs, assuming that it contains all the information in the original request – the partial hash and where it came from (my site), can the attacker construct an attack on my site is this way?

  1. Hash the passwords in the list of pwned password and get a list of hashes
  2. Match the partial hash he has with those in the above list and
    derive a refined dictionary of N number of possible passwords with
    same partial hash
  3. Try the passwords on my site

I am aware at every point in the above, measures can be put in place to mitigate each, e.g. 2FA. But it is not my objective to ask for how to secure my sign up, but to validate my concerns with using HIBP and whether there’s an attack vector to be considered.

PS: I’m not a security expert but I do know how passwords and hashes work. As HIBP is new to me, I don’t fully know how it works and all the features of its API. Pardon me if I made wrong assumptions.

Go to Source
Author: Aen Tan

Failed expand string in manualroute

I try add route with redirect based on mx record.

But my regexp never work.

Exim 4.90, os ubontu 18.04.

My config:

  driver     = manualroute
  #condition = ${lookup dnsdb{mxh=^mxd.mydom.net}{true}fail}
  condition  = ${lookup dnsdb{mxh=^.*$}{true}fail}
  transport  = non_mydom
  route_list = * 192.168.0.11

Test routing failed:

mk@mydom.net
    <-- mk@mydom.net
  router = dnslookup, transport = remote_smtp
  host mx1.mydom.net [xxxx] MX=10
  host mx2.mydom.net [xxxx] MX=20

Go to Source
Author: Terentev Maksim

My question is in a select statement how do you return the RID along with the table data?

I need your help with a concept I want to show developers, that concept is to help them understand how SQL Server retrieves data from the table. In the event that a developer does not use a clustered index on a table I want to be able to show them the RID (Row Identification number) SQL Server uses to find the record. So my question is in a select statement how do you return the RID?
I know that you can use the following to find where SQL Server stores the data in the data file.

SELECT TOP(100) sys.fn_PhysLocFormatter(%%physloc%%) AS [File:Page:Slot], *
FROM  [dbo].[Badges] ;
SELECT   TOP(100) *
FROM   [dbo].[Badges]
CROSS APPLY sys.fn_PhysLocCracker(%%physloc%%);

My question is in a select statement how do you return the RID along with the table data?

Go to Source
Author: Andy Eggers

Junior Developer Looking for Mentorship or Advice!

I am a Junior Developer in my first year of professional work experience, I have joined a very small start-up company where I am one of the few developers. We have two junior devs and an outsourced developer that helps with senior dev roles when needed. I am often tasked with jobs and tasks that are more likely to be given to an intermediate/senior developer and am having to learn a lot as I progress through development cycles and make mistakes.

I do not really have access to a senior developer to help mentor me properly and I feel as though I might be learning bad practices as I do not have someone that looks over my code. I generally work well and can get these tasks done but sometimes have to ask the outsourced developer for help, even in the tasks I complete although I think they are performing well I feel as though I am just getting by and not actually understanding half as much as I think I am.

I am wondering if there are any good sites where I can hire a mentor for about an hour a week where I can discuss with them the issues I faced that week and how I fixed them, etc. I wouldn’t need technical assistance, mostly just advice and assurance on the techniques I am using.

Cheers!

(I am a front end dev trying to expand into a full stack, I do almost all of the front end work of the website and am trying to learn more about the backend as I go.)

Go to Source
Author: Tomas Brown

Using tmux to host a server

So I have some API server that I need to be up 24/7. Is it a bad idea to open up a tmux window and run the server application? When you run a binary in tmux, the binary stays running even when you close the tmux window. The binary also stays running when I disconnect from the SSH session. I like running the server application in tmux because I can easily just attach to the tmux window and have access to a shell where the executable lives. The server constantly prints log messages to standard output, meaning I like to be able to read those messages in my tmux window. However, there is something that just seems off about this method of running a server application. I would prefer if the server could somehow run in the background, but I also want to be able to see the logs that the terminal is printing out at any given time. So, to summarize, is it a bad idea to run a server application in tmux? If so, what do I do instead so that I can still read the server application’s logs?

Go to Source
Author: Matt Y