Giter Club home page Giter Club logo

Comments (4)

samurailink3 avatar samurailink3 commented on September 28, 2024

Before the wall of text: I'll update the cards.js file and push it to the CDN, but I wanted to document the fix (mostly for my own reference). This fix will be compatible will any/all new card updates to this file format.

Found a fix with:

awk '{gsub("\:[0-9999]*\,",":"NR",",$0);print}' < cards.js | sed -e "s/,$//g" | sed -e "s/$/,/g" | tac |awk '/a/ && !seen {sub(/,$/, ""); seen=1} 1' | tac > output.js

I boiled the file down a to one-line-per-card array, then ran it through this Mario-esque line of pipes. Here's the basic flow:

awk '{gsub("\:[0-9999]*\,",":"NR",",$0);print}' < cards.js - This reads in the modified (and broken) cards.js file, then substitutes any number 0-9999 with a colon, the line number, and a comma. Then the input is printed to stdout.

| sed -e "s/,$//g" | sed -e "s/$/,/g" - The output is then piped into sed, then all commas at the end of each line are removed (or, rather, replaced with "", null). This output is then piped into another sed command, this one, replacing each blank line-ending with a comma, then line ending.

| tac |awk '/a/ && !seen {sub(/,$/, ""); seen=1} 1' | tac > output.js - The output from sed is then piped into tac (cat backwards), the file is printed in reverse (by line number), and piped to awk. awk then removes the comma from the ending of the last line (again, replacing the comma-line-ending with line-ending), but only for the first item seen (which is the last line, because the file was fed into awk in the reverse line order). The file is then run through tac again to orient the line numbers correctly, and output to a file.

I'm sure there's a cleaner way to manage this, but it's a fast one liner for fixing these types of issues in the future.

from hangouts-against-humanity.

samurailink3 avatar samurailink3 commented on September 28, 2024

Not closed! Holy crap, this changed 'numAnswers' as well... Time to re-tool the script.

from hangouts-against-humanity.

samurailink3 avatar samurailink3 commented on September 28, 2024

Fixed the script:

awk '{gsub("\"id\"\:[0-9999]*\,","\"id\":"NR",",$0);print}' < cards.js | sed -e "s/,$//g" | sed -e "s/$/,/g" | tac |awk '/a/ && !seen {sub(/,$/, ""); seen=1} 1' | tac > output.js

It only matches the id field now... Sorry about that. 😭

from hangouts-against-humanity.

samurailink3 avatar samurailink3 commented on September 28, 2024

Fixed here:

29787f8
5419bc7

from hangouts-against-humanity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.