Downloading and Uploading Gists

@Juce do you have any plan to port your upload-web trick into your program? It would be really nice to have a stand-alone program, rather than one that depends on the availability of your web site…

Another option would be to use CC repo instead of github for storing the raw project file. I think they dont use Json format. And CC repo is hosted by TLL. What do you think of this idea @ignatz, @briarfox, @Toffer? That would be quite simple for you to do, compared to what you have achieved with CC?

@juce Awesome tool for gists! Will make sharing code much easier.

@Jmv38 Great idea!

@juce i’ve made a couple changes to your code:

  • saving gist url to clipboard is automatic.
  • i make a backup copy of the link in tab ‘myGists’, this may be useful, cause the gists are anonymous…
  • added some prints.

--# Main
-- Gist uploader/downloader

local function iter(obj)
    if not then
    local data =
    local name, pos =, obj.pos
    local s, e, next = data:find("\
[-][-]# ([%w_]+)[^\
.", pos), obj.pos = next, e
    return name, data:sub(pos, s)

function tabs(data)
    local s, e, name = data:find("^%s*[-][-]# ([%w_]+)[^\
    local obj = {
        pos = e or 1, 
        name = name or "Main",
        data = data,
    return iter, obj

function saveLink(link)
    local name = "myGists"
    local tab = readProjectTab(name) or ""
    tab = tab .. "-- " .. link .. "  -- project: \

function setup()
    url, c = "", color(203, 209, 60, 255)
    -- Download gist via link in pasteboard
    parameter.action("Paste gist url", function()
        url = pasteboard.text
        parameter.action("Download", function()
            if not url:match("/raw") then
                url = url .. "/raw"
            http.request(url, function(data)
                msg = "Downloaded. Splitting into tabs ..."
                tween.delay(1, function()
                    for tabname,tabdata in tabs(data) do
                        saveProjectTab(tabname, tabdata)
                    msg, c = "Success!", color(96, 181, 47, 255)
                    parameter.action("Quit", function()
            end, function(err)
                msg, c = err, color(177, 49, 49, 255)
                parameter.action("Quit", function()
    -- Upload data from pasteboard to gist
    parameter.action("Upload new gist", function()
        data = pasteboard.text
        print("starting upload...")
        http.request('', function(link)
                msg, c = "Success!\
" .. link, color(96, 181, 47, 255)
                print("link copied in the pasteboard and in tab myGists")
                parameter.action("Quit", function()
        end, function(err)
            msg, c = err, color(177, 49, 49, 255)
            parameter.action("Quit", function()
        { method = 'POST', data = data })

function draw()
    background(18, 18, 19, 255)
    if msg then
        text(msg, WIDTH/2, HEIGHT/2)
        text(url, WIDTH/2, HEIGHT/2)

--# myGists
--  -- project: juce gister modified

Nice Project !

Here is my little contribution :

→ auto download of dkjson and use real gists api, so no proxy.

→ use just id for download (like 60058db98c5a010cb0f3)

@HyroVitalyProtago - does your code include Jmv38’s changes? It’s getting a bit confusing.

oh wow, all this activity, while i was away :slight_smile:

@Jmv38, to respond to your earlier post: i was a bit on the fence with the web-service vs included json lib. Didn’t want the project to be too big, where it no longer fits on a forum page… On the other hand, you were right that it is better to have it be self-contained, not relying on my service being up and running.

So i was thinking about how to include dkjson, in a “clever” way… And then @HyroVitalyProtago showed an interesting idea of downloading dkjson on-demand into global data storage. It’s a nice trick…

@Jmv38, myGists tab is a nice touch… although, it then needs to be removed, when a gist is being downloaded into the current project (duplicated from Gist).

@Ignatz, i believe Jmv38’s changes are included in HyroVitalyProtago’s version, but there are other things that are missing. So, yeah it is getting all confusing.

@HyroVitalyProtago, it’s a cool trick with dkjson library. Nicely done there! I have to say though that i don’t like the idea of using just the gist id. The full url is much easier to copy, and also explains what this id is. The id just by itself could refer to anything. Also, i think the whole idea of duplicating the project, downloading the project gist and splitting it into tabs - kinda got lost in your version. Not saying it’s necessarily bad, just completely different, and not what the initial code was trying to do…

One last random note: in my latest version, i had actually made a small tweak to tab-splitting logic - to fix the issue with an extra newline being added to the tabs after splitting.

@juce - I suggest you ask contributors to mark their code changes clearly in some way, or else use version control (although that is probably going a little overboard at this stage).

@Ignatz, fair point on source control, but yes, this is probably still small enough that we can get away with just exchanging gists

@juce all your remarks make a lot of sense.
It is important to keep the original spirit of your code.
I didnt think about removing myGist before downloading. This is quite easy to add.
But i wont touch the code before you tell me which version to start from.
Let me know what you decide to do.

@Ignatz : I have write my code from the @Jmv38 version.

@juce : sorry about remove tabs identification ! I have read the code too quickly and miss the feature ! My code split into tabs different files in a Gists. And I understand that’s not the spirit of original code.

I understand know why there is a --#myGists at the end of file and not into an another tab…

About the id or URL, when you copy, the id is 60058db98c5a010cb0f3. If you prefer URL, just replace at line 13 pasteboard.text by
pasteboard.text:gsub(".*/", "") for catch the id at the end of URL.

So, keep what you want or just ignore my version and have a nice day !

I updated first post to have the new version - 2.0. I think i got the merge of all the features correctly - from both of you guys :slight_smile: Check it out, should still work.

@Jmv38, no problem with myGists - i added the removal. As you said, it’s pretty simple. One thing where i had to modify your saveLink function slightly: to use listProjectTabs instead of direct readProjectTab(“myGists”), because readProjectTab throws an error, when the tab doesn’t exist (yet).

@HyroVitalyProtago, i used your idea of automatically downloading Dkjson library and storing it in global data. I think it is brilliant. Thanks!

Oh, and the gist for version 2.0:

What are gists?

@aurumcoder2624 :wink:

@juce great job!
i’ve used previous version to load the new one.
And used the new one to load… the new one again. Seemed to work fine.

@Juce hello! i have a small problem: the project creates this gist:
but if i pull it i get the whole github page, and not the code :frowning:
To get the code i must get this adress, from github site:
Any idea on how to get the real good adress automatically?

[EDIT] i am getting a bit lost. Now i seems to work…

[EDIT] Ah, my mistake, sorry, your code is fine. I was calling the wrong function in my code.

@Jmv38, no problem… Yeah, both links worked ok for me - maybe it was some weird glitch at github?

@Juce no, it was just my fault (stupid me…). Forget it.