Skip to content

Commit

Permalink
Merge pull request #1 from ActiveState/master
Browse files Browse the repository at this point in the history
sync
  • Loading branch information
mantonovic authored Sep 10, 2018
2 parents c2ffb72 + 73b09ed commit a7c3023
Show file tree
Hide file tree
Showing 21 changed files with 1,426 additions and 329 deletions.
12 changes: 6 additions & 6 deletions recipes/Bash/576876_awk_sample/recipe-576876.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#!/usr/bin/env bash

file=${1:?"file?"}
FILE=${1:?"FILE?"}

echo $*
#get the fields
Expand All @@ -9,10 +9,10 @@ echo $*
#print the fields

#awk 'BEGIN { FS = "\n"; RS = "" }\
#{print $2}' $file \
sed -n '/.*user.*system.*/p' $file \
|sed -e 's/user//' -e 's/system//' -e 's/elapsed//' |\
awk 'BEGIN { FS = " "; RS = "\n" }\
#{print $2}' $FILE \
$(which sed) -n '/.*user.*system.*/p' ${FILE} \
|$(which sed) -e 's/user//' -e 's/system//' -e 's/elapsed//' |\
$(which awk) 'BEGIN { FS = " "; RS = "\n" }\
{split($3, real, ":"); $3=real[1]*60 + real[2]} \
#{printf $1 "\t"$2 "\t" $3"\n"} \
{ user_sum += $1; sys_sum += $2; real_sum += $3; count++} \
Expand Down
2 changes: 1 addition & 1 deletion recipes/Bash/578661_find__grep/recipe-578661.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env zsh

tmp_file="/tmp/_unsorted_find_n_grep"
tmp_file="$(mktemp)"
echo "--- find <$2> in <$1>" > $tmp_file

find . -follow -iname "$1" | while read file
Expand Down
1 change: 1 addition & 0 deletions recipes/Bash/tree_alias/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This work is released to the public domain under the CC0 (Creative Commons) license terms: https://creativecommons.org/publicdomain/zero/1.0/legalcode
8 changes: 8 additions & 0 deletions recipes/Bash/tree_alias/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### An alias for the tree command

Author: Unknown
Submitter: Alan Young (harleypig)

If the tree command does not exist on your system, this alias will fake it.

I got this from a co-worker a long time ago. I don't remember when, or who it was. If it was you, let me know and I'll update this.
10 changes: 10 additions & 0 deletions recipes/Bash/tree_alias/tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# I got this from a co-worker many moons ago. Unfortunately, I don't remember
# who. Basically, if a tree program is not installed, fake it with this.

if ! command -v tree > /dev/null 2>&1; then

alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"

fi
29 changes: 15 additions & 14 deletions recipes/Python/117119_Sieve_of_Eratosthenes/recipe-117119.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# Sieve of Eratosthenes
# David Eppstein, UC Irvine, 28 Feb 2002
# Originaly made by : David Eppstein, UC Irvine, 28 Feb 2002
# Performance improvements : Gabriel Freitas, 7 Oct 2017

from __future__ import generators
from itertools import count

def eratosthenes():
'''Yields the sequence of prime numbers via the Sieve of Eratosthenes.'''
D = {} # map composite integers to primes witnessing their compositeness
q = 2 # first integer to test for primality
while 1:
if q not in D:
yield q # not marked composite, must be prime
D[q*q] = [q] # first multiple of q not already marked
else:
for p in D[q]: # move each witness to its next multiple
D.setdefault(p+q,[]).append(p)
del D[q] # no longer need D[q], free memory
q += 1
"""Yields the sequence of prime numbers via the Sieve of Eratosthenes"""
yield 2 # force yield the first prime number

D = {} # map composite integers to primes witnessing their compositeness
for q in count(start=3, step=2):
if q not in D:
yield q # not marked composite, must be prime
D[q*q] = [q] # first multiple of q not already marked
else:
for p in D[q]: # move each witness to its next odd multiple
D.setdefault(2*p+q,[]).append(p)
del D[q] # no longer need D[q], free memory
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ def recv_timeout(the_socket,timeout=2):
total_data.append(data)
begin=time.time()
else:
time.sleep(0.1)
# Incase there is actually no data to be read from a non blocking socket,
# a socket.error exception is raised with EWOULDBLOCK OR EAGAIN
# If there is data of zero length read, it implies the socket was closed on the other end.
the_socket.close()
break
except:
pass
return ''.join(total_data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def complete(self, text, state):
"""
# keep a completer class, and make sure that it uses the current local scope
if not hasattr(self, 'completer'):
import rlcompleter
self.completer = rlcompleter.Completer(self.curframe.f_locals)
else:
self.completer.namespace = self.curframe.f_locals
Expand Down
Loading

0 comments on commit a7c3023

Please sign in to comment.