My Hive Posts

    Written by Coding Defined who lives and works in India building useful things. You should follow him on Twitter

    How to Approach Utopian.io Regex Task Request

    May 25, 2018
    how-to-approach-utopian-io-regex-task-request

    So Utopian.io recently created a Task Request for Developers where they wanted skilled JS Developers and Regex experts which you can check here https://steemit.com/utopian-io/@utopian.tasks/js-developers-and-regex-experts-wanted-javascript-coding-task. Now there are quite a few checks you have to do before giving the result back. In the task request, it is specifically mentioned that that "Parse the text and compare it with a set of regular expressions", thus instead of easy split functions we should use REGEX. So lets find out how to approach this Task Request. First Of All, in the task request it is clearly mentioned that always it starts with "@utopian-bot !utopian", that means we have some starting point. Now using the Regex Expression we will check if the input test starts with @utopian-bot !utopian or not. I use https://regex101.com/ to check all my regex because it gives a clear explanation how my Regex Expression worked. Now since I know that my input will start with @utopian-bot !utopian I will start my regex with @utopian-bot !utopian* which means match everything which starts with "@utopian-bot !utopian". Next is to get the value after "@utopian-bot !utopian" which can be done using the Regex `@utopian-bot !utopian *([^\n]*)`. The Explanation from https://regex101.com/ is ![](https://cdn.steemitimages.com/DQmTLYwgaEEkFz6VygQddaaPxPkYCGj6YLc7arNsFCCUubA/image.png) `([^\n]*)` means get all the characters from the single line and then add it as a group. Thus we will get blank or the beneficiaries i.e. [], or '@mention1 @mention2 @mention3 @mention4' or '@mention1:15% @mention2:35% @mention3:25% @mention4:25%'. Our Next Part is to get the mention and the appropriate weight of that mentions which can be done using the regex `(\w+(?::)(\d+)?) ` which is creating groups of mention:weight as shown below ![](https://cdn.steemitimages.com/DQmfWSUnnSMxZroCZd9oTAykfEbQv5poVzcykNEoPWUmWT8/image.png) `\w+` matches any word character `:` matches the character : literally (case sensitive) `\d+` matches a digit (equal to [0-9]) Now after that you will get a group, thus you have to loop through it and send the mention and weight in the beneficiary. This is a how you approach for the similar Task Request in teh future.

    Street Photography - Kodaikanal - Happy Face

    May 24, 2018
    street-photography-kodaikanal-happy-face

    Street Photography - Kodaikanal, Tamil Nadu, India. A shopping place in the frame where a woman is happy to see people clicking photos of their shop. ![StreetPhotography.jpg](https://cdn.steemitimages.com/DQmQimszBytCHo5UkUsRxG6PFMsgzW6k55hHnZeTkyP1Mi5/StreetPhotography1.jpg) ### Camera: Nokia 6, Edited

    Travel to Red Fort in Delhi, India

    May 21, 2018
    travel-to-red-fort-in-delhi-india

    Red Fort is a fort which is situated in Delhi, India. It was a fort of Mughal Rulers who stayed here for more than 200 years. On the Independence Day, Prime Minister of India also delivers his speech after hoisting the Indian Flag at the main gate of the fort. ### View of Red Fort form a distance ![IMG_20180422_160450.jpg](https://steemitimages.com/DQmazjuToytjhZkhCaDpdeFKDVz47QT3aEVYWdxUcSyYuMV/IMG_20180422_160450.jpg) ### The surrounding area of Red Fort ![IMG_20180422_160900.jpg](https://steemitimages.com/DQmRJg3yQmpS2sQJSEiJnoBuY37WW4Z4CvDtupy3ArAqeyz/IMG_20180422_160900.jpg) ### Main Gate to go Inside the Fort ![IMG_20180422_162450.jpg](https://steemitimages.com/DQmUJFZXhtjeW46EuJ2fTaX8CfbMMMGkedrKr6GiPebdPHz/IMG_20180422_162450.jpg) ### Its a World Heritage Monument ![IMG_20180422_162835.jpg](https://steemitimages.com/DQmVzFKPGqdx9jZPS1L3k9SwrG4Qijzt2QMbJ9vbHnq1QRX/IMG_20180422_162835.jpg) ### Few Monumnets Inside the Read Fort Complex ![IMG_20180422_163800.jpg](https://steemitimages.com/DQmPuX979bAgCRwaX5R9WoNEBDHprFziFtQY3uG9aYaLLvb/IMG_20180422_163800.jpg) ![IMG_20180422_163858.jpg](https://steemitimages.com/DQmVAjCSf1RsqcFV8kiVeeBFyp7DhdgfG4hiuYoj9zzNxzW/IMG_20180422_163858.jpg) ![IMG_20180422_164246.jpg](https://steemitimages.com/DQmSnXXD7iYtjtfvCSqJXJcxbF7EqTjsLKZVdEcCPqxr4jd/IMG_20180422_164246.jpg) ![IMG_20180422_164640.jpg](https://steemitimages.com/DQmcMwS6gvsZhWd8ASnZ9jBxDKgjDcfDt4tcaaa1nq2cDpR/IMG_20180422_164640.jpg) # Camera : Nokia 6

    ColorChallenge - Thursday Green - Leaves

    May 17, 2018
    colorchallenge-thursday-green-leaves

    So I borrowed a Nikon D5200 from my friend to try out focusing. ![_DSC0047.jpg](https://steemitimages.com/DQmcz97qnWJbKT4HDuJ29pj42A4pHTvL9Zh6GMWj7PfVize/_DSC0047.jpg) ### Camera : Nikon D5200

    When You Are Standing Above the Clouds

    May 16, 2018
    when-you-are-standing-above-the-clouds

    So I was in KodaiKanal and where it was raining, the fog was so much that it looks like you are standing above the clouds. ![_DSC0213.jpg](https://steemitimages.com/DQmZN3hMG5hXTjPGqfNpg92oNpaTqJTk2HACPW6Py6QE7Nw/_DSC0213.jpg) ### Nokia 6 : Manual Mode

    How to get Details of All the Posts a Person Upvoted in Steemit

    May 14, 2018
    how-to-get-details-of-all-the-posts-a-person-upvoted-in-steemit

    #### Repository https://github.com/steemit/steem-js #### What Will I Learn? - You will learn How to get Votes Made by User - You will learn How to get Details about the Posts where Upvote is Made #### Requirements - Basic Understanding of Promises in JavaScript #### Difficulty - Basic #### Tutorial Contents This will be a very short tutorial where we will learn about getting all the posts you voted on whether it's a self-post or others posts. For this, you need to know two basic functions of Steem.js and they are getAccountVotes() and getContent(). getAccountVotes() gives you details about all the posts you have upvoted, where voter is the username without @. It will give you an array of objects. The object has authorperm which is a permalink of the post you voted, weight of the upvoted, reshares, percentage and the time as shown below. As you can see the time goes back to 2017, which means it gives me the upvotes from the start. ``` steem.api.getAccountVotes('codingdefined', function(err, result) { console.log(err, result); }); ``` ![](https://steemitimages.com/DQmTDvvnhAjQNDxwhexiQk9tDS8zTqxKB9xSfNdyUHJZLyw/image.png) Since I do not want to know the upvotes made by in 2017, so what I am gonna do is to reverse the array based on time so that I will get the latest upvote as shown below. ``` function compare(a,b) { if (a.time < b.time) return -1; if (a.time > b.time) return 1; return 0; } steem.api.getAccountVotes('codingdefined', function (err, resp) { if (err) console.log(err) resp.sort(compare); resp.reverse(); console.log(resp); }); ``` I have written a compare method, Sorted by Votes array and then reversed it. The sorting algorithm is for ascending order though I can change the logic, I just kept if anyone needs the array as an ascending order. Now I have the array which is sorted based on the most recent upvote. Next is to get the Content of the Post which I have upvoted, for that we will be using Promises as we have to call the Steemit Functions Asynchrously inside the loop of the array. Once done we will be combining all the promises and then create the list. Since there are quite a few data, so we will be taking only last 10 upvotes and then get the details. The Code of the same is, where we are first taking the 10 objects from the array and then looping it through the map function. Inside the loop, we are splittling the authorperm on '/' to get the author and permalink and then calling getContent asynchronously. At last we are combining all the promises and then displaying the result. ``` function compare(a,b) { if (a.time < b.time) return -1; if (a.time > b.time) return 1; return 0; } steem.api.getAccountVotes('codingdefined', function (err, resp) { if (err) console.log(err) resp.sort(compare); resp.reverse(); let promises = resp.slice(0, 10).map(r => { const autper = r.authorperm.split('/', 2); return steem.api.getContentAsync(autper[0], autper[1]) .then((result) => { return result }); }) Promise.all(promises) .then(results => { console.log(results); }) .catch(e => { console.error(e); }) }) ``` As you can see below my last upvote was on https://steemit.com/utopian-io/@amosbastian/introducing-football-a-python-wrapper-for-the-football-data-api. ![](https://steemitimages.com/DQmaTZhTRatZHSM5Gkm2EkHKFctyPvY9BG35EoNeYwNmtEZ/image.png) Thus this simple code gives you the understanding about how to combine two functions and get the required results. #### Resources https://github.com/steemit/steem-js/tree/master/doc #### Proof of Work Done https://github.com/codingdefined

    Getting Started with AspnetBoilerPlate

    May 12, 2018
    getting-started-with-aspnetboilerplate

    #### Repository - https://github.com/aspnetboilerplate/aspnetboilerplate #### What Will I Learn? - You will learn about AspnetBoilerPlate - You will learn about How to get started with AspnetBoilerPlate - You will learn the basic structure of the Code Base in AspnetBoilerPlate - You will learn about creating Tasks in AspnetBoilerPlate #### Requirements - Basic Understanding of C# - Visual Studio 2017 #### Difficulty - Basic #### Tutorial Contents ##### What is AspnetBoilerPlate Whenever you have to develop an application, you have to think about designing the architecture of the application, the security, the performance and how to minimize the development effort. What if I say that all the above things are already done for you, you just have to add the business logic to get up and running with the modern day application. This is where ASP.NET Boilerplate comes into the picture, which is an application framework which implements best practices thus helps the developers to focus only on the development of the application and do not think about the architecture. ##### How to get started with AspnetBoilerPlate To get started with ASP.NET Boiler Plate just head over to the https://www.aspnetboilerplate.com/Templates site and download the source code ![](https://steemitimages.com/DQmRnSjE5FGM4QKCaMNnDNGCjtRY9VrVMRDhKEFSXDNPWpr/image.png) ##### Basic structure of the Code Base in AspnetBoilerPlate When you download the Source Code you will be seeing the below structure of the Code Base. Now all of them are the different layers in the NLayered Architecture. ![](https://steemitimages.com/DQmVvMNunHegSKVU9KuzDGTQU48fVjmxcwPRgX6jq4xHdSg/image.png) **Infrastructure Layer** is the base layer of the framework where our ORM, Data Migrations, and other DB related tasks are done. In the ASPNETBoilerPlate it is done on the EntityFramework Core application. This is called infrastructure because it provides data to all other layers to be worked on. **Domain Layer** is the layer which has domain logic is written like the Entities which will talk to the Infrastructure Layer, the objects which will hold the value after fetching it from DB. The Core solution. **Application Layer** is the layer which acts as a link to fetch the values from the Domain Layer and pass it on to the frontend. It also helps in maintaining the authorization, session, caching etc. The application solution. **Service Layer** is the layer which is used to pass values if called as a REST Service. They mainly do not contain any logic, but just pass the values to the callee application. The Web.host solution. **Presentation Layer** is the layer which is shown to the end user and the end user interacts with it. The Web.MVC solution. The above are the NLayered architecture which sums up the whole application. #### Creating Tasks in AspnetBoilerPlate Since we know about the architecture, let's say if you want to build something like Steemit where you will store the Content in a database. For that you will be creating tasks, I will show how to do that. At first, you need to create a task in the Domain Layer i.e. .Core project. In the below code we have a created a SteemitPost which mainly contains three things Title, Body, and Tags. It is the simplest things you need when you create a Post. You can also see I have inherited the class CreationAuditedEntity because that will add which user has created this post and when. ``` using System.Collections.Generic; using Abp.Domain.Entities.Auditing; namespace MyApp { public class SteemitPost: CreationAuditedEntity { public virtual string Title { get; set; } public virtual string Body { get; set; } public virtual string Tags { get; set; } public SteemitPost(string title, string text, string tags) { Title = title; Body= text; Tags = tags; } } } ``` Next thing is that we have to add it to our infrastructure project i.e. EntityFramework. So inside DbContext.cs add the below line which basically tells the ORM that whenever you create the Database create SteemitPost entity too. ``` public virtual IDbSet SteemitPost { get; set; } ``` Then we have to run the Update-Database command from the Package Manager Console which creates the Table i.e. SteemitPost. Now we have a ready Database which has the required table SteemitPost and contains three Columns Title, Body and Tags. Next is how we get all the posts or specific posts. For that, we have to write a Service in an .Application Layer. At first, we will be creating a DTO i.e. or Data Transfer Object ``` using Abp.Application.Services.Dto; using Abp.AutoMapper; namespace MyApp { [AutoMapFrom(typeof(SteemitPost))] public class SteemitPostDto : CreationAuditedEntityDto { public string Title { get; set; } public string Text { get; set; } public string Tags { get; set; } } } ``` Next is to define an interface for my DTO ``` public interface ISteemitPostAppService : IApplicationService { PagedResultDto GetSteemitPosts(GetSteemitPostInput input); } ``` And then writing the actual logic to get all the posts ``` [AbpAuthorize] public class SteemitPostAppService : ApplicationService, ISteemitPostAppService { private readonly IRepository _SteemitPostRepository; public SteemitPostAppService(IRepository steemitPostRepository) { _steemitPostRepository= steemitPostRepository; } public PagedResultDto GetSteemitPosts(GetSteemitPostInput input) { var posts= _steemitPostRepository .GetAll() .ToList(); return new PagedResultDto { Items = posts.MapTo>() }; } } ``` That's it done, now we just have to call the Application Layer from the Frontend to get all the Steemit Posts. It is just for basic understanding is to how easy is the development when you have a framework like AspNetBoilerPlate.

    ColorChallenge - Friday Blue - Sky

    May 11, 2018
    colorchallenge-friday-blue-sky

    ![IMG_20180511_153801.jpg](https://steemitimages.com/DQmbGQZ54bcAs1hYKUWoDTdMjQn6GdRfQzTzi5WFPx6YMQ3/IMG_20180511_153801.jpg) Camera : Nokia 6

    ColorChallenge - Thursday Green - Golconda Fort

    May 10, 2018
    colorchallenge-thursday-green-golconda-fort

    This image is of Front Side of the Golconda Fort in Hyderabad. The fun part is that the fort is spread across 11 km. ![IMG_20180324_101014.jpg](https://steemitimages.com/DQmTq4X5nJpABopsictVxa66LvYDyWy6uweLjTTMRVLKDrf/IMG_20180324_101014.jpg) ![IMG_20180324_100956.jpg](https://steemitimages.com/DQmayEEohBCd1qJiEPh83YxQJHLygqZTSGy1RvS26NzB84A/IMG_20180324_100956.jpg) ### Camera : Nokia 6