SlideShare a Scribd company logo
1 of 11
<SLIDESHOW title=”My code formatter for blogs” alt=”Version 1” />
End goal Build an intuitive code formatter that can be grown by its users With some sample keywords from 5 languages, derive the language and apply styling 1st goal
Step 1: Break the problem down Photo by Douglas Woods http://www.flickr.com/photos/deerwooduk/1788483794/
[object Object],[object Object],[object Object],[object Object],[object Object],Breaking it down
Step 2: One brick at a time Photo by Douglas Woods http://www.flickr.com/photos/deerwooduk/1788483794/ Photo by Takomabibelot http://www.flickr.com/photos/takomabibelot/2455018965/
Create an array of keywords var pArr = new Array(); pArr[0] = /((join |inner |outer |from |where |select |group |by |order )+)/ig pArr[1] = /((delegate |object |string |byte |list )+)/ig pArr[2] = /((div |style |br )+)/ig pArr[3] = /((match|regex)+)/ig pArr[4] = /((var )+)/ig
Run a Regex match for each language and record the count var mArr = new Array(); for(var i=0; i<pArr.length; i++) { var m = (strIn.match(pArr[i])||[]).length; mArr[i] = new Array(); mArr[i][0] = pArr[i]; mArr[i][1] = m; }
Sort the array in descending order on match count mArr.sort(function(a,b){ return a[1] <= b[1]; });
Run a Regex replace, injecting formatting around identified keywords strIn = strIn.replace(mArr[0][0], '<br/><span style=&quot;color: green;font-weight: bold;&quot;>$1</span>'); strIn = strIn.replace(/({)/ig, '$1<br/>&nbsp;'); strIn = strIn.replace(/((^<br>)+)/,'');
Run a Regex replace, injecting line numbers to all lines var pLns = /(.*?)(<br>|$)/ig var lArr = strIn.match(pLns); strIn = &quot;&quot;; for(var i=0; i<lArr.length; i++) { var ln = lArr[i]; if(ln.length > 0) { var col = ((i%2)==1)? &quot;fff&quot; : &quot;eee&quot;; strIn += &quot;<div style=amp;quot;background-color:#&quot;+ col +&quot;amp;quot;><div style=amp;quot;float:left;color:#666;amp;quot;>Line &quot;+(i+1)+&quot;:&nbsp;</div><div><code>&quot;+ln+&quot;</code></div></div>&quot;; } }
And that's version 1. So what next? > More keywords > More languages > More styling > More interaction > More contribution Wanna help? http://at-dpitt.blogspot.com/p/code-formatter-for-blogs.html

More Related Content

Viewers also liked

Manipulating file in Python
Manipulating file in PythonManipulating file in Python
Manipulating file in Pythonshoukatali500
 
Introduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsIntroduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsCarl Brown
 
FLTK Summer Course - Part III - Third Impact
FLTK Summer Course - Part III - Third ImpactFLTK Summer Course - Part III - Third Impact
FLTK Summer Course - Part III - Third ImpactMichel Alves
 
FLTK Summer Course - Part VI - Sixth Impact - Exercises
FLTK Summer Course - Part VI - Sixth Impact - ExercisesFLTK Summer Course - Part VI - Sixth Impact - Exercises
FLTK Summer Course - Part VI - Sixth Impact - ExercisesMichel Alves
 
Git hooks For PHP Developers
Git hooks For PHP DevelopersGit hooks For PHP Developers
Git hooks For PHP DevelopersUmut IŞIK
 
FLTK Summer Course - Part I - First Impact - Exercises
FLTK Summer Course - Part I - First Impact - ExercisesFLTK Summer Course - Part I - First Impact - Exercises
FLTK Summer Course - Part I - First Impact - ExercisesMichel Alves
 
FLTK Summer Course - Part II - Second Impact
FLTK Summer Course - Part II - Second ImpactFLTK Summer Course - Part II - Second Impact
FLTK Summer Course - Part II - Second ImpactMichel Alves
 
Code Refactoring - Live Coding Demo (JavaDay 2014)
Code Refactoring - Live Coding Demo (JavaDay 2014)Code Refactoring - Live Coding Demo (JavaDay 2014)
Code Refactoring - Live Coding Demo (JavaDay 2014)Peter Kofler
 
TMS - Schedule of Presentations and Reports
TMS - Schedule of Presentations and ReportsTMS - Schedule of Presentations and Reports
TMS - Schedule of Presentations and ReportsMichel Alves
 
Servicios web con Python
Servicios web con PythonServicios web con Python
Servicios web con PythonManuel Pérez
 
13 Graph Classes
13 Graph Classes13 Graph Classes
13 Graph Classespoffdeluxe
 
Minimal standard c program
Minimal standard c programMinimal standard c program
Minimal standard c programSwain Loda
 
Internal Anatomy of an Update
Internal Anatomy of an UpdateInternal Anatomy of an Update
Internal Anatomy of an UpdateMongoDB
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practicesmanugoel2003
 
Logging in Python for large applications
Logging in Python for large applicationsLogging in Python for large applications
Logging in Python for large applicationsFayaz Yusuf Khan
 

Viewers also liked (20)

Manipulating file in Python
Manipulating file in PythonManipulating file in Python
Manipulating file in Python
 
Introduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsIntroduction to Git Commands and Concepts
Introduction to Git Commands and Concepts
 
FLTK Summer Course - Part III - Third Impact
FLTK Summer Course - Part III - Third ImpactFLTK Summer Course - Part III - Third Impact
FLTK Summer Course - Part III - Third Impact
 
Advanced Git
Advanced GitAdvanced Git
Advanced Git
 
FLTK Summer Course - Part VI - Sixth Impact - Exercises
FLTK Summer Course - Part VI - Sixth Impact - ExercisesFLTK Summer Course - Part VI - Sixth Impact - Exercises
FLTK Summer Course - Part VI - Sixth Impact - Exercises
 
Git hooks For PHP Developers
Git hooks For PHP DevelopersGit hooks For PHP Developers
Git hooks For PHP Developers
 
FLTK Summer Course - Part I - First Impact - Exercises
FLTK Summer Course - Part I - First Impact - ExercisesFLTK Summer Course - Part I - First Impact - Exercises
FLTK Summer Course - Part I - First Impact - Exercises
 
FLTK Summer Course - Part II - Second Impact
FLTK Summer Course - Part II - Second ImpactFLTK Summer Course - Part II - Second Impact
FLTK Summer Course - Part II - Second Impact
 
Code Refactoring - Live Coding Demo (JavaDay 2014)
Code Refactoring - Live Coding Demo (JavaDay 2014)Code Refactoring - Live Coding Demo (JavaDay 2014)
Code Refactoring - Live Coding Demo (JavaDay 2014)
 
TMS - Schedule of Presentations and Reports
TMS - Schedule of Presentations and ReportsTMS - Schedule of Presentations and Reports
TMS - Schedule of Presentations and Reports
 
Servicios web con Python
Servicios web con PythonServicios web con Python
Servicios web con Python
 
Linux GIT commands
Linux GIT commandsLinux GIT commands
Linux GIT commands
 
13 Graph Classes
13 Graph Classes13 Graph Classes
13 Graph Classes
 
Minimal standard c program
Minimal standard c programMinimal standard c program
Minimal standard c program
 
Internal Anatomy of an Update
Internal Anatomy of an UpdateInternal Anatomy of an Update
Internal Anatomy of an Update
 
Code of Conduct_formatted
Code of Conduct_formattedCode of Conduct_formatted
Code of Conduct_formatted
 
Python Fuse
Python FusePython Fuse
Python Fuse
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
Logging in Python for large applications
Logging in Python for large applicationsLogging in Python for large applications
Logging in Python for large applications
 
Tech talks#6: Code Refactoring
Tech talks#6: Code RefactoringTech talks#6: Code Refactoring
Tech talks#6: Code Refactoring
 

Recently uploaded

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Recently uploaded (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

Code formatter

  • 1. <SLIDESHOW title=”My code formatter for blogs” alt=”Version 1” />
  • 2. End goal Build an intuitive code formatter that can be grown by its users With some sample keywords from 5 languages, derive the language and apply styling 1st goal
  • 3. Step 1: Break the problem down Photo by Douglas Woods http://www.flickr.com/photos/deerwooduk/1788483794/
  • 4.
  • 5. Step 2: One brick at a time Photo by Douglas Woods http://www.flickr.com/photos/deerwooduk/1788483794/ Photo by Takomabibelot http://www.flickr.com/photos/takomabibelot/2455018965/
  • 6. Create an array of keywords var pArr = new Array(); pArr[0] = /((join |inner |outer |from |where |select |group |by |order )+)/ig pArr[1] = /((delegate |object |string |byte |list )+)/ig pArr[2] = /((div |style |br )+)/ig pArr[3] = /((match|regex)+)/ig pArr[4] = /((var )+)/ig
  • 7. Run a Regex match for each language and record the count var mArr = new Array(); for(var i=0; i<pArr.length; i++) { var m = (strIn.match(pArr[i])||[]).length; mArr[i] = new Array(); mArr[i][0] = pArr[i]; mArr[i][1] = m; }
  • 8. Sort the array in descending order on match count mArr.sort(function(a,b){ return a[1] <= b[1]; });
  • 9. Run a Regex replace, injecting formatting around identified keywords strIn = strIn.replace(mArr[0][0], '<br/><span style=&quot;color: green;font-weight: bold;&quot;>$1</span>'); strIn = strIn.replace(/({)/ig, '$1<br/>&nbsp;'); strIn = strIn.replace(/((^<br>)+)/,'');
  • 10. Run a Regex replace, injecting line numbers to all lines var pLns = /(.*?)(<br>|$)/ig var lArr = strIn.match(pLns); strIn = &quot;&quot;; for(var i=0; i<lArr.length; i++) { var ln = lArr[i]; if(ln.length > 0) { var col = ((i%2)==1)? &quot;fff&quot; : &quot;eee&quot;; strIn += &quot;<div style=amp;quot;background-color:#&quot;+ col +&quot;amp;quot;><div style=amp;quot;float:left;color:#666;amp;quot;>Line &quot;+(i+1)+&quot;:&nbsp;</div><div><code>&quot;+ln+&quot;</code></div></div>&quot;; } }
  • 11. And that's version 1. So what next? > More keywords > More languages > More styling > More interaction > More contribution Wanna help? http://at-dpitt.blogspot.com/p/code-formatter-for-blogs.html