Suggestion - Any way to Link to code And line - kill all stale code in web tutorials

Hi

not sure if this is the place to post this but just a suggestion or feature request.

I was reading a tutorial and it had code in a zip which you could download for github and it had snippets of the code in the tutorial (in HTML).

Example of tutorial with code snippets

https://www.raywenderlich.com/2865-how-to-make-a-simple-mac-app-on-os-x-10-7-tutorial-part-1-3

The tutorial was old but still worked but the the snippets were in older version of the language. 

The github had been updated but was now out of sync with the tutorial.

Is there any way to show the current code on the github repo but hosted in the web page of the tutorial.

I can add a link to the whole class e.g.

https://github.com/Ahmed-Ali/JSONExport/blob/master/JSONExport/DataType.swift

But theres no way to link to a line number

I know you can embed gists

https://blog.github.com/2008-07-24-embedded-gists/

What would be cool is a HTML view you could install on any web page.

Give it path to file

https://github.com/Ahmed-Ali/JSONExport/blob/master/JSONExport/DataType.swift

and start and end line numbers to show only a section of that file.

e.g. 

func toDictionary() -> NSDictionary

could be specified as 

path: https://github.com/Ahmed-Ali/JSONExport/blob/master/JSONExport/DataType.swift

lineStart: 37

lineEnd: 62

shows only 

func toDictionary() -> NSDictionary
{
let dictionary = NSMutableDictionary()

return dictionary
}

Advantages: when new sdks come out just recompile your code to keep it up to date

check the line numbers in case anything changed and change only them in your tutorial.

Hey there,

You can link to a specific line number in a file on GitHub in a few different ways, depending on your needs. The simplest way is to:

  1. Navigate to the file, ex: https://github.com/octocat/Spoon-Knife/blob/master/styles.css
  2. Left-click on the line number you want to highlight, ex: left-click on line 7
  3. Notice that the line you clicked is highlighted and the URL in your address bar has changed
  4. Copy the URL out of the address bar and use that to link to line 7 in https://github.com/octocat/Spoon-Knife/blob/master/styles.css

Now, if you want to link not only to line 7, but that specific version of line 7 no matter how that file changes in the future, you can:

  1. Follow the above steps
  2. Click the ellipsis menu to the left of the line number
  3. Click “Copy permalink”

This will copy the link https://github.com/octocat/Spoon-Knife/blob/d0dd1f61b33d64e29d8bc1372a94ef6a2fee76a9/styles.css#L7 to your clipboard that links to line 7 of that version of the file forever.

As far as embedding code in a non-GitHub web page, the best way to do that is through a Gist as you already understand.

I hope that helps!