Skip to content

Instantly share code, notes, and snippets.

View gognjanovski's full-sized avatar
🏠
Working from home

Gavril Ognjanovski gognjanovski

🏠
Working from home
View GitHub Profile
@gognjanovski
gognjanovski / gist:0f538ec686eecda43f14d8a57c763441
Last active July 23, 2017 12:13
Renew access token method
namespace Com.Example.Controllers
{
[Authorize]
public class HomeController : Controller
{
public HomeController()
{
}
//Use Refresh Token to generate new Access Token
(function () {
'use strict';
angular.module('token.service')
.factory('AuthorizationTokenService', AuthorizationTokenService);
AuthorizationTokenService.$inject = ['$q', '$injector'];
function AuthorizationTokenService($q, $injector) {
//Local storage for token
var tokenVM = {
accessToken: null,
(function () {
'use strict';
var core = angular.module('config');
core.config(configure);
configure.$inject = ['$httpProvider'];
/* @ngInject */
function configure($httpProvider) {
@gognjanovski
gognjanovski / create_dictionary.m
Created November 8, 2018 18:05
Create spam filter word dictionary
allwords = "";
% - Load and concatenate all the emails in one string
Files=dir('data/*/*.txt');
for k=1:length(Files)
FileNames = Files(k).name;
dr = Files(k).folder;
file = fileread(strcat(dr, '\', FileNames));
file = regexprep(file, '\<\w{1,2}\>', "");
allwords = strcat(allwords, ' ', file);
@gognjanovski
gognjanovski / process_email_features
Created November 8, 2018 20:37
Process Spam and Nonspam Emails
dictionaryList = get_dictionary_list();
#Train Features
#Train Labels
docId = 1;
featureTrain = zeros(1,3);
labelTrain = zeros(1,1);
@gognjanovski
gognjanovski / training_ml_model
Last active November 8, 2018 23:47
Training the model using Naive Bayes algorithm
numTrainDocs = 100;
numTokens = 2500;
% - Load train emails features
M = dlmread('train-features.txt', ' ');
spmatrix = sparse(M(:, 1), M(:, 2), M(:, 3), numTrainDocs, numTokens);
train_matrix = full(spmatrix);
% - Load train emails labels
train_labels = dlmread('train-labels.txt', ' ');
@gognjanovski
gognjanovski / test_ml_model
Created November 9, 2018 00:36
Test Naive Bayes Model on Email Test Data Set
N = dlmread('test-features.txt', ' ');
test_matrix = sparse(N(:, 1), N(:, 2), N(:, 3));
numTestDocs = size(test_matrix, 1);
numTestTokens = size(test_matrix, 2);
output = zeros(numTestDocs, 1);
% - Probability that one email is spam, number of spam emails divided by number of all emails
% - Because the ration of spam - nonspam emails in the training set is 50:50 this probability will be 0.5 (50%)
@gognjanovski
gognjanovski / getCsvData.m
Created November 30, 2018 13:01
Get Csv Data
function data_reshape = getCsvData(filename)
%GETCSVDATA load the csv data into cell array
fileID = fopen(filename,'r');
% Start row is 1 since the first line is the heading (name of the columns)
startRow = 1;
data = textscan(fileID, '%d %d\n', 'Delimiter', ';',...
'HeaderLines', startRow,'ReturnOnError', false);
fclose(fileID);
@gognjanovski
gognjanovski / swe_pop_2007_2017.csv
Last active December 5, 2018 16:43
Sweden Population Data
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
Year;Population
2007;9182927
2008;9256347
2009;9340682
2010;9415570
2011;9482855
2012;9555893
2013;9644864
2014;9747355
2015;9851017
% Load Population Data
statistics_data = getCsvData('swe_pop_2007_2017.csv');
% Convert cell to matrix
X = cell2mat(statistics_data(:,1));
y = cell2mat(statistics_data(:,2));
% Convert matrix values to double
X = double(X);
y = double(y);