Skip to content

Instantly share code, notes, and snippets.

@codeincontext
Created April 9, 2012 12:58
Show Gist options
  • Save codeincontext/2343241 to your computer and use it in GitHub Desktop.
Save codeincontext/2343241 to your computer and use it in GitHub Desktop.
Print the headers from a markdown document into 1.2.3 format
file = '/Users/skattyadz/Dropbox/PlainText/FYP.txt'
toc = ''
number_stack = [0]
File.readlines(file).each do |line|
if line[0] == '#'
hash_count = line.count('#')
if hash_count > number_stack.length
# down a level
number_stack << 1
else
if hash_count < number_stack.length
# up a level
levels_up = number_stack.length - hash_count
levels_up.times do
number_stack.pop
end
end
subheader_number = number_stack.pop + 1
number_stack << subheader_number
end
spacing = if hash_count == 1
"\n"
else
"\t" * (hash_count - 1)
end
header_number = number_stack * '.'
line_without_hashes = line.delete! '#'
toc << spacing + '- ' + header_number + line_without_hashes
end
end
puts toc
@codeincontext
Copy link
Author

Output (markdown)

- 1 Initial
    - 1.1 Title Sheet
    - 1.2 Abstract
    - 1.3 Declaration Sheet
    - 1.4 Acknowledgements
    - 1.5 Contents

- 2 Introduction
    - 2.1 Goals
    - 2.2 Approach

- 3 Background Reading
    - 3.1 Authentication
    - 3.2 Smartphones
    - 3.3 Existing methods
        - 3.3.1 OpenID
        - 3.3.2 NFC
        - 3.3.3 FB/twitter login
        - 3.3.4 Bump

- 4 Proposed development methods
    - 4.1 Methodology
    - 4.2 Languages / frameworks / Open source
    - 4.3 Git

- 5 Design Decisions
    - 5.1 High level proposal
    - 5.2 Criteria
    - 5.3 A new take on authentication
    - 5.4 Constraints
        - 5.4.1 Time
        - 5.4.2 Equipment
        - 5.4.3 Technical understanding
        - 5.4.4 Money

- 6 Design decisions
    - 6.1 Link between page and token
    - 6.2 Token credentials
    - 6.3 Login allocation on the web server
    - 6.4 Trigger login success on client page

- 7 Solution design
    - 7.1 Installation
    - 7.2 Authentication Process - User's perspective
    - 7.3 Technical overview
    - 7.4 Technologies Used
        - 7.4.1 QR Code
        - 7.4.2 Temporary User-Login Identifier link
        - 7.4.3 JavaScript Notification
    - 7.5 API endpoints:
    - 7.6 API endpoints:

- 8 Deliverable 1: Example Login Page

- 9 Deliverable 2: Adaptation of slideshow web application

- 10 Evaluation

- 11 Future work
    - 11.1 Wanted to do
        - 11.1.1 SSL
        - 11.1.2 QR code generation
        - 11.1.3 Realtime notification
        - 11.1.4 Enhanced security
            - 11.1.4.1 Timeouts
            - 11.1.4.2 HMAC
            - 11.1.4.3 Additional connection vectors
        - 11.1.5 Protocol versions

- 12 Conclusions
    - 12.1 How did QR codes go
    - 12.2 Was it secure
    - 12.3 Was it simple
    - 12.4 How was Rails
    - 12.5 How was Objective C
    - 12.6 How were my methods
    - 12.7 How was TDD for the rails example
    - 12.8 Should I have tested more
    - 12.9 Should I have structured stronger?

- 13 References

- 14 Appendices
    - 14.1 Proposal
    - 14.2 Ethics Checklist
    - 14.3 Turnitin report
    - 14.4 Designs, test plans, source code (cd)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment