How do I cite or reference code that has not been officially published? Let's say I go to someone's website, look up the source and use some of the JavaScript idea/pattern/code that is not a part of the wider framerwork/something similar, but a unique code that was written by the author of the website.

If it's not officially published in e.g. some coding tutorial, but I looked up the source of the website, is it appropriate to reference directly to the code on that website? (e.g. http://example.com/someonesscript.js)

Small edit #1: Just to mention, I have extensively edited the script, it is still similar, but not the same. It is about 100% longer, but there are similarities.
If it is part of the website or a webpage, simply refer to the webpage in your references. It clearly mentions that you are referring to a code which is published on a website.

Just look at this structure for a Chicago styled reference:


  Last Name, First Name. "Page Title." Website Title. Web Address
  (retrieved Date Accessed).


You can produce your citation like this:


  Code Producer's Last Name, Code Producer's First Name. "Sample computing source code for idea/pattern/code." Website Title. Web Address
  (retrieved Date Accessed).