<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by pradeep singh on Medium]]></title>
        <description><![CDATA[Stories by pradeep singh on Medium]]></description>
        <link>https://medium.com/@pradeep1991singh?source=rss-5060b58ac3d2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*alzvppyu46yGsn9F.jpg</url>
            <title>Stories by pradeep singh on Medium</title>
            <link>https://medium.com/@pradeep1991singh?source=rss-5060b58ac3d2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 02:03:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pradeep1991singh/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Git Branch Name Conventions]]></title>
            <link>https://medium.com/@pradeep1991singh/git-branch-name-conventions-b3934fd4bf0d?source=rss-5060b58ac3d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3934fd4bf0d</guid>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[branch-name]]></category>
            <category><![CDATA[git-branch]]></category>
            <dc:creator><![CDATA[pradeep singh]]></dc:creator>
            <pubDate>Sat, 22 Feb 2020 15:51:01 GMT</pubDate>
            <atom:updated>2020-02-22T15:51:01.282Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NqiUHULlv6279Q52kEQl9A.png" /></figure><p>A good, meaning-full, short Branch Name always helps :).</p><p>Branch Name which I always try to follow -</p><p>Thumb rule: use dashes (snake case) to separate words, and keep it short.</p><p>Scenarios:</p><p>1: Adding a new feature/screen Add Login screen .</p><p>Name: <strong>feature/add-login-screen</strong></p><p>2: Removing an old obsolete feature old login screen .</p><p>Name: <strong>feature/remove-old-login-screen</strong></p><p>3: Fixing a bug in Login Screen where the validation message is not correct.</p><p>Name: <strong>bugfix/login-validation-message</strong></p><p>4: Hotfix a bug in production where Login screenis not working.</p><p>Name: <strong>hotfix/login-screen</strong></p><p>5: Refactoring of a slow, stale or obsolete code of Login screen.</p><p>Name: <strong>refactor/login-screen</strong></p><p>7: Adding a library, package or any tool to help in the maintenance of code. e.g. adding a monitoring tool like Sonar Qube</p><p>Name: <strong>maintenance/add-sonarqube</strong></p><p>PS: Feel free to suggest updates anytime.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3934fd4bf0d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting started with SAML, Azure, and Nodejs]]></title>
            <link>https://medium.com/@pradeep1991singh/getting-started-with-saml-azure-and-nodejs-341879c64b01?source=rss-5060b58ac3d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/341879c64b01</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[saml]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[pradeep singh]]></dc:creator>
            <pubDate>Sat, 07 Sep 2019 11:40:42 GMT</pubDate>
            <atom:updated>2019-09-07T11:40:42.070Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*7onFcCI9qZPT_dXJQgswig.jpeg" /></figure><h3>Introduction</h3><p>Security Assertion Markup Language (SAML, pronounced SAM-el) is an open standard for exchanging authentication and authorization data between parties, in particular, between an identity provider and a service provider.</p><p>It’s used for logging users into applications based on their sessions in another context. This single sign-on (SSO) login standard has significant advantages over logging in using a username/password:</p><ul><li>No need for credentials</li><li>No need to remember and change passwords</li><li>No weak passwords</li></ul><p>Most organizations already know the identity of users because they are logged in to their Active Directory domain or intranet. It makes sense to use this information to log users into other applications, such as web-based applications, and one of the more elegant ways of doing this is by using SAML.</p><p>SAML is very powerful and flexible, but the specification can be quite a handful.</p><h3>How SAML works?</h3><p>SAML SSO works by validating user identity from an identity provider, for example from Azure active directory by validating the user’s identity from azure active directory (the identity provider) to web application (the service provider). This is done through an exchange of digitally signed XML documents.</p><p>Steps:</p><ul><li>A user is accessing a web application (the service provider).</li><li>A user enters an email address, the application identifies the user’s origin by email domain, based on the domain webserver (NodeJS) create SAML Request and send it to the identity provider (Azure active directory), asking for authentication.</li><li>The user either has an existing active browser session with the identity provider or establishes one by logging into the identity provider.</li><li>The identity provider builds the authentication response in the form of an XML-document containing the user’s email address, signs it using an X.509 certificate, and posts this information to the service provider.</li><li>The service provider, which already knows the identity provider and has a certificate fingerprint, retrieves the authentication response and validates it using the certificate fingerprint (using passport library available for NodeJs).</li><li>After identity established, the service provider callback the return URL extracting user’s email address and other details.</li><li>The application validates user identity and the user is provided with application access.</li></ul><h3>Flow Diagram</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/0*3YQN7ABploKzoWhF.jpg" /></figure><h3>Implementation</h3><h3>1. User access application</h3><pre><em>&lt;!--  entryPoint=</em><a href="https://login.microsoftonline.com/123456-xxxx-xxxx-xxxx-123456/saml2"><em>https://login.microsoftonline.com/123456-xxxx-xxxx-xxxx-123456/saml2</em></a><em> --&gt;</em><br>&lt;button class=&quot;btn-submit&quot;&gt;<br>  &lt;a :href=&quot;config.entryPoint&quot;&gt;SSO&lt;/a&gt;<br>&lt;/button&gt;</pre><h3>2. Create SAML Request</h3><pre><strong>const</strong> moment <strong>=</strong> require(&#39;moment&#39;)<br><em>// for deflating SAML request</em><br><strong>const</strong> pako <strong>=</strong> require(&#39;pako&#39;)<br><strong>const</strong> uuid <strong>=</strong> require(&#39;uuid&#39;)<br>.....</pre><pre><strong>const</strong> config <strong>=</strong> {<br>   <em>// domain of email address for identifying on client side if SAML is enable for same or not</em><br>  &quot;domain&quot;: &quot;<a href="http://outlook.com/">outlook.com</a>&quot;,<br>   <em>// unique entityId while setting up SAML server</em><br>  &quot;entityURI&quot;: &quot;<a href="https://example.com/">https://example.com</a>&quot;,<br>  <em>// SAML server login url, can be found in SAML XML file</em><br>  &quot;entryPoint&quot;: &quot;<a href="https://login.microsoftonline.com/123456-xxxx-xxxx-xxxx-123456/saml2">https://login.microsoftonline.com/123456-xxxx-xxxx-xxxx-123456/saml2</a>&quot;,<br>  <em>// X 509 signing certificate, can be found in SAML XML file</em><br>  &quot;certificate&quot;: &quot;MIIC8DCCAdigAwIBAgIQaKWqA3vVf7ZPHf5h52SkkjANBgkqhkiG9w0BAQsFADA0MTIwMAYDVQQDEylNaWNyb3NvZnQgQXMIIC8DCCAdigAwIBAgIQaKWqA3vVf7ZPHf5h52SkkjANBgkqhkiG9w0BAQsFADA0MTIwMAYDVQQDEylNaWNyb3NvZnQgQX8MIIC8DCCAdigAwIBAgIQaKWqA3vVf7ZPHf5h52SkkjANBgkqhkiG9w0BAQsFADA0MTIwMAYDVQQDEylNaWNyb3NvZnQgQX&quot;,<br>  <em>// callback url after successfully authentication</em><br>  &quot;entityReplyUrl&quot;: &quot;<a href="https://example.com/api/auth/saml">https://example.com/api/auth/saml</a>&quot;<br>}</pre><pre>.....</pre><pre>generateSAMLRequest (config) {<br>  <strong>const</strong> SAMLReq <strong>=</strong> `<strong>&lt;</strong>samlp:AuthnRequest<br>    xmlns<strong>=</strong>&quot;urn:oasis:names:tc:SAML:2.0:metadata&quot;<br>    ID<strong>=</strong>&quot;${config.domain}${uuid.v4()}&quot;<br>    Version<strong>=</strong>&quot;2.0&quot;<br>    IssueInstant<strong>=</strong>&quot;${moment().utc().format()}&quot;<br>    IsPassive<strong>=</strong>&quot;false&quot;<br>    AssertionConsumerServiceURL<strong>=</strong>&quot;${config.entityReplyUrl}&quot; xmlns:samlp<strong>=</strong>&quot;urn:oasis:names:tc:SAML:2.0:protocol&quot;<br>    ForceAuthn<strong>=</strong>&quot;false&quot;<strong>&gt;</strong><br>      <strong>&lt;</strong>Issuer xmlns<strong>=</strong>&quot;urn:oasis:names:tc:SAML:2.0:assertion&quot;<strong>&gt;</strong><br>        ${config.entityURI}<br>      <strong>&lt;</strong>/Issuer&gt;<br>      <strong>&lt;</strong>samlp:NameIDPolicy Format<strong>=</strong>&quot;urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified&quot;<strong>&gt;</strong><br>      <strong>&lt;</strong>/samlp:NameIDPolicy&gt;<br>    <strong>&lt;</strong>/samlp:AuthnRequest&gt;`</pre><pre>  <strong>const</strong> deflatedSAMLReq <strong>=</strong> pako.deflateRaw(SAMLReq)<br>  <strong>const</strong> deflatedBase64SAMLReq <strong>=</strong> Buffer(deflatedSAMLReq).toString(&#39;base64&#39;)<br>  <strong>const</strong> encodedDeflatedBase64SAMLReq <strong>=</strong> encodeURIComponent(deflatedBase64SAMLReq)</pre><pre>  <strong>return</strong> <strong>~</strong>config.entryPoint.indexOf(&#39;?&#39;)<br>    ? `${config.entryPoint}<strong>&amp;</strong>SAMLRequest<strong>=</strong>${encodedDeflatedBase64SAMLReq}`<br>    : `${config.entryPoint}?SAMLRequest<strong>=</strong>${encodedDeflatedBase64SAMLReq}`<br>}</pre><h3>3. Identity Established &amp; SAML Response returned</h3><ul><li>SAML Request sent to SAML server</li><li><a href="https://docs.microsoft.com/en-us/azure/active-directory/manage-apps/configure-single-sign-on-non-gallery-applications">Create SAML server on Azure active directory</a></li></ul><h3>4. App Verifies SAML Response &amp; Log User in</h3><ul><li><a href="https://github.com/bergie/passport-saml">Documentation</a></li></ul><p>Configure strategy for multiple providers You can pass a getSamlOptions parameter to MultiSamlStrategy which will be called before the SAML flows. Passport-SAML will pass in the request object so you can decide which configuration is appropriate.</p><pre><strong>var</strong> MultiSamlStrategy <strong>=</strong> require(&#39;passport-saml/multiSamlStrategy&#39;);</pre><pre>.....</pre><pre>passport.use(<strong>new</strong> MultiSamlStrategy(<br>  {<br>    getSamlOptions: <strong>function</strong>(request, done) {<br>      findProvider(request, <strong>function</strong>(err, provider) {<br>        <strong>if</strong> (err) {<br>          <strong>return</strong> done(err);<br>        }<br>        <strong>return</strong> done(<strong>null</strong>, provider.configuration);<br>      });<br>    }<br>  },<br>  <strong>function</strong>(profile, done) {<br>    findByEmail(profile.email, <strong>function</strong>(err, user) {<br>      <strong>if</strong> (err) {<br>        <strong>return</strong> done(err);<br>      }<br>      <strong>return</strong> done(<strong>null</strong>, user);<br>    });<br>  })<br>);</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=341879c64b01" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Full-stack development]]></title>
            <link>https://medium.com/@pradeep1991singh/full-stack-development-4be5350893d0?source=rss-5060b58ac3d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/4be5350893d0</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[pradeep singh]]></dc:creator>
            <pubDate>Fri, 23 Aug 2019 08:05:34 GMT</pubDate>
            <atom:updated>2019-08-23T08:05:34.342Z</atom:updated>
            <content:encoded><![CDATA[<p>Full-stack application development with front-end technologies</p><h3>Introduction</h3><p>Full-stack application development with front-end technologies</p><h3>Tech stacks</h3><ul><li>Package Manager NodeJS: <a href="https://nodejs.org/en/">nodejs</a></li><li>REST API: <a href="http://expressjs.com/">expressjs</a></li><li>Persistence storage: <a href="https://www.mongodb.com/">MongoDB</a></li><li>AngularJS: <a href="https://angularjs.org/">AngularJS</a></li></ul><h3>Backend setup and configuration</h3><h4>Initialization</h4><ul><li>Create api-server folder in fullstack-development folder and initialize api-serveropen terminal and type</li></ul><pre>$ npm init</pre><ul><li>Open package.json and copy below code in it</li></ul><pre>{<br>	&quot;name&quot;: &quot;api-server&quot;,<br>	&quot;version&quot;: &quot;1.0.0&quot;,<br>	&quot;description&quot;: &quot;fullstack application development with front-end technologies&quot;,<br>	&quot;main&quot;: &quot;api.js&quot;,<br>	&quot;scripts&quot;: {<br>		&quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br>	},<br>	&quot;repository&quot;: {<br>		&quot;type&quot;: &quot;git&quot;,<br>		&quot;url&quot;: &quot;<a href="https://github.com/pradeep1991singh/fullstack-development">https://github.com/pradeep1991singh/fullstack-development</a>&quot;<br>	},<br>	&quot;keywords&quot;: [<br>		&quot;fullstack&quot;,<br>		&quot;application&quot;,<br>		&quot;development&quot;,<br>		&quot;front-end&quot;,<br>		&quot;only&quot;,<br>		&quot;technologies&quot;<br>	],<br>	&quot;author&quot;: &quot;pradeep singh&quot;,<br>	&quot;license&quot;: &quot;ISC&quot;,<br>	&quot;dependencies&quot;: {<br>		&quot;body-parser&quot;: &quot;^1.16.0&quot;,<br>		&quot;express&quot;: &quot;^4.14.0&quot;,<br>		&quot;mongoose&quot;: &quot;^4.7.7&quot;,<br>		&quot;nodemon&quot;: &quot;^1.11.0&quot;<br>	}<br>}</pre><ul><li>So, basically above we are defining api-server information related to version, dependencies etc.</li><li>Main part is dependencies section. We are defining api-server dependencies which is</li><li><a href="https://github.com/expressjs/body-parser">body-parser</a> : for api middleware, handling in-coming request</li><li><a href="http://expressjs.com/">express</a> : for serving REST API</li><li><a href="http://mongoosejs.com/">mongoose</a> : for mongodb object modeling</li><li><a href="https://nodemon.io/">nodemon</a> : for reloading node server automaticaly</li></ul><h4>Installation</h4><ul><li>Switch to api-server root and install all dependencies mentioned in package.json open terminal and type</li></ul><pre>$ npm install</pre><h4>Server structure</h4><pre>fullstack-development/<br>--- api-server/<br>------ api.js<br>------ Todo.model.js<br>------ package.json</pre><h4>Build api-server</h4><ul><li>We will use <a href="https://www.mongodb.com/">mongoDB</a> for persistence back-end data storage.</li><li><a href="https://docs.mongodb.com/manual/installation/">Install mongoDB</a></li><li>Run mongoDB, start two terminal, one for mongoDB server and other for mongoDB shell</li><li>First terminal (run mongoDB server)</li></ul><pre>$ mongond</pre><ul><li>Second terminal (run mongoDB shell)</li></ul><pre>$ mongo</pre><ul><li>Create new db mydb and new collection todos. In mongoDB we have collections in place of tables - <a href="https://docs.mongodb.com/manual/core/data-modeling-introduction/">documentation</a></li><li>Create a new file api-server.js and paste below code in that</li></ul><pre><em>// api configuration</em></pre><pre><em>// express server configuration</em><br><strong>var</strong> express <strong>=</strong> require(&#39;express&#39;);<br><strong>var</strong> api <strong>=</strong> express();</pre><pre><em>// body configuration for handling middleware</em><br><strong>var</strong> bodyParser <strong>=</strong> require(&#39;body-parser&#39;);</pre><pre><em>// mongoose(mongoDB database) configuration</em><br><strong>var</strong> mongoose <strong>=</strong> require(&#39;mongoose&#39;);<br><strong>var</strong> Todo <strong>=</strong>  require(&#39;./Todo.model&#39;);</pre><pre><em>// api port, api will be running on 8080</em><br><strong>var</strong> port <strong>=</strong> 8080;</pre><pre><em>// connect to mongoDB</em><br><strong>var</strong> db <strong>=</strong> &#39;mongodb://localhost/mydb&#39;;<br>mongoose.connect(db);</pre><pre><em>// bodyParser configuration</em><br>api.use(bodyParser.json());<br>api.use(bodyParser.urlencoded({<br>  extended: <strong>true</strong><br>}));</pre><pre><em>// enable cors</em><br>api.all(&#39;/*&#39;, <strong>function</strong>(req, res, next) {<br>	console.log(&#39;request made for: %s&#39;, req.originalUrl);<br>	res.header(&#39;Access-Control-Allow-Origin&#39;, &#39;*&#39;);<br>	res.header(&#39;Access-Control-Allow-Headers&#39;, &#39;X-Requested-With, Content-Type&#39;);<br>	res.header(&#39;Access-Control-Allow-Methods&#39;, &#39;GET,POST,PUT,OPTIONS,DELETE&#39;);<br>	next();<br>});</pre><pre><em>// api root</em><br>api.get(&#39;/&#39;, <strong>function</strong>(req, res) {<br>  res.send(&#39;api running... &lt;br&gt; please use &quot;/api/todos&quot; for getting all todos &#39;);<br>});</pre><pre><em>// api listen</em><br>api.listen(port, <strong>function</strong>() {<br>  console.log(&#39;api listening on port &#39; <strong>+</strong> port);<br>});</pre><ul><li>We are serving a mongoDB api server on port 8080</li></ul><h4>Run api server</h4><ul><li>Switch fullstack-development/api-server folder open terminal and type</li></ul><pre>$ nodemon</pre><ul><li>Now you should able to see your api server running at <a href="http://localhost:8080/">http://localhost:8080/</a></li><li>Lets add few Rest api end-point for front-end todo applicaton. Paste below code in api-server.js between api root and api listen section.</li></ul><pre><em>// get list of todos</em><br>api.get(&#39;/api/todos&#39;, <strong>function</strong>(req, res) {<br>  console.log(&#39;getting all todos&#39;);<br>  Todo.find({})<br>    .exec(<strong>function</strong>(error, todos) {<br>      <strong>if</strong> (error) {<br>        console.log(&#39;error getting list&#39;);<br>      } <strong>else</strong> {<br>        console.log(todos);<br>        res.json(todos);<br>      }<br>    });<br>});</pre><pre><em>// get particular single todo</em><br>api.get(&#39;/api/todos/:id&#39;, <strong>function</strong>(req, res) {<br>  Todo.findOne({<br>    _id: req.params.id<br>  })<br>  .exec(<strong>function</strong>(error, todo) {<br>    <strong>if</strong> (error) {<br>      console.log(&#39;error getting&#39;);<br>    } <strong>else</strong> {<br>      console.log(todo);<br>      res.json(todo);<br>    }<br>  })<br>});</pre><pre><em>// add new todo</em><br>api.post(&#39;/api/todos&#39;, <strong>function</strong>(req, res) {<br>  Todo.create(req.body, <strong>function</strong>(error, todo) {<br>    <strong>if</strong> (error) {<br>      res.send(&#39;error saving todo&#39;);<br>    } <strong>else</strong> {<br>      console.log(todo);<br>      res.send(todo);<br>    }<br>  });<br>});</pre><pre><em>// update todo</em><br>api.put(&#39;/api/todos/:id&#39;, <strong>function</strong>(req, res) {<br>  Todo.findOneAndUpdate({<br>    _id: req.params.id<br>  },<br>  {$set: {status: req.body.status}},<br>  {upsert: <strong>true</strong> },<br>  <strong>function</strong>(error, todo) {<br>    <strong>if</strong> (error) {<br>      console.log(&#39;error updating&#39;);      <br>    } <strong>else</strong> {<br>      console.log(todo);<br>      res.sendStatus(204);<br>    }<br>  });<br>});</pre><pre><em>// remove todo</em><br>api.<strong>delete</strong>(&#39;/api/todos/:id&#39;, <strong>function</strong>(req, res) {<br>  Todo.findOneAndRemove({<br>    _id: req.params.id<br>  }, <strong>function</strong>(error, todo) {<br>    <strong>if</strong> (error) {<br>      console.log(&#39;error deleting&#39;);      <br>    } <strong>else</strong> {<br>      console.log(todo);<br>      res.sendStatus(204);<br>    }<br>  })<br>});</pre><ul><li>Now you have your API server listening at 8080 and running with required API end-points. Let&#39;s switch to the front-end application now.</li></ul><h3>Front-end setup and configuration</h3><h4>Initialization</h4><ul><li>Create angular-app folder in fullstack-development folder and initialize it with npm init</li><li>Open package.json and copy below code in it</li></ul><pre>{<br>  &quot;name&quot;: &quot;todo&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;todo app written in angular 1&quot;,<br>  &quot;main&quot;: &quot;index.html&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;<br>  },<br>  &quot;repository&quot;: {<br>    &quot;type&quot;: &quot;git&quot;,<br>    &quot;url&quot;: &quot;git+<a href="https://github.com/pradeep1991singh/fullstack-development/angular-app.git">https://github.com/pradeep1991singh/fullstack-development/angular-app.git</a>&quot;<br>  },<br>  &quot;keywords&quot;: [<br>    &quot;todo&quot;,<br>    &quot;app&quot;,<br>    &quot;angularjs&quot;,<br>    &quot;1&quot;,<br>    &quot;front-end&quot;,<br>    &quot;mobile&quot;,<br>    &quot;application&quot;,<br>    &quot;full&quot;,<br>    &quot;stack&quot;,<br>    &quot;development&quot;<br>  ],<br>  &quot;author&quot;: &quot;pradeep singh&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;,<br>  &quot;bugs&quot;: {<br>    &quot;url&quot;: &quot;<a href="https://github.com/pradeep1991singh/fullstack-development/angular-app/issues">https://github.com/pradeep1991singh/fullstack-development/angular-app/issues</a>&quot;<br>  },<br>  &quot;homepage&quot;: &quot;hhttps://github.com/pradeep1991singh/fullstack-development/angular-app#readme&quot;,<br>  &quot;devDependencies&quot;: {<br>    &quot;gulp&quot;: &quot;^3.9.1&quot;,<br>    &quot;gulp-autoprefixer&quot;: &quot;^3.1.1&quot;,<br>    &quot;gulp-inject&quot;: &quot;^4.2.0&quot;,<br>    &quot;gulp-natural-sort&quot;: &quot;^0.1.1&quot;,<br>    &quot;gulp-rename&quot;: &quot;^1.2.2&quot;,<br>    &quot;gulp-sass&quot;: &quot;^3.1.0&quot;,<br>    &quot;gulp-webserver&quot;: &quot;^0.9.1&quot;,<br>    &quot;run-sequence&quot;: &quot;^1.2.2&quot;<br>  }<br>}</pre><h4>Installation</h4><ul><li>Switch to angular-app root and install all dependencies mentioned in package.json.</li><li>It will install gulp and required gulp packages for serving angular app open terminal and type</li></ul><pre>$ npm install</pre><h4>Setup angular-app</h4><ul><li>Basically, we will be creating a simple todo application in angular and will consume REST API end-points offered by API-server running at <a href="http://localhost:8080/">http://localhost:8080/</a>.</li></ul><h4>App structure</h4><pre>fullstack-development/<br>--- angular-app/<br>------ app/<br>--------- scripts/<br>------------ controllers/<br>--------------- todo-list.controller.js<br>--------------- todo-details.controller.js<br>------------ services/<br>--------------- todo.service.js<br>------------ app.js<br>--------- views/<br>------------ todo-list.html<br>------------ todo-details.html<br>--------- styles/<br>------------ styles.css<br>--------- index.html<br>--------- bower.json<br>--------- gulpfile.js<br>--------- package.json</pre><h4>Build a front-end app</h4><ul><li>Create index.html which will be our main entry-point file for serving our application.</li></ul><pre><strong>&lt;!DOCTYPE html&gt;</strong><br><em>&lt;!--[if lt IE 7]&gt;      &lt;html class=&quot;no-js lt-ie9 lt-ie8 lt-ie7&quot;&gt; &lt;![endif]--&gt;</em><br><em>&lt;!--[if IE 7]&gt;         &lt;html class=&quot;no-js lt-ie9 lt-ie8&quot;&gt; &lt;![endif]--&gt;</em><br><em>&lt;!--[if IE 8]&gt;         &lt;html class=&quot;no-js lt-ie9&quot;&gt; &lt;![endif]--&gt;</em><br><em>&lt;!--[if gt IE 8]&gt;&lt;!--&gt;</em> &lt;html class=&quot;no-js&quot; lang=&quot;en&quot; ng-app=&quot;todo&quot;&gt; <em>&lt;!--&lt;![endif]--&gt;</em><br>  &lt;head&gt;<br>    &lt;meta charset=&quot;utf-8&quot;&gt;<br>    &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;<br>    &lt;title&gt;Todo app&lt;/title&gt;<br>    &lt;meta name=&quot;description&quot; content=&quot;&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;</pre><pre>  	<em>&lt;!-- inject:css --&gt;</em><br>  	&lt;link rel=&quot;stylesheet&quot; href=&quot;/bower_components/bootstrap/dist/css/bootstrap.css&quot;&gt;<br>  	&lt;link rel=&quot;stylesheet&quot; href=&quot;/app/styles/main.css&quot;&gt;<br>  	<em>&lt;!-- endinject --&gt;</em>    </pre><pre>    <em>&lt;!-- inject:js --&gt;</em><br>    &lt;script src=&quot;/bower_components/angular/angular.js&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;/bower_components/angular-resource/angular-resource.js&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;/bower_components/angular-route/angular-route.js&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;/app/scripts/app.js&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;/app/scripts/controllers/todo-details.controller.js&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;/app/scripts/controllers/todo-list.controller.js&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;/app/scripts/directives/todo-list.directive.js&quot;&gt;&lt;/script&gt;<br>    &lt;script src=&quot;/app/scripts/services/todo.service.js&quot;&gt;&lt;/script&gt;<br>    <em>&lt;!-- endinject --&gt;</em></pre><pre>  &lt;/head&gt;<br>  &lt;body&gt;<br>    <em>&lt;!--[if lt IE 7]&gt;<br>      &lt;p class=&quot;browsehappy&quot;&gt;You are using an &lt;strong&gt;outdated&lt;/strong&gt; browser. Please &lt;a href=&quot;#&quot;&gt;upgrade your browser&lt;/a&gt; to improve your experience.&lt;/p&gt;<br>    &lt;![endif]--&gt;</em></pre><pre>    &lt;div class=&quot;col-xs-12&quot; ng-view&gt;&lt;/div&gt;</pre><pre>  &lt;/body&gt;<br>&lt;/html&gt;</pre><ul><li>In index.html we have some bower dependencies lets create bower.json file.</li></ul><pre>{<br>  &quot;name&quot;: &quot;todo&quot;,<br>  &quot;description&quot;: &quot;todo app written in angular 1&quot;,<br>  &quot;main&quot;: &quot;index.html&quot;,<br>  &quot;authors&quot;: [<br>    &quot;pradeep singh&quot;<br>  ],<br>  &quot;license&quot;: &quot;ISC&quot;,<br>  &quot;keywords&quot;: [<br>    &quot;todo&quot;,<br>    &quot;app&quot;,<br>    &quot;angularjs&quot;,<br>    &quot;1&quot;,<br>    &quot;front-end&quot;,<br>    &quot;mobile&quot;,<br>    &quot;application&quot;,<br>    &quot;full&quot;,<br>    &quot;stack&quot;,<br>    &quot;development&quot;<br>  ],<br>  &quot;homepage&quot;: &quot;&quot;,<br>  &quot;ignore&quot;: [<br>    &quot;**/.*&quot;,<br>    &quot;node_modules&quot;,<br>    &quot;bower_components&quot;,<br>    &quot;test&quot;,<br>    &quot;tests&quot;<br>  ],<br>  &quot;dependencies&quot;: {<br>    &quot;angular&quot;: &quot;^1.6.1&quot;,<br>    &quot;angular-route&quot;: &quot;^1.6.1&quot;,<br>    &quot;bootstrap&quot;: &quot;^3.3.7&quot;,<br>    &quot;angular-resource&quot;: &quot;^1.6.1&quot;<br>  }<br>}</pre><ul><li>Install all bower dependencies open terminal and type</li></ul><pre>bower install</pre><ul><li>Let&#39;s bootstrap our angular-app, create app.js file</li></ul><pre>angular<br>  .module(&#39;todo&#39;, [&#39;ngRoute&#39;, &#39;ngResource&#39;])<br>  .config(<strong>function</strong>($routeProvider) {<br>    $routeProvider<br>      .when(&#39;/&#39;, {<br>        templateUrl: &#39;views/todo-list.html&#39;,<br>        controller: &#39;todoListController&#39;<br>      })<br>      .when(&#39;/todo/:id&#39;, {<br>        templateUrl: &#39;views/todo-details.html&#39;,<br>        controller: &#39;todoDetailsController&#39;<br>      })      <br>      .otherwise({<br>        redirectTo: &#39;/&#39;<br>      })<br>  });</pre><ul><li>We will be having two views todo-list and todo-details and corresponding controllers</li><li>Create todo-list.html in views folder</li></ul><pre>&lt;h3&gt;&lt;/h3&gt;</pre><pre>&lt;h4&gt;Create new todo&lt;/h4&gt;<br>&lt;form&gt;<br>  &lt;div class=&quot;form-group&quot;&gt;<br>    &lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;exampleInputEmail1&quot; placeholder=&quot;title&quot; ng-model=&quot;title&quot;&gt;<br>  &lt;/div&gt;<br>  &lt;div class=&quot;form-group&quot;&gt;<br>    &lt;textarea class=&quot;form-control&quot; rows=&quot;3&quot; placeholder=&quot;description&quot; ng-model=&quot;body&quot;&gt;&lt;/textarea&gt;<br>  &lt;/div&gt;<br>  &lt;button type=&quot;button&quot; class=&quot;btn btn-default&quot; ng-click=&quot;newTodo()&quot;&gt;Create&lt;/button&gt;<br>&lt;/form&gt;</pre><pre>&lt;hr/&gt;</pre><pre>&lt;h4&gt;Todo lists&lt;/h4&gt;<br>&lt;div class=&quot;list-group&quot;&gt;<br>  &lt;a href=&quot;javascript:void(0)&quot; class=&quot;list-group-item&quot; ng-repeat=&quot;todo in todoList&quot;    ng-click=&quot;todoDetails(todo)&quot;&gt;<br>    <br>    &lt;span class=&quot;badge&quot;&gt;&lt;/span&gt;<br>  &lt;/a&gt;<br>&lt;/div&gt;</pre><ul><li>Create corresponding todo-list.controller.js controller in scripts/controllers</li></ul><pre>angular<br>  .module(&#39;todo&#39;)<br>  .controller(&#39;todoListController&#39;, <strong>function</strong>($scope, TodoService, $location) {</pre><pre>    $scope.welcomeMessage <strong>=</strong> &quot;Welcome to todo application&quot;;</pre><pre>    <em>// get todo list</em><br>    $scope.todoList <strong>=</strong> [];<br>    TodoService.list().then(<strong>function</strong>(response) {<br>        $scope.todoList <strong>=</strong> response;<br>      },<br>      <strong>function</strong>(error) {<br>        console.log(error);<br>      });</pre><pre>    <em>// add new todo handler</em><br>    $scope.newTodo <strong>=</strong> <strong>function</strong>() {<br>      <strong>var</strong> newTodo <strong>=</strong> {<br>        title: $scope.title,<br>        body: $scope.body,<br>        status: &#39;todo&#39;<br>      };<br>      $scope.todoList.push(newTodo);</pre><pre>      TodoService.newTodo(newTodo).then(<strong>function</strong>(response) {<br>        console.log(response);<br>      },<br>      <strong>function</strong>(error) {<br>        console.log(error);<br>      });<br>    };</pre><pre>    $scope.todoDetails <strong>=</strong> <strong>function</strong>(todo) {<br>      $location.path(&#39;/todo/&#39; <strong>+</strong> todo._id);<br>    };</pre><pre>  });</pre><ul><li>We have a TodoService in our controller, let create scripts/services/todo.service.js for that.</li></ul><pre>angular<br>  .module(&#39;todo&#39;)<br>  .service(&#39;TodoService&#39;, <strong>function</strong>($q, $resource, $httpParamSerializerJQLike) {</pre><pre>    <strong>var</strong> baseUrl <strong>=</strong> &#39;<a href="http://localhost:8080/api">http://localhost:8080/api</a>&#39;;<br>    <strong>var</strong> Todo <strong>=</strong> $resource(baseUrl <strong>+</strong> &#39;/todos/:id&#39;, {id: &#39;@id&#39;}, {<br>        new: {<br>            method: &#39;POST&#39;,<br>            headers: {&#39;Content-Type&#39;: &#39;application/x-www-form-urlencoded&#39;},<br>            transformRequest: <strong>function</strong>(obj) {<br>                <strong>var</strong> str <strong>=</strong> [];<br>                <strong>for</strong> (<strong>var</strong> param <strong>in</strong> obj) {<br>                  str.push(encodeURIComponent(param) <strong>+</strong> &#39;=&#39; <strong>+</strong> encodeURIComponent(obj[param]));<br>                }<br>                <strong>return</strong> str.join(&#39;&amp;&#39;);<br>            },                       <br>        }         <br>      });</pre><pre>    <strong>this</strong>.list <strong>=</strong> <strong>function</strong>() {<br>      <strong>var</strong> defer <strong>=</strong> $q.defer();<br>      Todo.query(<strong>function</strong>(response) {<br>        defer.resolve(response);<br>      }, <strong>function</strong>(error) {<br>        defer.reject(error);<br>      });<br>      <strong>return</strong> defer.promise;<br>    };</pre><pre>    <strong>this</strong>.newTodo <strong>=</strong> <strong>function</strong>(newTodo) {<br>      <strong>var</strong> defer <strong>=</strong> $q.defer();<br>      Todo.<strong>new</strong>(newTodo, <strong>function</strong>(response) {<br>        defer.resolve(response);<br>      }, <strong>function</strong>(error) {<br>        defer.reject(error);<br>      });<br>      <strong>return</strong> defer.promise;<br>    };</pre><pre>    <strong>this</strong>.get <strong>=</strong> <strong>function</strong>(id) {<br>      <strong>var</strong> defer <strong>=</strong> $q.defer();<br>      Todo.get({id: id}, <strong>function</strong>(response) {<br>        defer.resolve(response);<br>      }, <strong>function</strong>(error) {<br>        defer.reject(error);<br>      });<br>      <strong>return</strong> defer.promise;<br>    };</pre><pre>    <strong>this</strong>.<strong>delete</strong> <strong>=</strong> <strong>function</strong>(id) {<br>      <strong>var</strong> defer <strong>=</strong> $q.defer();<br>      Todo.<strong>delete</strong>({id: id}, <strong>function</strong>(response) {<br>        defer.resolve(response);<br>      }, <strong>function</strong>(error) {<br>        defer.reject(error);<br>      });<br>      <strong>return</strong> defer.promise;<br>    };            </pre><pre>  });</pre><ul><li>Above we are consuming API create an API-server section and running at <a href="http://localhost:8080/">http://localhost:8080/</a>.</li><li>Let&#39;s create views/todo-details.html for displaying our todo-details Package</li></ul><pre>&lt;h3&gt;Todo details page&lt;/h3&gt;</pre><pre>&lt;div class=&quot;panel panel-default&quot;&gt;<br>  &lt;div class=&quot;panel-heading&quot;&gt;<br>    &lt;h3 class=&quot;panel-title&quot;&gt;&lt;/h3&gt;<br>  &lt;/div&gt;<br>  &lt;div class=&quot;panel-body&quot;&gt;<br>    &lt;p&gt;&lt;/p&gt;<br>    &lt;p&gt;<br>      &lt;span&gt;Status: &lt;/span&gt;<br>    &lt;/p&gt;</pre><pre>    &lt;button type=&quot;button&quot;<br>      class=&quot;btn btn-default&quot;<br>      ng-if=&quot;todo.status!=&#39;done&#39;&quot;<br>      ng-click=&quot;done()&quot;&gt;<br>      Done<br>    &lt;/button&gt;      <br>  &lt;/div&gt;<br>&lt;/div&gt;</pre><pre>angular<br>  .module(&#39;todo&#39;)<br>  .controller(&#39;todoDetailsController&#39;, <strong>function</strong>($scope, TodoService, $routeParams, $location) {</pre><pre>    <em>// get todo</em><br>    TodoService.get($routeParams.id).then(<strong>function</strong>(response) {        <br>        $scope.todo <strong>=</strong> response;<br>      },<br>      <strong>function</strong>(error) {<br>        console.log(error);<br>      });</pre><pre>    <em>// delete todo handler</em><br>    $scope.done <strong>=</strong> <strong>function</strong>() {<br>      TodoService.<strong>delete</strong>($routeParams.id).then(<strong>function</strong>(response) {<br>        $location.path(&#39;/&#39;);<br>      },<br>      <strong>function</strong>(error) {<br>        console.log(error);<br>      });<br>    };</pre><pre>  });</pre><h4>Run angular-app</h4><ul><li>We will use gulp for serving and building our angular-app.</li><li>Create gulpfile.js in angular-app folder</li></ul><pre><strong>var</strong> gulp <strong>=</strong> require(&#39;gulp&#39;);<br><strong>var</strong> inject <strong>=</strong> require(&#39;gulp-inject&#39;);<br><strong>var</strong> webserver <strong>=</strong> require(&#39;gulp-webserver&#39;);<br><strong>var</strong> naturalSort <strong>=</strong> require(&quot;gulp-natural-sort&quot;);<br><strong>var</strong> runSequence <strong>=</strong> require(&#39;run-sequence&#39;);</pre><pre><strong>var</strong> appBaseUrl <strong>=</strong> &#39;<a href="http://localhost:8000/app/index.html">http://localhost:8000/app/index.html</a>&#39;;</pre><pre>gulp.task(&#39;inject&#39;, <strong>function</strong> () {<br>  <strong>var</strong> target <strong>=</strong> gulp.src(&#39;./app/index.html&#39;);<br>  <em>// It&#39;s not necessary to read the files (will speed up things), we&#39;re only after their paths:</em><br>  <strong>var</strong> sources <strong>=</strong> gulp<br>    .src([&#39;./bower_components/angular/angular.js&#39;,<br>          &#39;./bower_components/angular-route/angular-route.js&#39;,<br>          &#39;./bower_components/angular-resource/angular-resource.js&#39;,<br>          &#39;./app/**/*.js&#39;,<br>          &#39;./bower_components/bootstrap/dist/css/bootstrap.css&#39;,<br>          &#39;./app/**/*.css&#39;<br>          ], {<br>            read: <strong>false</strong><br>          })<br>    .pipe(naturalSort());</pre><pre>  <strong>return</strong> target<br>    .pipe(inject(sources))<br>    .pipe(gulp.dest(&#39;./app&#39;));<br>});</pre><pre>gulp.task(&#39;serve&#39;, <strong>function</strong>() {<br>  gulp.src(&#39;.&#39;)<br>    .pipe(webserver({<br>      livereload: <strong>true</strong>,<br>      directoryListing: <strong>true</strong>,<br>      open: appBaseUrl<br>    }));<br>});</pre><pre>gulp.task(&#39;default&#39;, <strong>function</strong>() {<br>  <em>// place code for your default task here</em><br>  runSequence(<br>    &#39;inject&#39;,<br>    &#39;serve&#39;<br>  );  <br>});</pre><ul><li>Let&#39;s run our app using gulp, open new terminal and type (Note our API server should be running)</li></ul><pre>$ gulp</pre><ul><li>You should be seeing an angular-app running, Create new todo and those will start listing under Todo lists.</li></ul><h4>Summary</h4><p>Fork code at <a href="https://github.com/pradeep1991singh/fullstack-development">full-stack-development</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4be5350893d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Get color palettes out of image]]></title>
            <link>https://medium.com/@pradeep1991singh/get-color-palettes-out-of-image-121a25bde711?source=rss-5060b58ac3d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/121a25bde711</guid>
            <category><![CDATA[color-picker]]></category>
            <category><![CDATA[color-palette]]></category>
            <category><![CDATA[palette]]></category>
            <category><![CDATA[pickers]]></category>
            <category><![CDATA[image-color-picker]]></category>
            <dc:creator><![CDATA[pradeep singh]]></dc:creator>
            <pubDate>Sun, 15 Oct 2017 19:42:25 GMT</pubDate>
            <atom:updated>2017-10-15T19:42:25.477Z</atom:updated>
            <content:encoded><![CDATA[<p>How to get image color palettes out of image provided.</p><h3>What we have</h3><blockquote>Lets see what options we have when we want to get color palettes out of images and platform is React-Native.</blockquote><ul><li>We can use native 3rd party libraries out there in community.</li><li>We can build our own.</li></ul><p>When we say build our own then lets see do we have any easy way out as far as React-Native is concern. I can see that we can do something with Canvas and now there is a new doubt that “how to use Canvas in React-Native”? And seems React-Native have solution for this also which is React-Native WebView component. Let see how we can use this.</p><h3>React-Native WebView</h3><blockquote>First create a WebView</blockquote><pre><strong>&lt;</strong>WebView<br>	source<strong>=</strong><br>	javaScriptEnabled<strong>=</strong>{<strong>true</strong>}<br>	onMessage<strong>=</strong>{imageResponseCallback}<br>/&gt;</pre><ul><li>In source we will provide canvas html</li><li>JavaScriptEnabled: true as we will be creating Canvas using JS for that JavaScript need to be enabled.</li><li>onMessage will be used for response callback</li></ul><blockquote>Lets provide source as html which will have Canvas</blockquote><pre><strong>let</strong> canvasHtml <strong>=</strong> `<br>      <strong>&lt;!</strong>DOCTYPE html<strong>&gt;</strong><br>      <strong>&lt;</strong>html<strong>&gt;</strong><br>      <strong>&lt;</strong>script<strong>&gt;</strong><br>      <strong>const</strong> interval <strong>=</strong> setInterval(() <strong>=&gt;</strong> {<br>        <strong>const</strong> img <strong>=</strong> document.getElementById(&#39;__colorPickerCanvasImage&#39;);<br>        <strong>if</strong> (img.src.length <strong>!=</strong> 0) {<br>          getColorPalettes();<br>          clearInterval(interval);<br>        }<br>      }, 10);   <br>  <br>      <strong>&lt;</strong>/script&gt;<br>      <strong>&lt;</strong>body<strong>&gt;</strong><br>        <strong>&lt;</strong>img src<strong>=</strong>&#39;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJ4AAACeCAMAAAD0W0NJAAABKVBMVEX///8AAACP2PZisN9isN9RhMEYUpcybrY6bKYYUpdRhMEybrZGotlRhMEYU5disN9GotkYU5c6bKaP2PYYU5cYU5eP2PaP2PaP2PaP2PaP2PaP2PY6bKYYU5eP2PY6bKYYUpcYUpeP2PYYUpeP2PaP2PYYUpc6bKYYU5c6bKY6bKYYUpcYU5c6bKaP2PYYUpcYU5eP2PY6bKY6bKYYUpcYUpcYUpc6bKZbrd46bKY3aqVJf75isN86bKYYUpchWZtisN8YU5dRp9sYUpdRhMFRhMEYUpc6dLkaVJhZrN1FfL1gr98lXJ1drd5RhMEeV5otYqA+dropX58ybrY4aqU6bKZGotk0b7dRp9s6dLkYU5dLgL9DerxIo9k0Z6OP2PZisN8YUpdYq93h0Z0aAAAASHRSTlMAAIBAgIC/QL9AQICAv7+/QBBAv8+fQDDvYJ/fMGAQ7+8wUM8gr2AQr5+AUDCPcIDvz89wEJ9w30Cvv4BgII9AMHCA32AwIEDHFgI6AAADCElEQVR4XuzAgQAAAADDoPtT32AEtQAAcPbq4ARiEArC8K4tCE+fggdJroF0sJ1M/13sOcf31IGAfwHDd5vvo0N6mJjK8dwf4aVSMb1c+hSeRCyq6jCvnVjYncZ4KWNt6uRxdID6eCQdoF5ey2AkTt4JSrW5eB2kgotXwao5eAJawcEroFUdvAxeycwTELvMvAvEipkXQCyaeQXEbjMvgtkc3uZt3uZpYGb/XGqv4W3e5v3+zM6xCYVQEABBQUNBy/mBkZmI6XLJg8/1X4SZlwmCwk4F03/uN18e96b/54KLsBeYe4G5F5h7gbkXmHuJuZeYe4m5l5h7ibmXmHuJubdh7h1N2audsVc7Y692xl7tjL3aGXu1E/f2xru9ZXjTOt573DvZsUMCAAAQiIEgUB/pLf0zUQCBQO4STI9LQN6KvK4X1skwO8cmEAJAFAUvOxAs6xA2ED4vENH+67hwUxXRNxXM6d4432LlkJd6wdwL5l4w94K5F8y9YO4Fc2/H3CvMvcLcK8y9wtwrzL3C3CvMvW1R9npn7PXO2Oudsdc7Y693z/V+w1nT97o/O3avgjAQBAFYm3B16kAuBBJMCIH4h4I2glgEIqKNhTDv/xLWInK3u8eaIvMEHwcHMztdCcLwJt7Ea4x39pE4ZJ55+OY+QBw6T0GnwRswZl6PMfN6jJnX40+8haYuIvMqik6ft1TUYU3mJYo6bOiVIHXobgiXjM5z/I0rwuXEaCyxmg4tp1AZLZ1dcXixkg4tr47udHQ5sy2XWw2dzbhlPkkFuufvfPAK3tb45XtRdG5eIZlCSfelu4R8PFvLllrZ8HTw0kVn8ZCMDUcHD11eB9m5h6oj6+DS5cfs3Y4d4iAMwGAU5kkMSUnrqJ+Y2A0I1+D+ByEkkxOQkPBEn6357N8fzvDb9d39/HF5rHvs539/CS6HumZPyWvMvMbMa8y8xswrzLzCzCvMvMLMK8y8wswrzLwFMy/DzMtAzMtAzMtAzMtAzMtAzMtAzNsCMW9bEfOWle94/qZpmqYXVsy/bDxskC4AAAAASUVORK5CYII=&#39; <br>          id<strong>=</strong>&#39;__colorPickerCanvasImage&#39; <br>          onload<strong>=</strong>&#39;getColorPalettes()&#39; <strong>/&gt;</strong><br>      <strong>&lt;</strong>/body&gt;<br>      <strong>&lt;</strong>/html&gt;<br>    `;<br>};</pre><ul><li>So, basically we are planning to render base64 image inside Canvas.</li><li>Get color rgba values</li><li>Sending message with rgbaValues to callback handler</li></ul><blockquote>Now lets render image, for getting color palettes out of image we need to provide base64 value of image. You can use any online original image to base64 image. I will be using <a href="https://stackskull.com/posts/base64-image.de">base64-image.de</a>.</blockquote><pre><strong>function</strong> getColorPalettes() {  <br>        <strong>const</strong> imageElement <strong>=</strong> document.getElementById(&#39;__colorPickerCanvasImage&#39;);      <br>        <strong>const</strong> canvas <strong>=</strong> document.createElement(&#39;canvas&#39;);<br>        <strong>const</strong> canvasContext <strong>=</strong> canvas.getContext <strong>&amp;&amp;</strong> canvas.getContext(&#39;2d&#39;);<br>  <br>        <strong>if</strong> (<strong>!</strong>canvasContext) <strong>return</strong> [0, 0, 0, 1];<br>        <br>        <strong>let</strong> imageWidth <strong>=</strong> canvas.width <strong>=</strong> imageElement.naturalWidth <br>          <strong>||</strong> imageElement.offsetWidth <br>          <strong>||</strong> imageElement.width;                <br>  <br>        <strong>const</strong> imageHeight <strong>=</strong> canvas.height <strong>=</strong> imageElement.naturalHeight <br>          <strong>||</strong> imageElement.offsetHeight <br>          <strong>||</strong> imageElement.height;                   <br>  <br>        canvasContext.drawImage(imageElement, 0, 0);<br>		<br>		....        </pre><pre>      }</pre><blockquote>Get Color Palettes out of image</blockquote><pre><strong>function</strong> getAllPalettes(width, height, context) {<br>        <strong>let</strong> distinctPalettes <strong>=</strong> []; <br>		<em>// loop through each and every pixels of image       </em><br>        <strong>for</strong> (<strong>let</strong> i<strong>=</strong>0; i<strong>&lt;=</strong>height; i<strong>++</strong>) { <br>          <strong>for</strong> (<strong>let</strong> j<strong>=</strong>0; j<strong>&lt;=</strong>width; j<strong>++</strong>) { <br>            <strong>try</strong> {<br>              data <strong>=</strong> context.getImageData(i, j, 1, 1);<br>              <strong>if</strong> (data.data.toString().trim() <strong>!==</strong> &#39;0,0,0,0&#39;) {<br>                distinctPalettes.push(data.data);<br>              }<br>            } <strong>catch</strong>(e) {<br>              console.log(e);<br>            }<br>          }<br>        }  <br>        <strong>return</strong> distinctPalettes;<br>      }<br>  <br>	  <em>// get dominant color palettes</em><br>      <strong>function</strong> getDominantPalettes(allPalettes, distinctCount, colorType) {<br>        <strong>const</strong> combinations <strong>=</strong> getPaletteOccurrences(allPalettes);<br>        <strong>let</strong> palettes <strong>=</strong> combinations[0];<br>        <strong>let</strong> occurrences <strong>=</strong> combinations[1];<br>        <strong>const</strong> dominantPalettes <strong>=</strong> [];<br>  <br>        <strong>while</strong> (distinctCount) {               <br>          <strong>let</strong> dominant <strong>=</strong> 0, dominantKey <strong>=</strong> 0;  <br>          occurrences.forEach((v, k) <strong>=&gt;</strong> {           <br>            <strong>if</strong> (v <strong>&gt;</strong> dominant) {<br>              dominant <strong>=</strong> v;              <br>              dominantKey <strong>=</strong> k;                               <br>            }<br>          });<br>          dominantPalettes.push(palettes[dominantKey]);<br>            <br>          palettes.splice(dominantKey, 1);            <br>          occurrences.splice(dominantKey, 1);<br>          distinctCount<strong>--</strong>;<br>        }<br>        <strong>return</strong> dominantPalettes;<br>      }        <br>  <br>      <em>// get palette occurrences</em><br>      <strong>function</strong> getPaletteOccurrences(palettes) {<br>        <strong>let</strong> paletteList <strong>=</strong> [], occurrenceList <strong>=</strong> [], previousPalette;<br>        palettes.sort();<br>        palettes.forEach((palette, key) <strong>=&gt;</strong> {<br>          <strong>if</strong> (palette.toString() <strong>!==</strong> previousPalette) {<br>            paletteList.push(palette);<br>            occurrenceList.push(1);<br>          } <strong>else</strong> {<br>            occurrenceList[occurrenceList.length<strong>-</strong>1]<strong>++</strong>;<br>          }<br>          previousPalette <strong>=</strong> palettes[key].toString();<br>        });<br>        <strong>return</strong> [paletteList, occurrenceList];<br>      }</pre><blockquote>In last we want to notify UI with retrieved color palettes. We will be using window.postMessage for sending data to callback method.</blockquote><pre><strong>let</strong> palette <strong>=</strong> getDominantPalettes(getAllPalettes(imageWidth, imageHeight, canvasContext), 3, &#39;rgba&#39;);<br>window.postMessage(JSON.stringify({&#39;message&#39;:&#39;imageColorPicker&#39;,&#39;payload&#39;:palette}));</pre><h3>Complete project</h3><ul><li>Fork complete project here — <a href="https://github.com/pradeep1991singh/react-native-image-color-picker">Image Color Picker</a></li><li>Project demo</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*YphkB8jAEiG7KmKK.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=121a25bde711" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Custom domain and Sub-domain integration with firebase]]></title>
            <link>https://medium.com/@pradeep1991singh/custom-domain-and-sub-domain-integration-with-firebase-2e8bea536930?source=rss-5060b58ac3d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e8bea536930</guid>
            <category><![CDATA[medium]]></category>
            <dc:creator><![CDATA[pradeep singh]]></dc:creator>
            <pubDate>Thu, 03 Aug 2017 19:24:21 GMT</pubDate>
            <atom:updated>2018-02-02T18:38:55.260Z</atom:updated>
            <content:encoded><![CDATA[<p>Integrate your Custom domain and Sub-domain with Firebase hosting for free and get ssl certificate integration out to the box.</p><h3>Introduction</h3><blockquote>Lets take a look how to integrate Custom domain and Sub-domain with Firebase hosting. We will be integrating domain purchased from GoDaddy.</blockquote><h3>Things needed</h3><ul><li>Project hosted at <a href="https://stackskull.com/posts/getting-started-with-firebase-hosting">Firebase hosting</a></li><li>GoDaddy Account access</li></ul><h3>Firebase console</h3><ul><li>Go to firebase console, select your project</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*a27GpRh7QXYkqQ49.png" /></figure><ul><li>Click on Hosting from left panel and then click “CONNECT DOMAIN” button</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4ohhqxsJNf4ai-Al.png" /></figure><ul><li>You will see an “Add domain” popup. Type in your custom domain name e.g. <a href="https://stackskull.com/posts/mycustomdomain.com">mycustomdomain.com</a> and click “CONTINUE”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Vri-nagKg6vj-nTx.png" /></figure><ul><li>Next you need to verify the domain ownership, for this you need to add a “TXT” record in your GoDaddy account.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_J_JB3qOwXxgOoqo.png" /></figure><h3>GoDaddy Account</h3><ul><li>Login to your GoDaddy account and go to “DNS manage” section.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MEPXUyC5dMN83eNd.png" /></figure><ul><li>Add a new “TXT” type record, enter Type as “TXT” host s “@” and TXT Value as “google-site-verification=xxxxxxxx” (you can get this from Verify ownership scree we have seen before).</li><li>Remove any existing “TXT” records if any.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*I46eUIn9sxfxeWWN.png" /></figure><ul><li>Go back to firebase and click “Verify”, wait for few minutes and let firebase verify your ownership and then you can see your site up and running at <a href="https://stackskull.com/posts/mycustomdomain.com">mycustomdomain.com</a>.</li></ul><h3>Custom Sub-domain firebase section</h3><ul><li>For Sub-domain there is almost same steps with minor changes in adding records.</li><li>Open <a href="https://stackskull.com/posts/getting-started-with-firebase-hosting">Firebase hosting</a> section for your Sub-domain project, click “CONNECT DOMAIN” and this time we will enter Sub-domain name e.g. <a href="https://stackskull.com/posts/sub-domain.mycustomdomain.com">sub-domain.mycustomdomain.com</a>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RmRezygXtFd0TUeE.png" /></figure><ul><li>And as we already verified the ownership for mycustomdomain.com, firebase won’t ask us again :).</li><li>Click “CONTINUE”</li><li>For Sub-domain we need to add “A” type record to our GoDaddy manage DNS section.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jQcEIO4pjgkshFVZ.png" /></figure><ul><li>And click “FINISH”, wait for few minutes and your Sub-domain will be up and running in NO time at <a href="https://stackskull.com/posts/sub-domain.mycustomdomain.com">sub-domain.mycustomdomain.com</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*P2ZJxaZSUUOfW9wk.png" /></figure><blockquote><a href="https://firebase.google.com/docs/hosting">Firebase Hosting documentation</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*P2ZJxaZSUUOfW9wk.png" /></figure><blockquote><a href="https://firebase.google.com/docs/hosting">Firebase Hosting documentation</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*P2ZJxaZSUUOfW9wk.png" /></figure><blockquote><a href="https://firebase.google.com/docs/hosting">Firebase Hosting documentation</a></blockquote><blockquote><a href="https://stackskull.com/posts/custom-domain-sub-domain-integration-with-firebase">Original Post</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e8bea536930" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrate Wercker with Bitbucket, Firebase and Slack]]></title>
            <link>https://medium.com/@pradeep1991singh/integrate-wercker-with-bitbucket-firebase-and-slack-7eb3bc38543d?source=rss-5060b58ac3d2------2</link>
            <guid isPermaLink="false">https://medium.com/p/7eb3bc38543d</guid>
            <category><![CDATA[wercker]]></category>
            <category><![CDATA[slack-web-hooks]]></category>
            <category><![CDATA[bitbucket]]></category>
            <category><![CDATA[slack]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[pradeep singh]]></dc:creator>
            <pubDate>Sun, 30 Jul 2017 19:37:41 GMT</pubDate>
            <atom:updated>2017-07-30T19:40:32.831Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p><em>Wercker is a Continuous integration and Deployment system. In this post we will be using </em><a href="https://www.wercker.com/"><em>Wercker</em></a><em> to deploy changes as soon as they pushed on </em><a href="https://bitbucket.org/"><em>Bitbucket</em></a><em> repository’s master branch to domain hosted at </em><a href="https://firebase.google.com/"><em>Firebase</em></a><em> and then notifying other(team members etc) about the new deployment changes in </em><a href="https://slack.com/"><em>Slack</em></a><em>.</em></p><h3>Things we will use</h3><ul><li>Bitbucket (Need to have a repository hosted at bitbucket either public/private)</li><li>Wercker (Need to have account on wercker, if not create one 😉 )</li><li>Firebase (Need to have a domain hosted at firebase, if not host one 😉 )</li><li>Slack (Need to have a slack web hook, create one )</li></ul><h3>Bitbucket</h3><ul><li>Create Repository on Bitbucket if already not have.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3b7eR-iD2x_IKMGx.png" /></figure><h3>Wercker</h3><ul><li>Create Continuous integration app at “Wercker”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/0*Gng-BJSiXqS5jFQT.png" /></figure><ul><li>Select Bitbucket, type repository name, select it and click “Use selected repo”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6akS7xOeFZ9F_DQE.png" /></figure><ul><li>Select recommended option</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XFnflne27O_Ydnmb.png" /></figure><ul><li>Finish</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*alQUIgMFbRyIDECu.png" /></figure><ul><li>Add new pipeline “deploy-firebase”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*resaNCGux0txeEsm.png" /></figure><ul><li>Enter pipeline details and “Hook type” Default</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FalT2fMbNp59SQTL.png" /></figure><ul><li>Add “FIREBASE_PROJECT_NAME” and “FIREBASE_TOKEN” as environment variable for “deploy-firebase” pipeline</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*l5LFSOEmYl7Nbv5K.png" /></figure><ul><li>For “FIREBASE_TOKEN”, open terminal and type $firebase login:ci, login to account and after successful login token will get printed in same terminal, copy token and save as protected variable.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0FLR2LmoLsTMZKWx.png" /></figure><ul><li>After setting variables, your setting will look something like below</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OEDUi8wugsNn3vMc.png" /></figure><ul><li>Lets chain “deploy-firebase” pipeline after “build” pipeline finishes on master branch</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/0*ipg_foFwfTfQF1P4.png" /></figure><ul><li>Your pipelines will look something like below</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kxcnnKCIGn55pkMN.png" /></figure><ul><li>Add “Wercker.yml” to your repository root and file will look something like below</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e6ce7aa08db0fbe31c259d5b11da79d/href">https://medium.com/media/0e6ce7aa08db0fbe31c259d5b11da79d/href</a></iframe><ul><li>Go to <a href="https://api.slack.com/incoming-webhooks">Webhook Api</a> and create slack app, login into your slack team and then go to “incoming-hooks” and create new hooks, after creation your hook will look something like below</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RFVxlHThf4-NI2HU.png" /></figure><ul><li>You can also restrict build trigger on particular branch e.g. “website” branch is restricted as below</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VDt4RxeIJCLWyrX-.png" /></figure><ul><li>Lets commit some changes to “master” branch of your bitbucket repository and as soon as changes are up build will trigger automatically</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CZ9deX5RA569FKPR.png" /></figure><h3>Firebase</h3><ul><li>As soon as build finishes successfully a new build will be uploaded to firebase hosting</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_gGrBroTZEvtRyK8.png" /></figure><h3>Slack</h3><ul><li>After build finishes, slack hook will post a message to let the team know that a new build is release with appropriate message which build success or error.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*grqXGQtOcgOQ6Fkk.png" /></figure><blockquote><a href="https://devcenter.wercker.com/docs/home">Wercker documentation</a></blockquote><blockquote><a href="https://firebase.google.com/docs/hosting">Firebase Hosting documentation</a></blockquote><blockquote><a href="https://gist.github.com/pradeep1991singh/fd192c7fbeec7a59d41f5d02db92fd86">Wercker.yml</a></blockquote><h4><a href="https://stackskull.com/posts/integrate-wercker-with-bitbucket-firebase-slack"><strong><em>Original post</em></strong></a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7eb3bc38543d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>