text:
<repo_name>an23lm/GitBundlePlus<file_sep>/modules/git_cmd.py
#!/usr/bin/env python

import os
import subprocess
from .constants import Constants

class Git:

    statuslist = []
    stashlist = []

    @staticmethod
    def status(path):
        cmdstring = ['cd {}; git status -s'.format(path)]
        cmd = subprocess.Popen(cmdstring, shell=True, stdout=subprocess.PIPE)
        cmd.wait()
        for line in cmd.stdout:
            Git.statuslist.append(line)
        return cmd.returncode

    @staticmethod
    def stash_list(path):
        cmdstring = ['cd {}; git stash list'.format(path)]
        cmd = subprocess.Popen(cmdstring, shell=True, stdout=subprocess.PIPE)
        cmd.wait()
        if cmd.returncode == 0:
            cmdstring = ['cd {}; git stash list | grep -o \"stash@{{.*}}\"'.format(path)]
            cmd = subprocess.Popen(cmdstring, shell=True, stdout=subprocess.PIPE, universal_newlines=True)
            cmd.wait()
            for line in cmd.stdout:
                Git.stashlist.append(line.strip())
            return 0
        return cmd.returncode

    @staticmethod
    def stash(path):
        cmdstring = ['cd {}; git stash -u | grep "No .*"'.format(path)]
        cmd = subprocess.Popen(cmdstring, shell=True, stdout=subprocess.PIPE)
        cmd.wait()
        return cmd.returncode

    @staticmethod
    def tag_ref(tag_name, ref_name, path):
        cmdstring = ['cd {}; git tag {} {}'.format(path, tag_name, ref_name)]
        cmd = subprocess.Popen(cmdstring, shell=True, stdout=subprocess.PIPE)
        cmd.wait()
        return cmd.returncode

    @staticmethod
    def tag_refs(path):
        for idx, name in enumerate(Git.stashlist):
            Git.tag_ref(Constants.stash_tag_pattern.format(idx), name, path)

    @staticmethod
    def bundle(path):
        cmdstring = ['cd {}; git bundle create {}{} --all'.format(path, os.path.basename(path), ".bundle")]
        cmd = subprocess.Popen(cmdstring, shell=True, stdout=subprocess.PIPE)
        for line in cmd.stdout:
            print(line)
        cmd.wait()
        print(cmd.returncode)
        return cmd.returncode

    @staticmethod
    def del_tag_ref(tag_name, path):
        cmdstring = ['cd {}; git tag -d {}'.format(path, tag_name)]
        cmd = subprocess.Popen(cmdstring, shell=True, stdout=subprocess.PIPE)
        cmd.wait()
        return cmd.returncode

    @staticmethod
    def del_tag_refs(path, stashcode):
        if stashcode == 0:
            Git.del_tag_ref(Constants.stash_tag_pattern.format(Constants.stash_tag_latest), path)
        for idx in range(len(Git.stashlist)):
           Git.del_tag_ref(Constants.stash_tag_pattern.format(idx), path)

    @staticmethod
    def get_current_branch(path):
        cmdstring = ['cd {}; git branch | grep \* | cut -d " " -f 2'.format(path)]
        cmd = subprocess.Popen(cmdstring, shell=True, stdout=subprocess.PIPE)
        cmd.wait()
        return cmd.returncode
<file_sep>/README.md
# Git Bundle Plus

Bundle a local git project with all uncommitted changes, unstaged files, and stashes (git bundle on steroids).

