From acde9bbeb7337c821934d8649ca203c9e3192303 Mon Sep 17 00:00:00 2001 From: Geoff Crompton Date: Thu, 15 Mar 2018 11:42:03 +1100 Subject: [PATCH 1/5] Removing 278260, it's a duplicate of 278259 --- .../Python/278260_Dictionary_Tools/LICENSE.md | 3 - .../Python/278260_Dictionary_Tools/README.md | 6 - .../278260_Dictionary_Tools/recipe-278260.py | 291 ------------------ 3 files changed, 300 deletions(-) delete mode 100644 recipes/Python/278260_Dictionary_Tools/LICENSE.md delete mode 100644 recipes/Python/278260_Dictionary_Tools/README.md delete mode 100644 recipes/Python/278260_Dictionary_Tools/recipe-278260.py diff --git a/recipes/Python/278260_Dictionary_Tools/LICENSE.md b/recipes/Python/278260_Dictionary_Tools/LICENSE.md deleted file mode 100644 index 86fe1ce11..000000000 --- a/recipes/Python/278260_Dictionary_Tools/LICENSE.md +++ /dev/null @@ -1,3 +0,0 @@ -Copyright 2004 Runsun Pan - -The software is licensed according to the terms of the PSF (Python Software Foundation) license found here: http://www.python.org/psf/license/ \ No newline at end of file diff --git a/recipes/Python/278260_Dictionary_Tools/README.md b/recipes/Python/278260_Dictionary_Tools/README.md deleted file mode 100644 index 61a762b68..000000000 --- a/recipes/Python/278260_Dictionary_Tools/README.md +++ /dev/null @@ -1,6 +0,0 @@ -## Dictionary Tools -Originally published: 2004-04-14 14:06:08 -Last updated: 2004-04-14 14:06:08 -Author: Runsun Pan - -A collection of some dictionary tools \ No newline at end of file diff --git a/recipes/Python/278260_Dictionary_Tools/recipe-278260.py b/recipes/Python/278260_Dictionary_Tools/recipe-278260.py deleted file mode 100644 index 5a48beb42..000000000 --- a/recipes/Python/278260_Dictionary_Tools/recipe-278260.py +++ /dev/null @@ -1,291 +0,0 @@ -#======================================================================== - -def sumDict(d): - return reduce(lambda x,y:x+y, d.values()) - -#======================================================================== - -def avgDict(d): - return reduce(lambda x,y:x+y, d.values()) / (len(d)*1.0) - -#======================================================================== - -def mkDict(keyList, valueList, cond=None): - ''' - Make a new dict out of two lists. The first list provides keys, - the 2nd provides values. The cond is a function taking 2 arguments: - key and value. Example: lambda k,v:v%2==0 - A valid item means its cond(key, value) is true. Only valid items - are included in the returned dict. - - >>> a - [0, 1, 2, 3, 4] - - >>> b= [chr(x) for x in range(65,70)] - >>> b - ['A', 'B', 'C', 'D', 'E'] - - >>> mkDict(b,a) - {'A': 0, 'C': 2, 'B': 1, 'E': 4, 'D': 3} - - >>> mkDict(b,a,lambda x,y:y%2==0) - {'A': 0, 'C': 2, 'E': 4} - - Note: - mkDict(a,b) (without the conditional check) is equavilant to - dict(zip(a,b)), which is much faster. If you know there's no - conditional check, better use dict(zip(a,b)) instead. - ''' - - if cond==None: - return dict(zip(keyList, valueList)) - else: - return dict( [(k,v) for k,v in zip(keyList, valueList) if cond(k,v)] ) - -#======================================================================== - -def trimDict(aDict, cond=(lambda k,v:1)): - ''' Return a new dict in which its items whose cond(k,v) == true - are removed (discarded) from aDict. - The cond is a function taking 2 arguments: key and value - - >>> g - {'A': 0, 'C': 2, 'B': 1, 'E': 4, 'D': 3} - >>> trimDict(g, lambda x,y:y%2!=0) - {'A': 0, 'C': 2, 'E': 4} - - ''' - tmp={} - [tmp.setdefault(k,v) for k,v in aDict.items() if not cond(k,v)] - return tmp.copy() - -#======================================================================== - -def reDict(aDict, func, cond=(lambda k,v:1), delUnchanged=0): - ''' - Given aDict, return a new dict with valid items (= items whose - cond(key, value) is true) been modified by the function func. - if delUnchanged, then those invalid items are excluded from - the returned dict. - - >>> d - {'B': 1, 'D': 3} - >>> reDict(d, lambda x:x**2) - {'B': 1, 'D': 9} - >>> g - {'A': 0, 'C': 2, 'B': 1, 'E': 4, 'D': 3} - >>> reDict(g, lambda x:-x, lambda k,v: v%2==0) - {'A': 0, 'C': -2, 'B': 1, 'E': -4, 'D': 3} - >>> reDict(g, lambda x:-x, lambda k,v: v%2==0, delUnchanged=1) - {'A': 0, 'C': -2, 'E': -4} - - ''' - tmp={} - if delUnchanged: - [tmp.setdefault(k,func(v)) for k,v in aDict.items() if cond(k,v)] - else: - [tmp.setdefault(k,(cond(k,v) and func(v) or v)) for k,v in aDict.items()] - return tmp.copy() - -#======================================================================== - -def normDict(d, normalizeTo=1): - ''' Normalize the values of d by setting the largest value in d.values - to normalizeTo. The return dict will have it's values spreading - between 0~normalizeTo''' - ks = d.keys() - vs = d.values() - vMax = max(vs) - vs= [ x/(vMax*1.0)*normalizeTo for x in vs] - return dict(zip(ks, vs)) - -#======================================================================== - -def normDictSumTo(d, sumTo=1): - ''' Normalize the values of d to sumTo. The returned dict will - have value sum = sumTo - ''' - ks = d.keys() - vs = d.values() - sum = reduce(lambda x,y:x+y, vs) - vs= [ x/(sum*1.0)*sumTo for x in vs] - return dict(zip(ks, vs)) - -#======================================================================== - -def accumDict(d, normalizeTo=None): - ''' if d.values=[1,2,3,4,5]: - accumDict(d).values ==> [1, 3, 6, 10, 15] - if d.values=[0.25, 0.25, 0.25, 0.25] - accumDict(d).values ==> [0.25, 0.50, 0.75, 1.00] - - Required: odict() - Ordered Dictionary Class - Dave Benjamin - http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/161403 - ''' - ks = d.keys() - vs = d.values() - if normalizeTo: vs = normListSumTo(vs, sumTo=normalizeTo) - - r = range(1, len(vs)) - newList=[vs[0]] - for i in r: - newList.append( newList[-1]+ vs[i] ) - - odic = odict() - for i in range(len(newList)): - odic[ks[i]] =newList[i] - return odic - -#======================================================================== - -def fallInDict(val, aDict, baseValue=0): - ''' - oo: - { - 'a':3, - 'b':5, - 'c':2 - } - accumDict(oo): - { - 'a':3, - 'b':8, - 'c':10 - } - fallInDict(0, oo)=0 - fallInDict(1, oo)=0 - fallInDict(2, oo)=0 - fallInDict(3, oo)=0 - fallInDict(4, oo)=1 - fallInDict(5, oo)=1 - fallInDict(6, oo)=1 - fallInDict(7, oo)=1 - fallInDict(8, oo)=1 - fallInDict(9, oo)=2 - fallInDict(10, oo)=2 - - When val out of range: - - fallInDict(-1, oo)= -1 - fallInDict(11, oo)= -2 - fallInDict(12, oo)= -2 - ''' - - if valacd.values()[-1]: return -2 - - ra = range(len(acd)) - - for i in ra: - vInDict = acd.values()[i] - if val <= vInDict: break - - return aDict.keys()[i] - -#======================================================================== - -def randomPickDict(d): - ''' given a diictionary d, with all values are numbers, - randomly pick an item and return it's key according - to the percentage of its values''' - ks = d.keys() - vs = accumList(d.values(),1) - return ks[ findIndex( vs, random.random()) ] - -#======================================================================== - -def sumInDict(L): - ''' Given a list L: - [ {'S': [s11,s12,s13], 'V':[v11,v12,v13], ...}, - {'S': [s21,s22,s23], 'V':[v21,v22,v23], ...}, - {'S': [s31,s32,s33], 'V':[v31,v32,v33], ...}, - ... ] - - Return a dict: - {'S': [s1,s2,s3], 'V':[v1,v2,v3], ...} - - where s1 = s11 + s21 + s31 + ... - s2 = s12 + s22 + s32 + ... - ''' - keys = L[0].keys() - new={} - for k in keys: - new[k] = [] # Init 'S':[] - for x in L: # x = {'S': [s11,s12,s13], 'V':[v11,v12,v13], ...} - y = x[k] # y = [s11,s12,s13] - new[k].append(y) - - ''' new[k] = [ [s11,s12,s13],[s21,s22,s23],[s31,s32,s33], ...] - Then use sumInList=> {'S': [s1,s2,s3],'V': [v1,v2,v3],... }''' - new[k] = sumInList(new[k]) - return new - -#======================================================================== - -def avgInDict(L): - ''' Given a list L: - [ {'S': [s11,s12,s13], 'V':[v11,v12,v13], ...}, - {'S': [s21,s22,s23], 'V':[v21,v22,v23], ...}, - {'S': [s31,s32,s33], 'V':[v31,v32,v33], ...}, - ... ] - - Return a dict: - {'S': [s1,s2,s3], 'V':[v1,v2,v3], ...} - - where s1 = avg of (s11 + s21 + s31 + ...) - s2 = avg of (s12 + s22 + s32 + ...) - ''' - ''' First turn L into: - {'S': [ [s11,s12,s13],[s21,s22,s23],[s31,s32,s33], ...], - 'V': [ [v11,v12,v13],[v21,v22,v23],[v31,v32,v33], ...], - ... } ''' - - keys = L[0].keys() - new={} - for k in keys: - new[k] = [] # Init 'S':[] - for x in L: # x = {'S': [s11,s12,s13], 'V':[v11,v12,v13], ...} - y = x[k] # y = [s11,s12,s13] - new[k].append(y) - - ''' new[k] = [ [s11,s12,s13],[s21,s22,s23],[s31,s32,s33], ...] - Then use avgInList=> {'S': [s1,s2,s3],'V': [v1,v2,v3],... }''' - new[k] = avgInList(new[k]) - return new - -#======================================================================== - -def sumInDict2(D): - ''' Given a dict: - {'A':{'S': [s11,s12,s13], 'V':[v11,v12,v13], ...}, - 'B':{'S': [s21,s22,s23], 'V':[v21,v22,v23], ...}, - 'C':{'S': [s31,s32,s33], 'V':[v31,v32,v33], ...}, ... - } - Return a dict: - {'S': [s1,s2,s3], 'V':[v1,v2,v3], ...} - - where s1 = s11 + s21 + s31 + ... - s2 = s12 + s22 + s32 + ... - ''' - return sumInDict(D.values()) - -#======================================================================== - -def avgInDict2(D): - ''' Given a dict: - {'A':{'S': [s11,s12,s13], 'V':[v11,v12,v13], ...}, - 'B':{'S': [s21,s22,s23], 'V':[v21,v22,v23], ...}, - 'C':{'S': [s31,s32,s33], 'V':[v31,v32,v33], ...}, ... - } - Return a dict: - {'S': [s1,s2,s3], 'V':[v1,v2,v3], ...} - - where s1 = avg of (s11 + s21 + s31 + ...) - s2 = avg of (s12 + s22 + s32 + ...) - ''' - return avgInDict(D.values()) - -#======================================================================== From 61a74f5f93da087d27c70b2efe779ac6bd2a3b4f Mon Sep 17 00:00:00 2001 From: Jeff Rouse Date: Tue, 2 Jul 2019 23:44:37 -0700 Subject: [PATCH 2/5] Changed extension to denote a java file. --- .../{recipe-576955.js => recipe-576955.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename recipes/JavaScript/576955_Incrementing_counter/{recipe-576955.js => recipe-576955.java} (100%) diff --git a/recipes/JavaScript/576955_Incrementing_counter/recipe-576955.js b/recipes/JavaScript/576955_Incrementing_counter/recipe-576955.java similarity index 100% rename from recipes/JavaScript/576955_Incrementing_counter/recipe-576955.js rename to recipes/JavaScript/576955_Incrementing_counter/recipe-576955.java From 5b83ef48a845deffe0f8596724678e73390a3885 Mon Sep 17 00:00:00 2001 From: Tammy DiPrima Date: Mon, 11 May 2020 12:08:15 -0400 Subject: [PATCH 3/5] fixed missing import statement 'import re' --- .../577468_Minimalistic_PostgreSQL_console/recipe-577468.py | 1 + 1 file changed, 1 insertion(+) diff --git a/recipes/Python/577468_Minimalistic_PostgreSQL_console/recipe-577468.py b/recipes/Python/577468_Minimalistic_PostgreSQL_console/recipe-577468.py index 53eb233f4..18c4e9769 100644 --- a/recipes/Python/577468_Minimalistic_PostgreSQL_console/recipe-577468.py +++ b/recipes/Python/577468_Minimalistic_PostgreSQL_console/recipe-577468.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +import re import sys import psycopg2 import psycopg2.extras From db8c96c09c06d52b1ad4b0a6ff7f001f3d2241d6 Mon Sep 17 00:00:00 2001 From: swaroop998 <72223625+swaroop998@users.noreply.github.com> Date: Fri, 2 Oct 2020 00:08:28 +0530 Subject: [PATCH 4/5] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c7f9c4eb7..28c4eaf7a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 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 +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. @@ -18,7 +18,7 @@ You can find the master index of all recipes over at the [wiki](https://github.c *Coming Soon: Search Functionality!* -## How do I submit a new recipe? +## 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). From e6378c55515c45eb8eab07ca64c59ddefba9bf94 Mon Sep 17 00:00:00 2001 From: Jeff Rouse Date: Mon, 12 Oct 2020 16:31:24 -0700 Subject: [PATCH 5/5] Removed short form for between for inline docs. --- .../Python/578112_Bresenhams_line_algorithm/recipe-578112.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/recipes/Python/578112_Bresenhams_line_algorithm/recipe-578112.py b/recipes/Python/578112_Bresenhams_line_algorithm/recipe-578112.py index 8838ad588..dffe22406 100644 --- a/recipes/Python/578112_Bresenhams_line_algorithm/recipe-578112.py +++ b/recipes/Python/578112_Bresenhams_line_algorithm/recipe-578112.py @@ -68,8 +68,8 @@ def _bresenhamlines(start, end, max_iter): def bresenhamline(start, end, max_iter=5): """ - Returns a list of points from (start, end] by ray tracing a line b/w the - points. + Returns a list of points from (start, end] by ray tracing a line between + the points. Parameters: start: An array of start points (number of points x dimension) end: An end points (1 x dimension)