Coder Social home page Coder Social logo

activestate / code Goto Github PK

View Code? Open in Web Editor NEW
1.9K 237.0 679.0 12.05 MB

ActiveState Code Recipes

Home Page: https://code.activestate.com

License: MIT License

Shell 1.00% Batchfile 0.19% C++ 0.48% C 0.29% HTML 0.06% Java 0.30% JavaScript 0.95% PHP 1.30% Perl 0.25% Python 91.40% Ruby 0.21% Tcl 3.55% Hack 0.01%

code's Introduction

ActiveState Code Recipes

Welcome to the ActiveState Code recipes repo! We have migrated all of the great content from code.activestate.com to its new forever-home here at GitHub. This makes it easier for everyone to submit new recipes, contribute code and integrate all the great information into their own projects.

The vast majority of code that existed on the code.activestate.com website has a home here, however if you do come across any recipe that is missing, or conversely, is totally outdated and no longer relevant please submit an issue.

What is this repo for?

This repo exists to contribute useful snippets, utility functions, and other interesting tidbits in any language that may be helpful to other developers.

Is there a master list of all the recipes?

You can find the master index of all recipes over at the wiki.

Coming Soon: Search Functionality!

How could I submit a new recipe?

  1. Fork this repo.
  2. Create your new recipe in the correct language subfolder (create a new folder if it doesn't already exist).
  3. Make sure you have included a README as well as your source file.
  4. Submit a PR.

Coming Soon: Submit recipes hosted in your own repo linked back from here!

How do I submit a change or revision to a recipe?

Same as above, fork the repo and submit a PR with your change.

What license is this code released under?

By default, all newly submitted code is licensed under the MIT license. If your recipe is being released under a different license, please make sure to include a LICENSE file inside your recipe directory.

All legacy recipes retain their original license. Please see the LICENSE file inside each recipe folder for details.

How else can I contribute?

Recipes don't always have to be code - great documentation, tutorials, general tips and even general improvements to our wiki are greatly appreciated.

code's People

Contributors

ahsec avatar anishk23733 avatar crumblez avatar devasiathomas avatar geoffcrompton avatar glowinthedark avatar harleypig avatar jorjmckie avatar ke4roh avatar kekepower avatar kgashok avatar mrjean1 avatar pshishpo-intel avatar rawktron avatar sayz avatar swaroop998 avatar tdiprima avatar ulrichblumensaat avatar volf52 avatar zoofood avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

code's Issues

Ping onn

Create ur own DIY project at ActiveState Code

J

J

Requesting recvall2 update

The recvall2 code was posted sometime ago but never really updated. I am currently using the snippet of code recvall2 and have run into a problem. The author originally stated that he would try to update the recvall function to handle data that is a duplicate of the end marker but has not due to the fact that he assumes that the chances of this happening is low. Although the chances of this happening are pretty low I am in a situation where the data is a duplicate of the end marker. I am trying to send over a copy of my python script using sockets however the script contains a copy of the end marker so the recvall breaks at the end marker, not receiving the full data. I am requesting for someone to update the snippet of code.(Maybe try combining the End Marker method with a timeout method to check if data is still present after detecting an End Marker?)

Tail call optimization decorator (Python)

I'm not positive, but I don't think this recipe made it into the repo: http://code.activestate.com/recipes/474088-tail-call-optimization-decorator/

Here's the updated code for Python 3 (inherit from BaseException, and updated syntax for except):

import sys

class TailRecurseException(Exception):
  def __init__(self, args, kwargs):
    self.args = args
    self.kwargs = kwargs

def tail_call_optimized(g):
  """
  This function decorates a function with tail call
  optimization. It does this by throwing an exception
  if it is it's own grandparent, and catching such
  exceptions to fake the tail call optimization.

  This function fails if the decorated
  function recurses in a non-tail context.
  """
  def func(*args, **kwargs):
    f = sys._getframe()
    if f.f_back and f.f_back.f_back \
        and f.f_back.f_back.f_code == f.f_code:
      raise TailRecurseException(args, kwargs)
    else:
      while 1:
        try:
          return g(*args, **kwargs)
        except TailRecurseException as e:
            args = e.args
            kwargs = e.kwargs
  func.__doc__ = g.__doc__
  return func

@tail_call_optimized
def factorial(n, acc=1):
  "calculate a factorial"
  if n == 0:
    return acc
  return factorial(n-1, n*acc)

print(factorial(10000))
# prints a big, big number,
# but doesn't hit the recursion limit.

@tail_call_optimized
def fib(i, current = 0, next = 1):
  if i == 0:
    return current
  else:
    return fib(i - 1, next, current + next)

print(fib(10000))
# also prints a big number,
# but doesn't hit the recursion limit.

Directory listing too large, github truncates it at 1K

Directory listing in some areas is too large, Github truncates it at 1K

here are some options:

option 1: (simple option)
please reorganize into sub-directories containing no more than 1k for each directory

option 2: (better option)
create an index file, which lists all the recipes and may be even adds descriptions for each too.

Easier way to search recipe?

Say I want to have enums in my (Python) project and I am searching through the recipes hoping to find something that fits my description. It would be easier for me to search if there was a file depicting what each recipe does (<100 words for each recipe) with 'tags'. Since there are over 4k recipes in Python and many recipes do not have good (easy to understand) names and I have to go through their readme to find what they do. Of course, I can search for recipes with name containing Enum in the Python folder but that may not give the best possible results at all times.

***Test Failed*** 2 failures

This code fails:

> python3 bresenham_nd.py
**********************************************************************
File "bresenham_nd.py", line 14, in __main__._bresenhamline_nslope
Failed example:
    _bresenhamline_nslope(s)
Expected:
    array([[ 0.,  0.,  0.,  0.]])
Got:
    array([[0., 0., 0., 0.]])
**********************************************************************
File "bresenham_nd.py", line 18, in __main__._bresenhamline_nslope
Failed example:
    _bresenhamline_nslope(s)
Expected:
    array([[ 0.,  0.,  1.,  0.]])
Got:
    array([[0., 0., 1., 0.]])
**********************************************************************
1 items had failures:
   2 of   6 in __main__._bresenhamline_nslope
***Test Failed*** 2 failures.

doc_inherit doesn't work with two levels of sub-classing

I'm trying to get the doc_inherit recipe (576862) to work with my classes, and the problem is that sometimes I have classes that go 2 levels down from the base class, rather than just one. This leads to an infinite recursion when the middle layer uses doc_inherit for a method.

Here is a minimal case that reproduces my problem:

from recipe_576862 import doc_inherit

class Base(object):

    def foo(self):
        "Base class foo"
        pass

class Mid(Base):

    @doc_inherit
    def foo(self):
        # Should inherit doc string from Base
        pass

class Final(Mid):

    def __init__(self): pass

obj = Final()
obj.foo()

The output is:

python doc-inherit-bug.py 
Traceback (most recent call last):
  File "doc-inherit-bug.py", line 22, in <module>
    obj.foo()
  File "/Users/Mike/Downloads/recipe_576862.py", line 34, in __get__
    return self.get_with_inst(obj, cls)
  File "/Users/Mike/Downloads/recipe_576862.py", line 40, in get_with_inst
    overridden = getattr(super(cls, obj), self.name, None)
[snip]
  File "/Users/Mike/Downloads/recipe_576862.py", line 34, in __get__
    return self.get_with_inst(obj, cls)
  File "/Users/Mike/Downloads/recipe_576862.py", line 40, in get_with_inst
    overridden = getattr(super(cls, obj), self.name, None)
RuntimeError: maximum recursion depth exceeded while calling a Python object

Unfortunately, I don't understand python's super well enough to figure out how to fix it. Anyone have an idea how the recipe could be tweaked to allow this use case?

Thanks so much for your help.

MineGo

Here is my MineGo Referral Code: axel Sign up now and let's win together.

comments?

I was viewing an ActiveState recipe at: https://code.activestate.com/recipes/65207-constants-in-python/

I saw the link to this GitHub repo. I'm not sure what is the intention of this repo. Is it meant to replace the website? If so, the repo is missing a very important thing: the comments.

Many recipes include comments that expand upon the recipes themselves. Look at the page I mentioned above for an example.

connection refused

Hi,
I am following this recipe: https://github.com/ActiveState/code/blob/3b27230f418b714bc9a0f897cb8ea189c3515e99/recipes/Python/577548_HTTPS_httplib_Client_ConnectiCertificate/recipe-577548.py

but I am getting the following error:

Traceback (most recent call last):
File "./firas.py", line 45, in
conn.request('GET', '/_searchguard/authinfo')
File "/usr/lib64/python2.7/httplib.py", line 1017, in request
self._send_request(method, url, body, headers)
File "/usr/lib64/python2.7/httplib.py", line 1051, in _send_request
self.endheaders(body)
File "/usr/lib64/python2.7/httplib.py", line 1013, in endheaders
self._send_output(message_body)
File "/usr/lib64/python2.7/httplib.py", line 864, in _send_output
self.send(msg)
File "/usr/lib64/python2.7/httplib.py", line 826, in send
self.connect()
File "./firas.py", line 26, in connect
sock = socket.create_connection((self.host, self.port), self.timeout)
File "/usr/lib64/python2.7/socket.py", line 571, in create_connection
raise err
socket.error: [Errno 111] Connection refused

Any help is really appreciated. I am not seeing anything in the logs that can help me in debugging this issue.

Thanks,
Firas Khasawneh

DOC: what does "b/w" mean?

I don't understand this:

Returns a list of points from (start, end] by ray tracing a line b/w the points.

get_rev_children() ?

In recipe-579138.py, there is a get_rev_children method in the depth-first search. This method does not work on any of my editors/REPLs and there is no documentation on it anywhere. Is this a typo? Or is something missing?

Wiki is full of duplicated entries and broken links.

The last commit of the wiki left most of its pages chock full of duplicates and incorrect links. I cleaned it up some, but someone should probably write a proper script to generate those files instead of whatever bone-headed method was used last time.

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.