## Contents
- [Requirements](#req)
- [Installation](#inst)
- [Usage](#usage)
- [Example](#ex)
- [**.bundle** output + retrieve git project](#output)
- [How it works](#works)
- [Like](#love)
- [Contributers](#con1)
- [Contribute](#con2)
- [License](#lice)

## Requirements ✅
* Python 3

## Installation 🔌

### Using pip
Use the package manager [pip](https://pip.pypa.io/en/stable/) to install [Git-Bundle-Plus](https://pypi.org/project/Git-Bundle-Plus/).

```bash
pip install git-bundle-plus
```
### Clone + Python 3
```bash
git clone https://github.com/an23lm/GitBundlePlus.git
```
```bash
python ./gitbundleplus [-h] path
```

## Usage 👩💻

```bash
gitbundleplus [-h] path
```
**-h** : Help

**path** : Path to local git project folder you would like to bundle

##### ⚠ Note: After using `gitbundleplus` on a project the uncommitted and unstaged files will be statshed. You can easily retrieve these files by using `git stash apply` and drop the applied stash with `git stash drop` if you have no further need for it.

## Example 👶

### Bundle project
```bash
gitbundleplus ~/Documents/mygitproject
```

### Unbundle project
```bash
git clone ~/Documents/mygitproject.bundle
```

### Retrieve uncommited and unstanged changes
```bash
git stash apply ga-stash-tag-{ga-latest}
```

## `.bundle` output + retrieve git project 📦
`<git-folder-name>.bundle` will be created in the git folder specified.

### To unbundle the bundled git project, clone the bundle.
```bash
git clone path/to/bundle
```

### Restore the unstaged and uncommitted changes.

All the unstaged and uncommitted changes are stashed (`git stash`) and tagged (`git tag`) before bundling.

```bash
git stash apply ga-stash-tag-{ga-latest}
```

Delete the tag to drop the stash after your done applying.
```bash
git tag -d <tag-name>
```

### Find and apply your previously stashed changes.

`git tag list` to view all your previously stashed changes, tagged with the pattern `ga-stash-tag-{<stash-number>}`. Apply and drop these tagged stashes as per your requirements.
```bash
git stash apply <tag-name>
```
Delete the tag to drop the stash after your done applying.
```bash
git tag -d <tag-name>
```

##### ⚠ Note: Unbundled projects do not checkout to your current working branch. They default to `master` branch. Please, take care to use `git checkout <branch-name>` to start using a particular branch before applying stashed changes.

#### Please read [How it works](#works) for more information.

## How it works ⚙
1. `git stash list` is run and all the previously stashed items are tagged with the pattern `ga-stash-tag-{<stash-number>}`. *Example: `git tag ga-stash-tag-{0} stash@{0}`*.
2. Stash uncommited and unstaged changed using `git stash -u`. If a stash is created, this stash will be assigned the tag `ga-stash-tag-{ga-latest}`.
3. Bundle the git project using `git bundle <git-folder-name>.bundle` and the bundle is placed in the git folder.
4. All the tags from the original git project will be removed. *Example: `git tag -d ga-stash-tag-{0}`*.

## Show some love ❤
If you found this interesting or helpful, leave a star. ⭐

## Contributers 👨👩👧👦
* [<NAME>](https://github.com/an23lm)

## Contribute 💪
Pull requests are welcome.

## License 📃
[MIT](https://choosealicense.com/licenses/mit/)
<file_sep>/modules/constants.py
#!/usr/bin/python

class Constants:
    stash_tag_pattern = "ga-stash-tag-{{{}}}"
    stash_tag_latest = "ga-latest"
    git_ignore = ".gitignore"
<file_sep>/modules/__init__.py
from .constants import *
from .git_cmd import *<file_sep>/gitbundleplus
#!/usr/bin/env python

import sys
import os
from modules.git_cmd import Git
from modules.constants import Constants
import argparse

def dir_path(string):
    if os.path.isdir(string):
        return string
    else:
        raise NotADirectoryError(string)

if __name__ == "__main__":
    default_dir = os.getcwd()
    parser = argparse.ArgumentParser(description="Bundle a local Git project with all uncommitted changes and stashes.")
    parser.add_argument("path", help="Git directory to archive", type=dir_path, default=default_dir)
    args = parser.parse_args()
    cwd = os.path.realpath(args.path)

    if Git.status(cwd) != 0:
        print("An error occured when performing `git status ...`")
        sys.exit()
    if Git.stash_list(cwd) != 0:
        print("An error occured when performing `git stash list`")
        sys.exit()
    Git.tag_refs(cwd) != 0
    stashcode = Git.stash(cwd)
    if stashcode == 0:
        Git.tag_ref(Constants.stash_tag_pattern.format("ga-latest"), "stash@{{0}}", cwd)
    if Git.bundle(cwd) != 0:
        print("An error occured when performing `git bundle ...`")
        sys.exit()
    Git.del_tag_refs(cwd, stashcode)
<file_sep>/setup.py
import setuptools

with open("README.md", "r") as fh:
    long_description = fh.read()

setuptools.setup(
     name='Git Bundle Plus',
     version='0.9.1',
     author="<NAME>",
     author_email="<EMAIL>",
     description="Bundle a local Git project with all uncommitted changes and stashes (git bundle on steroids).",
     long_description=long_description,
     long_description_content_type="text/markdown",
     url="https://github.com/an23lm/GitBundlePlus",
     scripts=['gitbundleplus'],
     packages=['modules'],
     classifiers=[
         "Programming Language :: Python :: 3",
         "License :: OSI Approved :: MIT License",
         "Operating System :: OS Independent",
     ],
 )


text:
<repo_name>ricardoameijeiras/MeanShiftSegmentation<file_sep>/plotclusters3D.py
import numpy as np
import matplotlib.pyplot as plt

def plotclusters3D(data, labels, peaks):
    """
    Plots the modes of the given image data in 3D by coloring each pixel
    according to its corresponding peak.

    Args:
        data: image data in the format [number of pixels]x[feature vector].
        labels: a list of labels, one for each pixel.
        peaks: a list of vectors, whose first three components can
        be interpreted as BGR values.
    """
    fig = plt.figure()
    ax = fig.add_subplot(111, projection="3d")
    bgr_peaks = np.array(peaks[:, 0:2], dtype=float)
    rgb_peaks = bgr_peaks[...,::-1]
    rgb_peaks /= 255.0

    peaks_it = np.array(peaks[:, 0:2].T)

    for idx, peak in enumerate(peaks_it):
        inds = np.where(labels == idx + 1)
        cluster = data[:, inds[0]].T

        ax.scatter(cluster[:, 0], cluster[:, 1], cluster[:, 2], color='y', marker="*", s=.5, alpha=0.4)
        ax.scatter(peak[0], peak[1], peak[2], color='b', marker="x", s=110)

    plt.show()

def plotclusters3D_rgb(data, labels, peaks):
    """
        Plots the modes of the given image data in 3D by coloring each pixel
        according to its corresponding peak.

        Args:
            data: image data in the format [number of pixels]x[feature vector].
            labels: a list of labels, one for each pixel.
            peaks: a list of vectors, whose first three components can
            be interpreted as BGR values.
        """
    fig = plt.figure()
    ax = fig.add_subplot(111, projection="3d")
    bgr_peaks = np.array(peaks, dtype=float)
    rgb_peaks = bgr_peaks[..., ::-1]
    rgb_peaks /= 255.0

    colors = ["g", "y", "c", "b", "k"]

    for idx, peak in enumerate(peaks):
        inds = np.where(labels == idx + 1)
        cluster = data[:, inds[0]].T

        ax.scatter(cluster[:, 0], cluster[:, 1], cluster[:, 2], colors, marker="*")

    plt.show()
<file_sep>/imageSegmentation.py
import os
import pathlib
import sys
import time
import cv2
import matplotlib.pyplot as plt
import numpy as np
import scipy.io
from numpy import asarray
from scipy.ndimage import gaussian_filter
from scipy.spatial.distance import cdist
from skimage import color
from plotclusters3D import plotclusters3D, plotclusters3D_rgb

# findpeak optimized, necessary for the second speed-up
def findpeak_opt(data, idx, r, c, features_size):
    t = 0.01
    shift = np.array([1])
    dataT = data.T
    data_point = data[:, idx]
    data_pointT = data_point.T
    data_pointT = data_pointT.reshape(1, features_size)
    cpts = np.zeros(len(data.T))

    # Runs until the shift is smaller than the set threshold
    while shift.all() > t:
        # Calculate the euclidian distance between the current data point and
        # the rest of data (pairwise)
        dist = cdist(dataT, data_pointT)

        # We obtain where there are datapoints within our given radius - window.
        inds = np.where(dist <= r)
        datapoints_in_range = dataT[inds, :]

        # Points within a distance of r/c of the search path are obtained, and
        # a value of 1 is given
        cpts_idx = np.where(dist <= r/c)[0]
        cpts[cpts_idx] = 1

        # Peak is defined as the mean of every datapoint in range
        peak = np.mean(datapoints_in_range, axis=1)

        # We define our shift and data point is updated to get convergence
        shift = np.abs(data_pointT - peak[0])
        data_pointT = peak[0].reshape(1, features_size)

    return data_pointT.T, cpts

# Mean shift algorithm with two speed-ups
def meanshift_opt_2(data, r, c, features):
    labels = np.zeros(len(data.T))
    peaks = []
    label_no = 1

    # findpeak_opt is called for the first index out of the loop, to initialize peaks
    peak, cpts = findpeak_opt(data, 0, r, c, features)
    peakT = np.concatenate(peak, axis=0).T
    peaks.append(peakT)

    # Every data point is iterated through but will be ignored in case it's already
    # found in the labels list
    for idx in range(0, len(data.T)):
        if idx % 5000 == 0:
            print("Index", idx, "/", len(data.T))

        if labels[idx] != 0:
            continue

        # Points within distance r/c of the search path are associated with the
        # converged peak
        new_peak = True
        peak, cpts = findpeak_opt(data, idx, r, c, features)
        associated_points = np.where(cpts == 1)
        peakT = np.concatenate(peak, axis=0).T

        # It is check whether a new peak is found, or in the contrary we can bound
        # the one we found with an existent one
        for i in range(0, label_no):
            distance = cdist(np.array(peaks)[i].reshape(1, features), peakT.reshape(1, features))
            if distance < (r / 2):
                labels[associated_points] = i + 1
                new_peak = False
                break

        # In case it is a peak never seen before, we augment the number of labels,
        # append a new peak to the list and link its label to the associated points
        if new_peak:
            peaks.append(peakT)
            label_no += 1
            labels[associated_points] = label_no

    return labels.astype(int), np.array(peaks).T[0:3]

# Mean shift algorithm with one speed-up
def meanshift_opt(data, r):
    labels = np.zeros(len(data.T))
    peaks = []
    label_no = 1

    # findpeak is called for the first index out of the loop
    peak, inds = findpeak(data, 0, r)
    peakT = np.concatenate(peak, axis=0).T
    peaks.append(peakT)

    # First element of the labels list is always 1
    labels[inds[0]] = label_no

    # Every data point is iterated through but will be ignored in case it's already
    # found in the labels list
    for idx in range(0, len(data.T)):
        if labels[idx] != 0:
            continue

        # findpeak gets called for every data point (unless found previously in the
        # labels list)
        new_peak = True
        peak, inds = findpeak(data, idx, r)
        peakT = np.concatenate(peak, axis=0).T

        # In case it is a peak never seen before, we augment the number of labels, append
        # a new peak to the list and link its label to the associated points
        for i in range(0, label_no):
            distance = cdist(np.array(peaks)[i].reshape(1, 3), peakT.reshape(1, 3))
            if distance < (r / 2):
                labels[inds] = i + 1
                new_peak = False
                break

        # In case it is a peak never seen before, we augment the number of labels, append
        # a new peak to the list and link its label to the indices returned from findpeak
        if new_peak:
            peaks.append(peakT)
            label_no += 1
            labels[inds] = label_no

    return labels, np.array(peaks).T

# findpeak function suitable both for 0 speed-ups and one speed-up
def findpeak(data, idx, r):
    t = 0.01
    shift = np.array([1])
    data_point = data[:, idx]
    dataT = data.T
    data_pointT = data_point.T
    data_pointT = data_pointT.reshape(1, 3)

    # Runs until the shift is smaller than the set threshold
    while shift.all() > t:
        # Calculate the euclidian distance between the current data point and
        # the rest of data (pairwise)
        dist = cdist(dataT, data_pointT)

        # We obtain where there are datapoints within our given radius - window.
        inds = np.where(dist <= r)
        datapoints_in_range = dataT[inds, :]

        # Peak is defined as the mean of every datapoint in range
        peak = np.mean(datapoints_in_range, axis=1)

        # We define our shift and data point is updated to get convergence
        shift = np.abs(data_pointT - peak[0])
        data_pointT = peak[0].reshape(1, 3)

    return data_pointT.T, inds[0]

# Mean shift algorithm without speed-ups
def meanshift(data, r):
    labels = np.zeros(len(data.T))
    peaks = []
    label_no = 1
    labels[0] = label_no

    # findpeak is called for the first index out of the loop
    peak, inds = findpeak(data, 0, r)
    peakT = np.concatenate(peak, axis=0).T
    peaks.append(peakT)

    # Every data point is iterated through
    for idx in range(0, len(data.T)):
        new_peak = True
        peak, inds = findpeak(data, idx, r)
        peakT = np.concatenate(peak, axis=0).T

        # It is checked whether it is actually a new found peak or can be connected
        # to an already existent one
        for i in range(0, label_no):
            distance = cdist(np.array(peaks)[i].reshape(1, 3), peakT.reshape(1, 3))
            if distance < (r / 2):
                labels[idx] = i + 1
                new_peak = False
                break

        # In case it is a new peak, it gets appended to the list and the number of
        # labels is incremented
        if new_peak:
            peaks.append(peakT)
            label_no += 1
            labels[idx] = label_no

    return labels, np.array(peaks).T

# Returns the image with the coordinate concatenation for 5D features
def conc_coordinates(imglab, img):
    # Pair of coordinates for x and y are created
    x, y = np.mgrid[0:img.shape[0], 0:img.shape[1]]

    # Now, these coordinates get reshaped and concatenated to the image matrix
    X = np.reshape(x, (img.shape[0] * img.shape[1], 1))
    Y = np.reshape(y, (img.shape[0] * img.shape[1], 1))
    img_reshaped = np.concatenate((imglab, X, Y), axis=1)

    return img_reshaped

# Method for image segmentation
def segmIm(img, r, c, features):
    # Image gets reshaped to a 2D array
    img_reshaped = np.reshape(img, (img.shape[0] * img.shape[1], 3))

    # We will work now with CIELAB images
    imglab = color.rgb2lab(img_reshaped)

    # segmented_image is declared
    segmented_image = np.zeros((img_reshaped.shape[0], img_reshaped.shape[1]))

    if features == 3:
        # Mean shift algorithm function with two speed-ups is called
        labels, peaks = meanshift_opt_2(imglab.T, r, c, features)

        # Labels are reshaped to only one column for easier handling
        labels_reshaped = np.reshape(labels, (labels.shape[0], 1))

        # We iterate through every possible peak and its corresponding label
        for label in range(0, peaks.shape[1]):
            # Obtain indices for the current label in labels array
            inds = np.where(labels_reshaped == label + 1)[0]

            # The segmented image gets indexed peaks for the corresponding label
            corresponding_peak = peaks[:, label]
            segmented_image[inds, :] = corresponding_peak

    elif features == 5:
        # Concatenates the coordinates to imglab
        conc_img = conc_coordinates(imglab, img)

        # Mean shift algorithm function with two speed-ups is called
        labels, peaks = meanshift_opt_2(conc_img.T, r, c, features)

        # Labels are reshaped to only one column for easier handling
        labels_reshaped = np.reshape(labels, (labels.shape[0], 1))

        # We iterate through every possible peak and its corresponding label
        for label in range(0, peaks.shape[1]):
            # Obtain indices for the current label in labels array
            inds = np.where(labels_reshaped == label + 1)[0]

            # The segmented image gets peaks indexed for the corresponding label
            corresponding_peak = peaks[:, label]
            segmented_image[inds, :] = corresponding_peak

    else:
        print("Specified number of features is incorrect")

    # The segmented image gets reshaped and turn back into RGB for display
    segmented_image = np.reshape(segmented_image, (img.shape[0], img.shape[1], 3))

    print("Total number of found peaks:", peaks.shape[1] + 1)

    plotclusters3D_rgb(img_reshaped.T, labels, np.array(peaks.T))

    return color.lab2rgb(segmented_image)

def main(argv):
    # The given parameters get processed
    image = argv[0]
    radius = argv[1]
    feature_type = argv[2]
    c = 4

    path2data = os.path.join(pathlib.Path(__file__).parent.absolute(), 'data/pts.mat')
    path2img = os.path.join(pathlib.Path(__file__).parent.absolute(), image)

    # Mat file and image get loaded
    mat = scipy.io.loadmat(path2data)
    data = np.asarray(mat['data'])
    img = cv2.imread(path2img)

    # Uncomment any of the next tuples in case of desired testing
    #labels, peaks = meanshift_opt_2(data, float(radius), float(c), 3)
    #plotclusters3D(data, labels, peaks)

    #labels, peaks = meanshift_opt(data, float(radius))
    #plotclusters3D(data, labels, peaks)

    #labels, peaks = meanshift(data, float(radius))
    #plotclusters3D(data, labels, peaks)

    # PRE-PROCESSING

    # Normalization
    pixels = asarray(img).astype('float32')
    norm = (pixels - np.min(pixels)) / (np.max(pixels) - np.min(pixels))

    # Mean filter
    kernel = np.ones((5, 5), np.float32) / 25
    mean_filtered_img = cv2.filter2D(norm, -1, kernel)

    # Gaussian filter
    gaussian_filtered_img = gaussian_filter(norm, sigma=1)

    # Median blur
    median_filtered_img = cv2.medianBlur(norm, 5)

    # segIm is called, obtaining the segmented image
    segmented_image = segmIm(median_filtered_img, float(radius), float(c), int(feature_type))

    # Mean filtered normalized image is displayed
    cv2.imshow('Input image to segmIm', median_filtered_img)
    cv2.waitKey(0)
    plt.show()

    #Segmented image is finally shown
    cv2.imshow('Segmented image', segmented_image)
    cv2.waitKey(0)
    plt.show()

if __name__ == '__main__':
    main(sys.argv[1:])

branch_name: refs/heads/main

repo_language: Python

repo_name: ricardoameijeiras/MeanShiftSegmentation


text:
<repo_name>rentzso/tagapp<file_sep>/server.js

/**
 * Module dependencies.
 */

var express = require('express')
  , routes = require('./routes')
  , path   = require('path');

var app = module.exports = express.createServer();

// Configuration

app.configure(function(){
  app.set('views', __dirname + '/public/views');
  app.set('view engine', 'html');
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(path.join(__dirname, '/public')));
  app.set("view options", {layout: false});

  app.register('.html', {
    compile: function(str, options){
      return function(locals){
        return str;
      };
    }
  });
});

app.configure('development', function(){
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function(){
  app.use(express.errorHandler());
});
// connection to db and model creation

var mongoose = require('mongoose');

mongoose.connect('mongodb://localhost/rentzso');

var Schema = mongoose.Schema;

// the mongoDB model of the
var Tag = mongoose.model('Tag', new Schema({
  name: {type: String, index: true},
  links: [String]
}));

// Routes

// main page
app.get('/', routes.index);

// get request retrieves all the tags
app.get('/api/tags', function(req, res){
  //console.log(req);
  return Tag.find(function(err, tags) {
    return res.send(tags);
  });
});

app.get('/api/tags/:id', function(req, res){
  return Tag.findById(req.params.id, function(err, tag) {
    if (!err) {
      return res.send(tag);
    }
  });
});

app.put('/api/tags/:id', function(req, res){
  return Tag.findById(req.params.id, function(err, tag) {
    tag.name = req.body.name;
    tag.link = req.body.link;
    return tag.save(function(err) {
      if (!err) {
        console.log("updated");
      }
      return res.send(tag);
    });
  });
});

// post request handles passing data
// to the DB
app.post('/api/tags', function(req, res){
  //console.log(req);
  var tagList = [];
  //console.log(req.body);

  var index;
  // splitting the tags
  var in_tags = req.body.name.split(' ',20);

  //console.log(in_tags);

  // for each tag push the new link
  // in the link list relative to the tag
  for (index = 0;index < in_tags.length;index++) {
    (function(i){
      var cur_n = in_tags[i];

      Tag.update( { name : cur_n}, {$push: {links: req.body.link} },
		  { upsert: true}, function(err){
                                     console.log(err);
				     if (!err){
				       console.log('updated');
                                     }
                                   });
    })(index);
  }

  return res.send('');
});

app.delete('/api/tags/:id', function(req, res){
  return Tag.findById(req.params.id, function(err, tag) {
    return tag.remove(function(err) {
      if (!err) {
        console.log("removed");
        return res.send('')
      }
    });
  });
});

app.listen(17507);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
<file_sep>/readme.md
A simple tag app using Backbone, node.js and MongoDB inspired by the Backbone Todo application.

branch_name: refs/heads/master

languages: Markdown JavaScript

repo_language: Markdown

repo_name: rentzso/tagapp


text:
<repo_name>NathShubham28/Coursera-module-3<file_sep>/README.md
# Coursera-module-3


text: <file_sep># github-mahesh

repo_name: maheshmhanere/github-mahesh


text:
<file_sep>Here is a small Python project based on lists, here I go through various controls to make a basic traveler app!
It take various destinations and then adds various attractions, the traveler would then add there data and get a message response on good attractions
based on where they are going and there interests

repo_language: Text


text:
<repo_name>Italo-Neves/Assembly<file_sep>/ex02/entrada.asm
;Prigrama para entrada de dados

SYS_EXIT    equ 1
RET_EXIT    equ 5
SYS_READ    equ 3
SYS_WRITE   equ 4
STD_IN      equ 0
STD_OUT     equ 1
MAX_IN      equ 10

segment .data
    msg db "Entre com o seu nome: ",0xA,0xD
    len equ $- msg

segment .bss ;Blocked Start by Symbol
    nome resb 2

segment .text

global _start

_start:
    ; ax -> acumulador para operações númericas
    ; bx -> acumulador de registro base
    ; cx -> registro de conta
    ; dx -> registr de dados
    mov eax, SYS_WRITE
    mov ebx, STD_OUT
    mov ecx, msg
    mov edx, len
    int 0x80

;Entrada de dados
    mov eax, SYS_READ
    mov ebx, STD_IN
    mov ecx, nome
    mov edx, MAX_IN
    int 0x80

exit:
    mov eax, SYS_EXIT
    mov ebx, RET_EXIT
    int 0x80
<file_sep>/ex01/helloword.asm
;-------------------------------
; Programa hello word
;------------------------------

section .data: ;campo das variaves
    msg db 'hello, word!', 0xa
    len equ $ - msg

section .text:

global _start

_start:
    mov edx, len
    mov ecx, msg
    mov ebx, 1
    mov eax, 4
    int 0x80 ;endereço do kernel

    ;saída

    mov eax, 1
    mov ebx, 0
    int 0x80

repo_language: Assembly

repo_name: Italo-Neves/Assembly


text:
<file_sep>import os
import random
import math
import copy
import re

def add_dict(wl, d):
    for w in wl:
        if w in d:
            d[w] += 1
        else:
            d[w] = 1

# extract info from email
def extract(fname):
    text = open(fname)
    line = text.readline()
    searchObj = re.search( r'Received: from (.*)', line, re.M|re.I)
    url = searchObj.group(1)
    priority = 0
    while not line.split() == []:
        line = text.readline()
        searchObj = re.search( r'X-Priority: (.)', line, re.M|re.I)
        if not searchObj == None:
            priority = int(searchObj.group(1))
    body = text.read()
    return body.split(), url, priority

def load_data():
    data_cut_dir = "../trec06c-utf8/data_cut"
    label_file = open("../trec06c-utf8/label/index")

    pairs = []
    for line in label_file:
        info = line.split()
        email_path = os.path.join(data_cut_dir, info[1][-7:])
        # print(email_path)
        body, url, priority = extract(email_path)
        if info[0] == "spam":
            pairs.append((True, body, [url], [priority]))
        else:
            pairs.append((False, body, [url], [priority]))
    return pairs

def partition(data_list, num, train_rate):
    random.seed(1)
    random.shuffle(data_list)

    data_pack = {}

    train_size = int(len(data_list) * train_rate)
    test_set = data_list[train_size:]
    data_pack["test_set"] = test_set

    data_list = data_list[:train_size]
    length = int(math.ceil(len(data_list) * 1.0 / num))
    par_list = []
    for i in range(0, num - 1):
        par_list.append(data_list[length * i : length * (i + 1)])
    par_list.append(data_list[(num - 1) * length:])
    data_pack["train_set"] = par_list
    return data_pack

def judge_spam(words, spam_dic, ham_dic, url_l, spam_url, ham_url, pri_l, spam_pri, ham_pri, spam_num, ham_num, alpha, url_figure, pri_figure):
    url = url_l[0]
    pri = pri_l[0]
    # P(h|x1, ..., xn) : P(x1|h) * ... * P(xn|h)P(h)
    # [x]: email, h: spam
    spam_p = math.log(spam_num)
    ham_p = math.log(ham_num)
    for word in words:
        if word in spam_dic:
            spam_p += math.log(spam_dic[word])
        else:
            spam_p += math.log(alpha)
        if word in ham_dic:
            ham_p += math.log(ham_dic[word])
        else:
            ham_p += math.log(alpha)

    # print("spam: %f, ham: %f" % (spam_p, ham_p))
    if url in spam_url:
        spam_p += url_figure * math.log(spam_url[url])
    else:
        spam_p += url_figure * math.log(alpha)
    if url in ham_url:
        ham_p += url_figure * math.log(ham_url[url])
    else:
        ham_p += url_figure * math.log(alpha)
    # print("url spam: %f, ham: %f" % (spam_p, ham_p))

    if pri in spam_pri:
        spam_p += pri_figure * math.log(spam_pri[pri])
    else:
        spam_p += pri_figure * math.log(alpha)
    if pri in ham_pri:
        ham_p += pri_figure * math.log(ham_pri[pri])
    else:
        ham_p += pri_figure * math.log(alpha)

    if spam_p > ham_p:
        return True
    else:
        return False

def fold_train(data_pack, alpha, url_figure, pri_figure):
    data_list = data_pack["train_set"]
    test_set = data_pack["test_set"]

    n_fold = len(data_list)

    val_rate = 0
    best_spam_dic = {}
    best_ham_dic = {}
    best_spam_url = {}
    best_ham_url = {}
    best_spam_pri = {}
    best_ham_pri = {}
    best_spam_num = 0
    best_ham_num = 0
    best_accuracy = 0.0

    spam_dic = {}
    ham_dic = {}
    spam_url = {}
    ham_url = {}
    spam_pri = {}
    ham_pri = {}
    for i in range(0, n_fold):
        spam_dic.clear()
        ham_dic.clear()
        spam_num = 0
        ham_num = 0
        for j in range(0, n_fold):
            if i == j:
                val_set = data_list[j]
                continue
            for item in data_list[j]:
                if item[0]:
                    add_dict(item[1], spam_dic)
                    add_dict(item[2], spam_url)
                    add_dict(item[3], spam_pri)
                    spam_num += 1
                else:
                    add_dict(item[1], ham_dic)
                    add_dict(item[2], ham_url)
                    add_dict(item[3], ham_pri)
                    ham_num += 1
        correct = 0
        for item in val_set:
            if item[0] == judge_spam(item[1], spam_dic, ham_dic, item[2], spam_url, ham_url, item[3], spam_pri, ham_pri, spam_num, ham_num, alpha, url_figure, pri_figure):
                correct += 1
        current_rate = correct * 1.0 / len(val_set)
        print("No.%d patch: %f" % (i, current_rate))
        val_rate += current_rate

        if current_rate > best_accuracy:
            best_spam_dic = copy.deepcopy(spam_dic)
            best_ham_dic = copy.deepcopy(ham_dic)
            best_spam_url = copy.deepcopy(spam_url)
            best_ham_url = copy.deepcopy(ham_url)
            best_spam_pri = copy.deepcopy(spam_pri)
            best_ham_pri = copy.deepcopy(ham_pri)
            best_spam_num = spam_num
            best_ham_num = ham_num
            best_accuracy = current_rate

    val_rate /= n_fold
    print("Average Validate Accuracy: %f" % (val_rate))

    # test set
    correct = 0
    True2False = 0
    False2True = 0
    True_tol = 0
    False_tol = 0
    for item in test_set:
        if item[0]:
            True_tol += 1
        else:
            False_tol += 1
        if item[0] == judge_spam(item[1], best_spam_dic, best_ham_dic, item[2], best_spam_url, best_ham_url, item[3], best_spam_pri, best_ham_pri, best_spam_num, best_ham_num, alpha, url_figure, pri_figure):
            correct += 1
        else:
            if item[0]:
                True2False += 1
            else:
                False2True += 1
    test_rate = correct * 1.0 / len(test_set)
    print("Test Accuracy: %f" % (test_rate))
    print("Test Size: %d" % (len(test_set)))
    print("True2False: %d, %f" % (True2False, True2False * 1.0 / True_tol))
    print("False2True: %d, %f" % (False2True, False2True * 1.0 / False_tol))

if __name__ == "__main__":
    data_ori = load_data()
    data_pack = partition(data_ori, 10, 0.9)
    fold_train(data_pack, 0.00000001, 1000, 0)


text:
<repo_name>system-dev-formations/todo-flask-mysql<file_sep>/requirements.txt
Flask
Flask-SQLAlchemy
mysql-connector-python
mysqlclient
<file_sep>/INSTALL_UBUNTU.md
# Install on Ubuntu

## Pre-requisites
```shell script
sudo ufw disable
sudo apt-get -y install python3 python3-venv
python3 -m venv venv
source venv/bin/activate
sudo apt-get -y install build-essential
sudo apt-get install python3-dev libxml2-dev libxslt-dev
pip3 install docker-compose
````
Note: ssh tunnel ```ssh -L 3306:localhost:11000  ubuntu@172.16.58.3```

Add this command in mysql
Get your public ip address
https://www.showmyip.com/
```GRANT ALL ON foo.* TO bar@'public-ip-address' IDENTIFIED BY '<PASSWORD>';```<file_sep>/sql/todos.sql
-- phpMyAdmin SQL Dump
-- version 4.9.0.1
-- https://www.phpmyadmin.net/
--
-- Host: 172.17.0.2

-- version: 5.6.38-log
-- PHP Version: 7.2.19

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `tododb`
--

-- --------------------------------------------------------

--
-- Table structure for table `todos`
--
USE tododb;

CREATE TABLE `todos` (
  `todo_id` bigint(20) UNSIGNED NOT NULL,
  `title` varchar(60) COLLATE latin1_bin NOT NULL,
  `text` varchar(80) COLLATE latin1_bin NOT NULL,
  `done` varchar(50) COLLATE latin1_bin NOT NULL,
  `pub_date` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin;

--
-- Dumping data for table `todos`
--

INSERT INTO `todos` (`todo_id`, `title`, `text`, `done`, `pub_date`) VALUES
(1, 'test', 'test', '0', '2019-11-20'),
(2, 'qwerty', 'yyy', '0', '2019-11-20');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `todos`
--
ALTER TABLE `todos`
  ADD UNIQUE KEY `todo_id` (`todo_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `todos`
--
ALTER TABLE `todos`
  MODIFY `todo_id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
<file_sep>/README.md
# Todo-flask-mysql
Example on how to set up a multi-containers platform using Python-Flask and MySQL database

## How to set up the environment platform
Start a MySQL database container
```shell script
docker run -d --name dbm -e MYSQL_ROOT_PASSWORD=<PASSWORD> -p 3306:3306 \
-v /var/log/mysql-db:/var/log/mysql astondevops/docker-mysql-5.6
```
In your Goland Intellij IDE set a connection to the MySQL database
create a database named ```tododb```
and run the script ./sql/todos.sql

Launch a PhpMyAdmin container connected to MySQL database
```shell script
docker run -d  --name phpmyadmin --link dbm:mysql \
 -e MYSQL_USERNAME=root -p 8181:80 nazarpc/phpmyadmin
```
Get this repository
```git clone https://github.com/system-dev-formations/todo-flask-mysql.git```
Build todo-sql image
```cd todo-flask-mysql```
```docker build -t todo-mysql . ```

After type in your shell console
```code
docker run -d -it --name mytodo --link dbm:todo -p 26000:5000 todo-mysql
```

# Test
Bring up your favorite browser
``` http://localhost:5000/```
and check

# Docker-compose version
We are going to setup a python virtualenv
## On ubuntu
### Packages, virtualenv, activate
```code
sudo apt-get -y install python3
sudo apt-get -y install python3-pip
sudo apt-get -y install python3-venv
python3 -m venv venv
source venv/bin/activate
```
### docker-compose set up
```code
pip3 install wheel
pip3 install docker-compose
```
## On Centos
```code
sudo yum install python3
sudo yum install python3-pip
python3 -m venv venv
source venv/bin/activate
pip3 install docker-compose
pip3 install --upgrade pip
```
## Execute
In the directory todo-flask-mysql, hit
```docker-compose up ```
or
```docker-compose up -d```

languages: Markdown Text SQL

repo_name: system-dev-formations/todo-flask-mysql