<?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 Sanjay Patel on Medium]]></title>
        <description><![CDATA[Stories by Sanjay Patel on Medium]]></description>
        <link>https://medium.com/@sanjayypatel?source=rss-3f42ed306b72------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*N6WanaJ1fjmxrYQTf16Phw.png</url>
            <title>Stories by Sanjay Patel on Medium</title>
            <link>https://medium.com/@sanjayypatel?source=rss-3f42ed306b72------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 21:47:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sanjayypatel/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[macOS/Jamf Binary Basics]]></title>
            <link>https://medium.com/@sanjayypatel/macos-jamf-binary-basics-9b2a654fe4a1?source=rss-3f42ed306b72------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b2a654fe4a1</guid>
            <category><![CDATA[scripting]]></category>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[mdm]]></category>
            <category><![CDATA[shell]]></category>
            <category><![CDATA[jamf]]></category>
            <dc:creator><![CDATA[Sanjay Patel]]></dc:creator>
            <pubDate>Mon, 24 Oct 2022 03:55:06 GMT</pubDate>
            <atom:updated>2022-10-24T03:58:30.714Z</atom:updated>
            <content:encoded><![CDATA[<h3>Background</h3><p>The <a href="https://docs.jamf.com/10.30.0/jamf-pro/administrator-guide/Components_Installed_on_Managed_Computers.html">Jamf binary</a> is one of the core tools for IT staff supporting macOS devices enrolled in a Jamf Pro server. It is installed at enrollment and provides a scriptable command line interface for common Jamf functions.</p><pre># The binary is located at<br>/usr/local/jamf/bin/jamf</pre><pre># However it is sym-linked to <br>/usr/local/bin/jamf</pre><pre># You can verify the path to the jamf binary with which<br>$ which jamf<br>/usr/local/bin/jamf</pre><h3>Jamf Help</h3><p>The jamf binary provides a set of <strong>verbs </strong>to trigger different events or functions. You can view available verbs with the jamf <strong>help</strong> verb.</p><pre># Show the list of available verbs<br>$ jamf help</pre><pre># Show available options for a specific verb<br>$ jamf help recon</pre><h3>Jamf CheckJSSConnection</h3><p>The <strong>checkjssconnection </strong>verb has two functions:</p><ul><li>Reach out to the Jamf server and confirm that it is reachable from the managed Mac.</li><li>Displaying the url of the Jamf server the Mac is enrolled in.</li></ul><pre>$ jamf checkjssconnection<br>Checking availability of <a href="https://academyart.jamfcloud.com/...">https://mycompany.jamfcloud.com/...</a><br>The JSS is available.</pre><h3>Jamf Recon</h3><p>The <strong>recon </strong>verb triggers an <a href="https://docs.jamf.com/10.42.0/jamf-pro/documentation/Computer_Inventory_and_Criteria_Reference.html">Inventory Update</a> in Jamf. This gathers hardware and software information, runs script-based extension attributes, collects usage logs, and then submits it to the Jamf Pro server.</p><p>This information populates the corresponding computer record, which Jamf uses to calculate scope for Smart Groups, Policies, Profiles, and other management.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h2acXP6Sr2wCVsdzlOLrMQ.png" /><figcaption>Diagram of how information is gathered from Macs enrolled in Jamf.</figcaption></figure><p>Any time you change information on the Mac that Jamf ought to know, you should run a recon. For example after changing the computer name or creating a new user account.</p><pre># Run a regular inventory update<br>$ sudo jamf recon</pre><pre># Run an inventory update and update some editable fields<br># In this example, set a building and room<br>$ sudo jamf recon -building &quot;123 Broadway&quot; -room &quot;100&quot;</pre><h3>Jamf SetComputerName</h3><p>The <strong>setcomputername </strong>verb allows you to set Computer Name, Local Hostname and Hostname simultaneously with one command.</p><pre># Set all three names using jamf setComputerName<br>$ sudo jamf setcomputername -name &quot;newcomputername&quot;</pre><pre># Dont forget to recon to update the Jamf record.<br>$ sudo jamf recon</pre><p>The <strong>setcomputername</strong> verb has a couple of extra tricks that can really save time naming a large batch of computers, say using an ARD unix command. You can use a Serial Number combined with a prefix to consistently name a batch of computers or even script the naming task.</p><pre># Using a serial number and prefix<br>sudo jamf setcomputername -prefix mac -useSerialNumber<br># this will result in the name mac-[SERIALNUMBER]</pre><h3>Jamf Policy</h3><p>The <strong>policy </strong>verb signals to the Jamf server that specific <strong>events </strong>have occured on the managed Mac.</p><p>Events such as startup, enrollment complete, login, or recurring check-in are built-in Jamf events that can trigger a Policy to run.</p><pre># the policy verb without an event option runs &quot;recurring check-in&quot;<br>sudo jamf policy</pre><pre># the policy verb with an event flag and trigger built-in events<br>sudo jamf policy -event login<br>sudo jamf policy -event enrollmentcomplete</pre><h3>Next Steps</h3><p>That covers some of the most common commands you might use supporting macOS devices enrolled in Jamf. However, there is a <strong>lot</strong> more that the Jamf binary can do, particularly when you start working on batches of Macs or even setting zero-touch automated workflows!</p><p>I recommend diving into the notes available using <strong>jamf help</strong> and trying the functions out for yourself. Another good place to dig deeper into what the Jamf binary can do is on the <a href="https://community.jamf.com/">Jamf Nation user forums</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b2a654fe4a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTTP for Newbie Developers]]></title>
            <link>https://medium.com/@sanjayypatel/http-for-newbie-developers-17cbd0821d?source=rss-3f42ed306b72------2</link>
            <guid isPermaLink="false">https://medium.com/p/17cbd0821d</guid>
            <category><![CDATA[https]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Sanjay Patel]]></dc:creator>
            <pubDate>Tue, 05 Jul 2016 20:36:28 GMT</pubDate>
            <atom:updated>2016-07-05T20:36:28.337Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*XKAwDGu7HP6NYTn_DB7acQ.gif" /><figcaption>Viewing a HTTP request in Chrome Dev Tools.</figcaption></figure><p>If you’re learning web developement of any sort — front-end, back-end, Wordpress, HTML, Rails, Javascript, whatever — then you’re probably going to run into HTTP at some point.</p><p>While I was learning how to build a Rails app for the first time, HTTP was touched on, but with a “Don’t worry about this today” approach. Well, if I could go back and give myself advice on that day, I’d have said “NO! Definitely learn about this today!”</p><p>In fact, I’d say that an elementary understanding of HTTP would benefit just about any new developer, even before you write your first line of code.</p><h4>So, what’s HTTP stand for?</h4><p>You’ll learn lots of acronyms as a web developer, but I like this one in particular because it sounds so TRON-esque. The <strong>H</strong>yper<strong>t</strong>ext <strong>T</strong>ransfer <strong>P</strong>rotocol, or HTTP, describes the rules and actions that clients and servers can use to communicate.</p><p>That still sounds a bit over complicated, so in plainer English —</p><blockquote>HTTP describes how a browser might ask a server for a website.</blockquote><blockquote>It also describes how that server might respond with the content of a webpage (text, images, etc.).</blockquote><blockquote>HTTP also describes how a form you submit on a webpage results in your information being stored on that website’s server.</blockquote><p>In short, HTTP describes how a browser and server talk to each other.</p><p>Now, this is all really imprecise language, which some programmers might chafe at, but my opinion is that learning these larger concepts is a lot easier when you build up your understanding in layers. So as a foundation to your understanding of HTTP, this will work nicely.</p><h4>But what does that look like?</h4><p>That’s a really good question! Because HTTP describes how a client (your browser) and a server talk, it makes sense to examine HTTP <strong>transactions</strong> as “conversations.”</p><p>Each conversation consists of a <strong>request </strong>and a <strong>response</strong>. The request is what you’re browser is sending to a server behind the scenes when you type in a URL or click on a website’s link. The response is how the server reacts to your request, either by giving you what you asked for, changing what you asked to update, or giving you back an error something went wrong.</p><p>Probably the most common HTTP request is the GET request, which asks a server to send us something. We can actually see what a request looks like if we use the developer tools in our browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bxkgTIuz9az6Wzb6mltalw.png" /><figcaption>Using Chrome dev tools to examine an HTTP request.</figcaption></figure><blockquote>If you need help accessing them, let me point you to <a href="http://devtoolsecrets.com/">DevToolSecrets</a>, which is a really handy reference for accessing developer tools in multiple browsers, as well as a more thorough rundown of their different parts and things you can do with them. For my example, I’ll use Chrome’s dev tools which you can access using <strong>cmd + option + I</strong> (Hold command and option keys and press I) on a Mac or <strong>F12</strong> on Windows.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*hQYo1dng9QdI6LLiqamg_A.gif" /><figcaption>Navigate to Network, and use the Doc filter.</figcaption></figure><p>In a new Chrome window, open up your developer tools and then in the top of the browser navigate to <a href="http://httpbin.org/">httpbin.org</a> (this is a website that’s built for testing/learning about HTTP requests).</p><p>There’s a lot of tabs and buttons in the dev tools, but ignore those for now. Just make sure you have the “Network” tab selected from the top bar of the developer tools area. You may be seeing a lot more “stuff” than I have listed here, you can filter that list by clicking on “Doc” which will restrict the list to main web page in the results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*fh8jn11u4ZNOyhT8DZrjmQ.gif" /><figcaption>Examining the request.</figcaption></figure><p>Looking at this list we can see that there is one item, the httpbin.org document. Click on the document in list, and you’ll be shown the details of the actual HTTP request. You can see that there’s a lot of information bundled up in what seems, at first, like a really simple request. All the browser did was ask a server for the web page at httpbin.org, but look at all the things that happen under the hood!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CcvxBYUqPr1slF0cKY9-Qg.png" /><figcaption>Examining request headers.</figcaption></figure><p>Note in the General section that there’s a <strong>Request URL </strong>and <strong>Request Method. </strong>What you’re seeing is the information the browser sent to the server where httpbin.org is hosted. The browser requested a resource from httpbin.org (Request URL) and asked for it to be returned as a GET action (Request Method). Our request used the method GET and the location httpbin.org to let the server know what we were looking for and that we wanted to read it, not edit it.</p><p>If we take a look at the section labeled “Request Headers”, we’ll see that there was, in fact, quite a lot of information sent from our browser to the server. There are <strong>Accept</strong> headers that tell the server what kinds of “stuff” we’re willing to receive from the server — in this case we’re looking for an HTML document(“text/html”). There’s also a header called <strong>User-Agent</strong> which tells the server what kind of browser we’re using. If you look through the listed options, you’ll see the exact version of Chrome you’re using to make the request.</p><p>All of these Request headers give the server more information about how to talk to us. They let the server know what language version we’re looking for, what kind of encoding we can use, or even information about the connection we’re making to the server. A lot of that is beyond the goal of this article, but it’s interesting stuff to <a href="https://en.wikipedia.org/wiki/List_of_HTTP_header_fields">investigate further</a>.</p><p>The big take-away here, is that <strong>there’s no magic at work here</strong>. Our browser uses HTTP to format a request for a web page to a server. All the details involved are bundled up in our request in a pre-defined format that the server should understand, and that format is <strong>defined by HTTP.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rFMfcoSNDugu3heL3hIK1g.png" /><figcaption>Examining response headers.</figcaption></figure><p>Now let’s take a moment to look at the Response headers in our dev tools. The response headers aren’t showing us anything too wild — mostly just letting us know what kind of content we’re getting back.</p><p>As luck would have it (well, not really luck since we knew the website worked) we get back the HTML document we asked for. The <strong>Content-Type</strong> header lets us know it’s a text/html document, and the <strong>Content-Length</strong> header gives the amount of data in bytes that’s being sent back to us.</p><p>There’s also one important part of the Response in the “General” section — the <strong>Status Code.</strong> HTTP defines a <a href="https://en.wikipedia.org/wiki/List_of_HTTP_status_codes">bunch of status codes</a> that are shorthand for what happened on the server when you made a request. As you learn to build and troubleshoot web sites and applications, you’ll start encountering more of these codes, so it’s work familiarizing yourself with their categories.</p><p>The code we go for our request, “200 OK”, is the general response for an HTTP request that was successful. You’ve probably also seen a “404 Not Found” status code if you’ve ever clicked a link to something that wasn’t there. In troubleshooting, these codes are helpful for narrowing down where an error might be occuring.</p><p>OK, so that’s a lot of information <em>about</em> the response — the status, the format, the length, but what about the “stuff” I asked for?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*chmTwMRCcV1bQ2Y4sXtfig.png" /><figcaption>The response payload.</figcaption></figure><p>Now, let’s look at the response <strong>Content</strong> — the actual “payload” of the server’s response to our browser. In the case of httpbin.org, we were requesting an HTML document, and the server has responded with, well HTML. So far, we’ve been looking at the “Headers” tab, now click over to the “Response” tab and you’ll see what all this has been about. This is the actual HTML we’re viewing in the window above the dev tools. It’s formatted and styled by CSS and other processes, but underneath all that, is the HTML we originally asked for!</p><p>Again, there’s no magic here, the server saw our request, found the HTML document we asked for, and sent it back to your browser, which showed us the HTML. That’s it!</p><h4>OK, but so what?</h4><p>As you can see, HTTP acts like the rules of a conversation — telling a browser and server how to talk to each other so that users (us) can get what we want.</p><p>The coolest part of HTTP, is that once you get the basic hang of how it works in the case of a web browser, seeing it at work throughout your training in web development will be that much easier.</p><p>For example, take writing routes in Ruby on Rails. This is a<a href="http://guides.rubyonrails.org/routing.html"> pretty big, and complex topic</a>, but it gets a tad easier when you understand that a lot of your routes are designed to tell your app what do when different types of requests are made by users. If you look a routes.rb file for a blog built in Rails you’d probably see some code like this:</p><pre>resources :posts</pre><p>Which looks like not a lot of code, but what it’s really doing is defining a bunch of URL’s that Rails “knows” how to match up to. What that single line is summarizing might look like this:</p><pre>get &#39;posts&#39;, to: &#39;posts#index&#39;<br>get &#39;posts/:id&#39; to: &#39;posts#show&#39;<br># ... and a few more lines that look like these ...</pre><p>What you’re seeing are templates for requests that Rails might receive (“get ‘posts/:id’) and the part of the application that will handle the response (“to: ‘posts#show’). Each one of those lines is a “route.” Now, if you’re not familiar with Rails, this might seem over your head, but let’s break it down.</p><p>The first part, get ‘posts/:id’ means simply, “If you receive a HTTP GET request, with the URL matching the format ‘post/:id’ then use this route. The :id is just a stand-in for “some number or identifier.” In Rails, that’s usually a number, assigned to a post as it’s created. So if you were to make a request for <a href="http://exampleapp.com/posts/11">http://exampleapp.com/posts/11</a> then the GET request would be asking Rails for the eleventh blog post.</p><p>The second part, is more specific to Rails, but what it means is “look up the Post_Controller class (written in Ruby by the developer) and call the Post_Controller.show method.” That method is written by a developer to look up the correct blog post and give it to the browser. So in short, Rails lets you define patterns of HTTP requests AND lets you automate how your code reacts to those requests! Cool, right?</p><p>Well, if that’s a bit confusing to you, that’s OK. You don’t need to understand Rails routing today. What you can take from this example is this — knowing how HTTP works, allows you to start building an understanding of how just about any kind of web development works. <strong>Your users are going to make requests, and as developers, we right code that knows how to the respond.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17cbd0821d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NE_01 by Ethan Redd]]></title>
            <link>https://medium.com/575-gaming/ne-01-by-ethan-redd-bb96771eec67?source=rss-3f42ed306b72------2</link>
            <guid isPermaLink="false">https://medium.com/p/bb96771eec67</guid>
            <category><![CDATA[kidd-raddical]]></category>
            <category><![CDATA[ne-01]]></category>
            <category><![CDATA[haiku]]></category>
            <category><![CDATA[ethan-redd]]></category>
            <dc:creator><![CDATA[Sanjay Patel]]></dc:creator>
            <pubDate>Sun, 26 Jun 2016 06:16:56 GMT</pubDate>
            <atom:updated>2016-06-26T06:16:56.107Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7trM1mEris6OByDKiAcalw.png" /></figure><p>Override order:</p><p>I must leave this shaded spot.</p><p>I seek to be whole.</p><p><a href="https://kiddraddical.itch.io/ne01">kiddraddical.itch.io/ne01</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bb96771eec67" width="1" height="1" alt=""><hr><p><a href="https://medium.com/575-gaming/ne-01-by-ethan-redd-bb96771eec67">NE_01 by Ethan Redd</a> was originally published in <a href="https://medium.com/575-gaming">575 Gaming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hyper Light Drifter by Heart Machine]]></title>
            <link>https://medium.com/575-gaming/hyper-light-drifter-by-heart-machine-c7c45f1a3e73?source=rss-3f42ed306b72------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7c45f1a3e73</guid>
            <category><![CDATA[heart-machine]]></category>
            <category><![CDATA[haiku]]></category>
            <category><![CDATA[hyper-light-drifter]]></category>
            <category><![CDATA[games]]></category>
            <dc:creator><![CDATA[Sanjay Patel]]></dc:creator>
            <pubDate>Tue, 21 Jun 2016 23:15:47 GMT</pubDate>
            <atom:updated>2016-06-26T06:17:32.622Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1l6b5kLu3QvNGY1cnPSiZA.png" /></figure><p>Resting on the ground,</p><p>a thought occurs but is lost</p><p>like a deer startled.</p><p><a href="http://www.heart-machine.com/">heart-machine.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7c45f1a3e73" width="1" height="1" alt=""><hr><p><a href="https://medium.com/575-gaming/hyper-light-drifter-by-heart-machine-c7c45f1a3e73">Hyper Light Drifter by Heart Machine</a> was originally published in <a href="https://medium.com/575-gaming">575 Gaming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A haiku.]]></title>
            <link>https://medium.com/@sanjayypatel/a-haiku-46448e501ef3?source=rss-3f42ed306b72------2</link>
            <guid isPermaLink="false">https://medium.com/p/46448e501ef3</guid>
            <category><![CDATA[rockridge]]></category>
            <category><![CDATA[haiku]]></category>
            <category><![CDATA[poetry]]></category>
            <category><![CDATA[oakland]]></category>
            <dc:creator><![CDATA[Sanjay Patel]]></dc:creator>
            <pubDate>Thu, 09 Jun 2016 14:14:35 GMT</pubDate>
            <atom:updated>2016-06-09T14:14:35.805Z</atom:updated>
            <content:encoded><![CDATA[<p>Over many steps</p><p>Through many hidden pathways</p><p>Seeking open air.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46448e501ef3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A haiku.]]></title>
            <link>https://medium.com/the-crazedsf/a-haiku-5a5be90c99b0?source=rss-3f42ed306b72------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a5be90c99b0</guid>
            <category><![CDATA[haiku]]></category>
            <category><![CDATA[san-francisco]]></category>
            <dc:creator><![CDATA[Sanjay Patel]]></dc:creator>
            <pubDate>Thu, 02 Jun 2016 04:27:16 GMT</pubDate>
            <atom:updated>2016-06-02T04:27:16.479Z</atom:updated>
            <content:encoded><![CDATA[<p>Once pier, now parking,</p><p>Tethered, floating on the sea.</p><p>Waves entice collapse.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a5be90c99b0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-crazedsf/a-haiku-5a5be90c99b0">A haiku.</a> was originally published in <a href="https://medium.com/the-crazedsf">Mad Frisco</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recursion — JavaScript Meetup notes]]></title>
            <link>https://medium.com/@sanjayypatel/recursion-javascript-meetup-notes-883a378d70c3?source=rss-3f42ed306b72------2</link>
            <guid isPermaLink="false">https://medium.com/p/883a378d70c3</guid>
            <category><![CDATA[recursion]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Sanjay Patel]]></dc:creator>
            <pubDate>Mon, 09 May 2016 19:08:53 GMT</pubDate>
            <atom:updated>2016-05-09T19:08:53.998Z</atom:updated>
            <content:encoded><![CDATA[<p><em>I attended a </em><a href="https://medium.com/u/5a8bb2bca047"><em>MakerSquare</em></a><em> meetup in SF last week and the talk dived into Recursion in Javascript. It was a great, small meetup with a lot of opportunities to discuss the topic. To anyone learning JS in the Bay, I’d highly recommend checking out MakerSquare’s meetups. Here’s some highlights from my notes that evening.</em></p><h3>What is Recursion?</h3><p>I’d always thought of recursion as a function or program or block of code that <strong>called itself</strong>. But the definition proposed at the meetup approached recursion from a different angle.</p><blockquote>Recursion — A programming method wherein you divide a problem into subproblems of the same type. By combining the results of the solved subproblems, you arrive at the solution to the main problem.</blockquote><p>This seems kind of obvious to me now, but it really helped to clarify how to go about writing recursive code. You have to shelve solving the total problem, and in the mean time, focus on just a part of the solution.</p><p>The steps to writing recursive code were presented to us as follows:</p><ol><li>Define the base case(s).</li><li>Define the recursive case(s).</li><li>What action do you need to perform on the argument to lead you to a base case? In other words, what do you need to do to a recursive case to turn it into a base case?</li></ol><p>Lets dig into what these steps and terms mean:</p><h3>Base Cases</h3><p>If you continue to break the problem down until you’ve found a trivially solvable case, then you’ve found a base case. Defining the base cases for recursive problems tells your function when and where to stop recurring (calling itself).</p><p>One example presented in the meetup was a simple program that counted down from a supplied integer, logging each number to console and stopping at 0.</p><p>In this example, the base case is <em>when n is less than 0, stop the program. </em>Also note that this example only has one base case, while others might have two or more.</p><p>Here’s our code with the base case defined:</p><pre>var countDownFrom = function(n) {<br> // Check for base case<br> if(n &lt; 0){<br>   return;<br> }<br> // Handle all recursive cases here...<br>}</pre><p>This function checks for the base case and stops recursing (returns) if n is less than 0.</p><h3>Recursive Cases</h3><p>In the countDownFrom example above, the base case if clearly defined in the if statement, but how do you know what do in all other cases? These other cases, called recursive cases are when the function recurs (calls itself).</p><p>Handling recursive cases is a little trickier than base cases, because it requires putting into code how to solve a single case of the total problem. In countDownFrom, the total problem is logging all the numbers from n down to 0. So how can we break that total problem down in to parts?</p><p>In this case, you need to log just a single number, then rely on recursion to take care of all the subsequent cases. That’s the trick to recursive thinking — <em>forget about the whole problem or the next problem, just solve </em>this<em> one.</em></p><p>Our updated code now looks like this:</p><pre>var countDownFrom = function(n) {<br> // Check for base case<br> if(n &lt; 0){<br>   return;<br> }<br> // Solve this case:<br> console.log(n);<br> // Handle all the other cases with recursion...<br>}</pre><p>We don’t need to worry about printing ALL of the numbers in a single function call, only printing out the one we have right now. Then we trust in the power of recursion to take care of the other cases.</p><h3>Approaching a Base Case</h3><p>The last step in setting up our recursive solution is to figure out how to make our current case<em> </em><strong>approach</strong> a base case. This might seem daunting, but this step can itself be broken up a bit.</p><p>Let’s examine why we say “approach” instead of “become”? Because, really, the recursive call, needs to be supplied with the <strong>next</strong> case, not the actual base case.</p><p>In our example, if we’re given a number n, the next case will always be n minus 1.</p><p>If we know the next case (n-1) then we can assume our function will solve it, by just calling our function and passing in the next case. Incidentally, this next case will get us closer to our base case (n&lt;0) because we’re steadily decrementing n! Here’s the code including the recursive call:</p><pre>var countDownFrom = function(n) {<br> // Check for base case<br> if(n &lt; 0){<br>   return;<br> }<br> // Solve this case:<br> console.log(n);<br> // Handle the next case using recursion<br> countDownFrom(n-1);<br>}</pre><h3>Wrapping Up</h3><p>Now we have a complete solution. If we pass it any number that would qualify as a base case (-1 or below), the program sees the base case and immediately stops.</p><p>If we pass it a higher number, the function will ignore the total problem (log all numbers from n down to and including 0) and instead just solve this one case (log n). Then it will recur, supplying itself with the next case (n-1) and assuming all of the other cases will be handled. Eventually, the function will be called with a base case (n == -1) and the function will stop.</p><p>That, in a nutshell, is one way to tackle writing recursive solutions — define your base case, define your recursive case, and define how to move a recursive case towards a base case.</p><p>Bigger problems, like working with trees, or searching file directories, can get a lots harder, but the basic steps remain the same.</p><p><em>As I continue striving to be a better programmer and developer, I’m finding it helpful to summarize my notes from books, talks, meetups and classes. Hopefully other burgeoning programmers can find it useful too.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=883a378d70c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Trail]]></title>
            <link>https://medium.com/@sanjayypatel/trail-2aead7bcb1f1?source=rss-3f42ed306b72------2</link>
            <guid isPermaLink="false">https://medium.com/p/2aead7bcb1f1</guid>
            <category><![CDATA[poetry]]></category>
            <category><![CDATA[hiking]]></category>
            <dc:creator><![CDATA[Sanjay Patel]]></dc:creator>
            <pubDate>Mon, 09 May 2016 16:57:15 GMT</pubDate>
            <atom:updated>2016-05-09T16:57:15.805Z</atom:updated>
            <content:encoded><![CDATA[<p>A cloistered puddle of green on a map,</p><p>slivered and trimmed by encroaching progress.</p><p>We walked quietly ‘long a muddy trail that</p><p>pulsed and writhed against reclaiming life.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2aead7bcb1f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[First Gem — ACTransitRails]]></title>
            <link>https://medium.com/@sanjayypatel/first-gem-actransitrails-a4f261a709a3?source=rss-3f42ed306b72------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4f261a709a3</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[gem]]></category>
            <dc:creator><![CDATA[Sanjay Patel]]></dc:creator>
            <pubDate>Wed, 15 Jul 2015 00:00:00 GMT</pubDate>
            <atom:updated>2016-03-09T22:13:05.872Z</atom:updated>
            <content:encoded><![CDATA[<p>Here’s my first stab at a gem and the open-source dev community — <a href="https://github.com/sanjayypatel/actransit_rails">ACTransitRails</a>, hosted on <a href="https://rubygems.org/gems/actransit_rails">RubyGems</a></p><p>It’s a little Ruby wrapper for the <a href="http://api.actransit.org/transit/">ACTransit API</a> that allows you to access the route and bus stop info for the Bay Area ACTransit system.</p><p>Their API is pretty straightforward set of requests that respond with JSON formated information, so this seemed like a good topic to dip my feet into gem creation.</p><p>Here’s a little rundown of what I did.</p><ul><li>I built a module, ACTransitRails, that defined all of the helper methods I wanted to create. Each helper method defines a URI instance that takes a string formatted like “http://api.actransit.org/transit/…options…/?token=’api_access_token’”</li></ul><p>Then the uri is passed to the private get_response method which makes the actual request to the api. Here’s an example helper function:</p><pre>module ACTransitRails # base_url, search_string, and my_token are all private methods that return static parts of the url def self.get_all_routes # define the url uri = URI.parse( base_url + &quot;routes/&quot; + # this part of the uri will be different for each helper method search_string + my_token ) # make the request of the api using the url return get_response(uri) end def self.get_route(route) # ... end # ... end</pre><p>This request is formated as an Net::HTTP request in a private method get_response(uri).</p><pre>def self.get_response(uri) http = Net::HTTP.new(uri.host, uri.port) response = http.request(Net::HTTP::Get.new(uri.request_uri)) return JSON.parse response.body end</pre><p>The uri passed to get_response is created in each of the helper methods, as each method needs a specifically formatted url. Last, the response from the api is returned as JSON, which can be parsed into arrays and hashes using JSON.parse.</p><p>So that’s basically it. To use the gem, you call ACTransitRails.configure(access_token) where access_token is your api access token as a string. Then following calls to helper methods will use your token to make requests of the api.</p><p><em>(You get an access token by registering an application with </em><a href="http://api.actransit.org/transit/Account/Register"><em>ACTransit’s API</em></a><em>.)</em></p><p>Here’s an example call to the api using a helper function:</p><pre>ACTransitRails.get_route(&#39;E&#39;) # =&gt; {&quot;RouteId&quot;:&quot;E&quot;,&quot;Name&quot;:&quot;E&quot;,&quot;Description&quot;:&quot;San Francisco - Claremont -Parkwood&quot;}</pre><p>The return values for each method varies, either arrays or hashes, which is how the api responds to different requests. I think the next thing I’ll look into doing is formatting all of the responses in a standardized way, although that will take some thinking. For now, the gem successfully simplifies a dev’s access to the api in their rails apps, while still returning responses in the api-expected formats, and that’s good for now.</p><p>Check out the code over on <a href="https://github.com/sanjayypatel/actransit_rails/">Github.</a> Collaborators and contributors welcome!</p><ul><li>A little disclaimer: As I said, I’m really new to Ruby dev, so don’t take my code or strategies for “expert advice.” Rather, I’m documenting my progress learning various aspects of participating the cool world of software development. That also means that if you’ve got some ideas or feedback on how I could improve/change my code or projects then please, shoot me an email, make a pull-request, or tweet at me!</li></ul><p><em>Originally published at </em><a href="http://sanjayypatel.com/2015/07/15/First-Gem-ACTransit-Rails.html"><em>sanjayypatel.com</em></a><em> on July 15, 2015.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4f261a709a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Modeling Collaboration in Rails]]></title>
            <link>https://medium.com/@sanjayypatel/modeling-collaboration-in-rails-8e1ea4f0b06f?source=rss-3f42ed306b72------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e1ea4f0b06f</guid>
            <category><![CDATA[collaboration]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Sanjay Patel]]></dc:creator>
            <pubDate>Sat, 04 Jul 2015 00:00:00 GMT</pubDate>
            <atom:updated>2016-03-09T22:25:44.626Z</atom:updated>
            <content:encoded><![CDATA[<p>In my <a href="https://github.com/sanjayypatel/wiki-pocket">current project</a> in the Bloc.io Ruby on Rails course, I’m tackling a particularly confusing topic (confusing to me, at least) — Collaboration.</p><p>I’ve had some experience with join tables, but the situation is a little convoluted since a User has many wikis, a wiki belongs to a user, AND a user has many shared wikis through collaborations.</p><h4>Models</h4><p>Here’s how I setup the models:</p><p>User.rb</p><pre>has_many :collaborations<br>has_many :wikis<br>has_many :shared_wikis, through: :collaborations, source: :wiki</pre><p>On the third line, source: :wiki allows me to call user.shared_wikis to access any wikis that have been shared with the user by other authors and avoids colliding with user.wikis.</p><p>Wiki.rb</p><pre>belongs_to :user<br>has_many :collaborations<br>has_many :users, through: :collaborations</pre><p>Next I needed generate the Collaboration model:</p><p>$ rails g model Collaboration user:references wiki:references</p><p>Collaboration.rb</p><pre>belongs_to :user<br>belongs_to :wiki</pre><p>Basically, User has_many Wikis in two relationships, one directly between the Users and Wikis tables, and one through the Collaboration join table.</p><h4>User Flow</h4><p>Now that I knew how to structure accessing (1) users from wikis, (2) wikis from users, and (3) shared_wikis from users, I needed to think through how to present a collaboration to a user of the application.</p><p>Here’s the flow I came up with:</p><ol><li>From the Wikis#show and Wikis#edit views, a user can search for a user by username and add them to the wiki as collaborator.</li><li>The application looks up a user by username and creates a new collaboration record linking the current wiki shown and the searched-for user. If a user isn’t found, the collaboration record will not be created.</li><li>The Wikis policy, created with Pundit, allows users who are collaborators to edit wikis. Even standard users should be able to edit private wikis if they are collaborators. <em>(In this app, only premium users can create private wikis.)</em></li><li>The wiki’s author can remove collaborators from a wiki.</li></ol><p>Before diving into views and controllers, here’s how I added collaborations to routes:</p><pre>resources :wikis do <br>  resources :collaborations, only: [:create, :destroy] <br>end</pre><p>Since collaborations aren’t accessed without a related wiki, I nested them and added routes for create and destroy actions. The nesting had the added benefit of passing a :wiki_id to the Collaborations#create controller action.</p><h4>Views</h4><p>Here’s how I wired up the views:</p><p>collaborations/_form.html.erb</p><pre>&lt;%= form_tag [wiki, collaboration] do %&gt;<br> &lt;%= text_field_tag :search, params[:search] %&gt;<br> &lt;%= submit_tag &quot;Add User&quot; %&gt;<br>&lt;% end %&gt;</pre><p>I created a form rendered on the Wikis#show and Wikis#edit pages. Instead of a field to directly populate the user or wiki attributes of the collaboration, I setup a search field that passed the input text to the CollaborationsController in the form of params[:search].</p><h4>Create</h4><p>The controller receives the searched-for username using params[:search] and uses it to find a relevant user.</p><p>Here’s how I setup the collaborations controller:</p><p>Collaborations_Controller.rb</p><pre>def create<br> @wiki = Wiki.find(params[:wiki_id])<br> @user = User.where(&#39;username LIKE ?&#39;, &quot;%#{params[:search]}%&quot;)<br>        .all_except(current_user)<br>        .exclude_collaborators(@wiki)<br>        .first<br> if @user <br>    @collaboration = Collaboration.new(wiki: @wiki, user: @user) <br>    if @collaboration.save<br>      flash[:notice] = &quot;User successfully added to wiki.&quot; <br>    else<br>      flash[:error] = &quot;There was a problem adding user. Please try again.&quot;<br>    end<br>  else<br>    flash[:error] = &quot;Sorry that wasn&#39;t a valid username. Please try again.&quot;<br>  end <br>  redirect_to @wiki <br>end`</pre><p>The create action references the appropriate wiki using params[:wiki_id] and the user is referenced by searching the table for the input username. I added scopes to the user model that exclude the current_user and excludes the users who are already collaborators for the wiki.</p><p>Next, if the user is found, a new collaboration is created linking the wiki and user, otherwise an error is rendered letting the user know that the typed username wasn’t found.</p><h4>Destroy</h4><p>Removing a collaborator is even easier, just added a button to a view that uses the DELETE method. I added a data confirm popup to prevent stray clicks.</p><pre>&lt;%= link_to &quot;Remove&quot;, [wiki, collab], method: :delete, data: { confirm: &#39;Are you sure you want to remove this user?&#39;} %&gt;</pre><p>That’s more or less how I got it all hooked together. I’d guess that depending on the needs of the application, you’ll have some variations from my strategy like policies allowing view elements to be shown.</p><p><em>Originally published at </em><a href="http://sanjayypatel.com/2015/07/04/Modelling-Collaboration-in-Rails.html"><em>sanjayypatel.com</em></a><em> on July 4, 2015.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e1ea4f0b06f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>