Shop OBEX P1 Docs P2 Docs Learn Events
How to post code in a thread? — Parallax Forums

How to post code in a thread?

Sorry I've searched around and not found the answer here, though this has probably been covered. How to we post code to a thread? Hundreds of lines in this case.

I know I can attach the code files. I was hoping there's a way to post code like most code related sites allow.

Comments

  • PublisonPublison Posts: 12,366
    edited 2015-07-30 14:47
    The number of characters have been increase, but I forgot the number. I tried to post  The Servo SPIN file , and it was over by 7000 characters. 
    Best to attach a ZIP file for now.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2015-08-06 21:00
    Until the dev team gets
    tags working, I've been using this:
            
    [code]<pre style="background-color:#ffffe0;max-height:400px;max-width:fill-available;overflow:auto;font-family:Parallax,Courier,monospaced;font-size:11pt;line-height:11pt;border-style:solid;border-width:1px;padding:5px">
    Paste code here.</pre>
    

    You have to click the <> button in the editor first before typing the HTML stuff.
    -Phil
  • PublisonPublison Posts: 12,366
    edited 2015-07-30 14:49
    Until the dev team gets [code] tags working, I've been using this:
    <pre style="background-color:#ffffe0;max-height:400px;max-width:fill-available;overflow:auto;font-family:Parallax,Courier,monospaced;font-size:11pt;line-height:11pt;border-style:solid;border-width:1px;padding:5px">
    Paste code here.</pre>
    You have to click the <> button in the editor first before typing the HTML stuff.
    -Phil

    Phil,
    Does that have the character limitation? Have not tried it.
  • twm47099twm47099 Posts: 867
    edited 2015-07-30 14:54
    The method I used in this thread:
    http://forums.parallax.com/discussion/161769/activitybot-sirc-control-whiskers
     is as follows.

    I type my normal text (2 paras or 1 para and my name with a couple of line feeds between them). 
    Then I click on the "<>" button on the right side of the icons at the top of the edit window.  That shows me my text and a lot of formatting stuff.
    I put the cursor between the "<br">s between the paragraphs and press "enter" a couple of times to give some space.
    Then I type <pre> and </pre> at the beginning of the space where I want my code (with a couple of blank lines between them).
    Then I paste the code in the space between the <pre> and </pre>.

    Not as easy as
    
    , but it works.
    There is at least one other method, but I'm not sure how to do it. EDIT: The other method is in the third post of this thread, and adds formatting.

    Tom

  • Thanks guys will try these out. If there's still a character limit I'm guessing I'll have to split it up or just upload the code files. Just seems harder to discuss the code back and forth when it's not right there on the page.
  • Publison asked, "Does that have the character limitation?"
    Yes, unfortunately. When I pointed out in another thread that the limitation should not apply to code -- especially in a scrolled code box that takes up limited space -- the response was just to attach the file rather than to display it.
    -Phil
  • I just wanted to jump in here and say thanks Phil. I tried your method in my test thread and it includes

    horizontal and vertical scrolling! Oh well, I guess it is time to learn HTML.
  • potatoheadpotatohead Posts: 10,261
    edited 2015-07-30 17:20
    https://github.com/dougdingus/snapNcrackle/blob/master/libsnap/src/AddressingMode.c

    That's a random thing in my GitHub account.  I'm thinking about just using that and ignoring code features here.

    Opens in a new window, has the syntax highlight, though I'm not sure that is true for SPIN.  (probably not) 

    BTW, here is Vanilla, if you want to go looking at it.

    https://github.com/vanilla/vanilla

    The way I see it, attaching here makes no sense.  If we can display it in a window, great!  That's handy, and like people say, right here for discussion.  But, if it won't fit, or it's a PITA, then using GitHub brings revisions, collaboration, and other features.  Much higher value IMHO.



  • PublisonPublison Posts: 12,366
    edited 2015-07-30 17:27
    Publison asked, "Does that have the character limitation?"
    Yes, unfortunately. When I pointed out in another thread that the limitation should not apply to code -- especially in a scrolled code box that takes up limited space -- the response was just to attach the file rather than to display it.
    -Phil

    15K is the max character limit in a post.. So the way to post code is a ZIP file. 
    Hopefully the ZIP file download name not being the same will be resolved soon.

  • Just to clarify: attachments don't count toward the character limit; only inline stuff.
    -Phil
  • TorTor Posts: 2,010
    If you post code here it becomes MIT-licensed, right? So what happens when you post a link to a github repo as a way to display formatted code..?

    -Tor
  • Heater.Heater. Posts: 21,230
    edited 2015-07-31 10:04
    I don't think posting code here can impose any different license on it than it has already. For  example if I post some GPL'ed code here I don't have the right to un GPL it. Neither does Parallax. What would MS say if I posted my copy of Windows 10 source code here?
    Where did your hear such a thing?
    Now, putting it into OBEX is another matter. If I remember Parallax has attached the MIT licensing condition to that. That does rather imply that you must have the right to apply that license to the code. Posting GPLed code to OBEX would be a no-no.
    Posting a link to a repo like github certainly has no impact on whatever licence that code is subject to. 
  • LeonLeon Posts: 7,620
    edited 2015-07-31 10:23
    I just tried
    and
    
    with the update pre-release:

    http://stage-forums.parallax.com/

    and they work OK. :)
  • TorTor Posts: 2,010
    edited 2015-08-06 20:58
    As I remember it, this wasn't limited to OBEX at all. The discussion (and policy) was about snippets of code posted right on the forum.

    I agree that posting a link to elsewhere cannot imply (re-)licensing the code. So it was kind of a rhetorical question. Using it as a method of getting code properly formatted (as long as the forum can't do it properly by itself) is not the same then - you can't just use the code as you wish, unlike posted code (if my memory is correct about that, and I'm quite certain).

    Edit: From the forum guidelines thread (sticky, in announcements):

    Code:
    Mind the licenses of the software you're using and treat them according to their restrictions.
    Code uploaded to this site without consent of the author or license holder is subject to removal without notice.
    Code snippets are to be treated as MIT licensed, minus the requirement to include the license text and mandatory attribution.
    If your posted code is under an existing license other than MIT you are required to include license attributions.
    

    -Tor
  • Heater.Heater. Posts: 21,230
    Interesting.
    No doubt lawyers could debate this all day but as far as I'm concerned copyright law has the provision for "fair use". I take that as meaning that posting a quote from a copyrighted work is OK. That certainly works for books and such like. I see no reason why it should not work for source code snippets. As long as they are not the entire or substantial part  of the work.
    Certainly nobody is going to bother tracking down the licence attached to every little snippet they post here.
    If Parallax want to put an MIT license on something I have written myself and posted here I'm fine with that.   
  • potatoheadpotatohead Posts: 10,261
    edited 2015-07-31 15:16
    That "snippet" bit happened when we had the Creative Commons code put here a while back.  Until then, we were all using MIT out of the OBEX, and snippets were implied, "do what you want"  At that time, the question of forum licensing and how do we do what we like to do came up, and Chip specifically asked for some resolution to continue on with no worries.

    Many of us were concerned, and couldn't look at the code for fear of some license snafu, thus the snippet language was born. 

    Fair use is actually a legal defense that is composed of a legal test and actually doesn't exist as a defined state in US Copyright Law.  When one cites fair use, really that is something like "justified or acceptable infringement" leaving the status of whatever is infringed, and the infringing work unchanged. 

    Translation:  "Fair use = I believe this minor infringement is OK."  That's it.

    That legal test generally is:

    http://fairuse.stanford.edu/overview/fair-use/four-factors/

    The four factors judges consider are:
    • the purpose and character of your use
    • the nature of the copyrighted work
    • the amount and substantiality of the portion taken, and
    • the effect of the use upon the potential market.
    - See more at: http://fairuse.stanford.edu/overview/fair-use/four-factors/#sthash.rPfBEt6r.dpufThe four factors judges consider are:

        the purpose and character of your use
        the nature of the copyrighted work
        the amount and substantiality of the portion taken, and
        the effect of the use upon the potential market.

    And the only way to get a definitive answer is to present the fair use work in court.  Ugh...  Otherwise, one can look at all the successful case law on fair use and compare, or more generally, look at and compare to other infringing activities that appear as fair use, which Heater did above.  If it seems to make sense and is generally OK, it probably is. 

    That's how we know satire, for example, is protected and fair use.  For snippets, the fact that it happens all the time, and people cannot have academic discussions without it happening and that it doesn't really impact anyone economically is a very strong fair use defense.  I'm not sure there is a lot of case law on code snippets, but there is a lot of it related to academic type discussion of copyrighted works.  It's best we don't ask that legal question.  We are likely to lose out more than we are to see an expansion or more formal treatment of it all.  This is due to the fact that the major rights holders will always, always seek to marginalize fair use.  Just saying...

    "Treated as MIT, minus the license attribution requirement", avoids the tangle of public domain, which also barely exists in US Copyright Law where every creative work automatically has copyright and it's questionable as to how exactly one does put something into the public domain.  I don't actually know how to put something into the public domain.  I do know it will end up there after an embarrassingly long time though.  Interesting isn't it? 

    So basically, the "treating it as MIT, minus the requirements..." means "do what you want with it" with no real worries and no requirement to post a license and all that jazz just to discuss some code. 

    It's not a matter of Parallax wanting anything other than the discussion that is supposed to happen here really.  It is a matter of finding some easy path to overall compliance that doesn't bother anyone.  And it's not actually transformative in terms of the license either.  "treated as" is just a concise expression to communicate the intent of the rules on forum snippets, not a declaration nor assignment of license.  Just FYI.  A declaration or assignment would actually require some agreement be made, or notice given, and who wants to bother with all of that mess? 

    So we don't bother.  And nobody cares, until they do.  Hopefully, nobody cares, and if they do, the intent here is expressed clearly, and hopefully that all is good enough.  And that all is about as good as it gets without things getting really painful. 

    I had a small part in helping resolve that matter and the language, which is why I'm speaking to it now.  Really, the intent is "no worries" on code posted to the forum as a snippet.  As it should be.  And I've sadly had some experience dealing with licensing.  And it's generally painful outside the small realm we inhabit here too.  Did I mention mind numbingly painful?  Yeah. 

    This all mostly goes unsaid, but in this case, somebody actually wanted it said, so it's said in very reasonable fashion.  That's it as far as intent goes too. 

    Finally, this is the kind of thing that happens when someone somewhere wants it said.  Be careful what you wish for.  You might just get it!  Great lesson there from that school of hard knocks.  :)


    The four factors judges consider are:
    • the purpose and character of your use
    • the nature of the copyrighted work
    • the amount and substantiality of the portion taken, and
    • the effect of the use upon the potential market.
    - See more at: http://fairuse.stanford.edu/overview/fair-use/four-factors/#sthash.rPfBEt6r.dpufThe four factors judges consider are:
    • the purpose and character of your use
    • the nature of the copyrighted work
    • the amount and substantiality of the portion taken, and
    • the effect of the use upon the potential market.
    - See more at: http://fairuse.stanford.edu/overview/fair-use/four-factors/#sthash.rPfBEt6r.dpuf
Sign In or Register to comment.