Recent Pads - Page 30

Total pad count: 637
created 6 years, 7 days ago
better-python-script-to-count-extensions

# bash script to find all extensions in the current tree
find . -type f -name '*.*' | awk -F. '{print $NF}' > /tmp/extensions.txt



# python script to count extensions
extensions = {}
... view all 33 lines

created 6 years, 7 days ago
7e0b293b-acb8-443f-acd8-58023b61764f

>>> assetDict = {}
>>> for asset in api.assets()['response']['assets']:
...     try:
...         assetDict[ asset['id'] ] = { 'name': asset['name'], 'ips': asset['definedIPs'] }
...     except:
...         pass
... view all 6 lines

created 6 years, 8 days ago
spread-server-patch-over-time-period

from getservers import getservers

import datetime # used to create datetime objects

import sys # used to get args from cli

def datepool( startdate, days = 8 ):
... view all 55 lines

created 6 years, 8 days ago
python-read-and-seek-binary-file

file = open( 'binaryfile', 'rb' )

# read to the needed data, this does a seek
file.read( 48 )

header  = file.read( 12 )
drawing = file.read( 6 )
... view all 8 lines

created 6 years, 8 days ago
perl-check-if-pid-is-running

#cat check_if_pid_running.pl

sub check_pid_file{
    open(PIDFILE, $_[0]) || return undef;
    my $pid = <PIDFILE>;
    close(PIDFILE);
    $pid =~ /^\s*(\d+)/ || return undef;
... view all 22 lines

created 6 years, 12 days ago
05820f2b-c54b-43a9-98e2-8e83001fe370

  cost | requests |   ratio | market
 15.00 |   15,000 | $1:1000 | Good for development
 60.00 |   75,000 | $1:1250 | Better for freelancers
180.00 |  300,000 | $1:1665 | Best for production
... view all 4 lines

created 6 years, 12 days ago
python-file-rotation-with-retention-count

def rotate( target, retention = 3 ):
    """file rotation routine"""
    if path.isfile( target ): # check if we even need to rotate
        for i in range( retention-2, 0, -1 ): # count backwards
            old_name = "%s.%s" % ( target, i )
            new_name = "%s.%s" % ( target, i + 1 )
            try: move( old_name, new_name  )
... view all 10 lines

created 6 years, 12 days ago
python-file-rotation-with-varible-retention-count

from os import path
from shutil import move

tehfile = "junk"
retention = 3

if path.isfile( tehfile ):
... view all 23 lines

created 6 years, 18 days ago
python-count-file-extensions

# bash script to find all extensions in the current tree
find . -type f -name '*.*' | awk -F. '{print $NF}' > /tmp/extensions.txt

# python script to count extensions
extensions = {}
f = open( '/tmp/extensions.txt' )
for extension in f.readlines():
... view all 16 lines

created 6 years, 18 days ago
7aadb76f-0827-4fb0-92a3-d016d65e8b89

>>> f.close()
>>> f = open( '/tmp/extens.txt' )
>>> for ext in f.readlines():
...     ext = ext.rstrip('\n')
...     if ext in myDICT:
...         myDICT[ext] += 1
...     else:
... view all 9 lines

created 6 years, 18 days ago
pymongo-is-so-simple

import pymongo
db = pymongo.Connection( 'mongodb://localhost/' )[ 'linkpeek' ]
print sum( [ user['rcount'] for user in db.user.find() ] )
... view all 4 lines

created 6 years, 20 days ago
messing-with-python-callbacks

>>> from time import sleep
>>> def call_me_maybe( target, callback ):
...     print target
...     sleep( 5 )
...     callback( target.upper() )
... 
>>> def test_call_me_maybe( target ):
... view all 17 lines

created 6 years, 23 days ago
python-multi-arm-bandit

from random import random, choice

def choose_lever( levers ):
    """Accept a dict of levers, return tuple ( key, levers )"""
    if random() < 0.1:
        # exploration! choose random lever 10% of time
        explored_key = choice( levers.keys() )
... view all 45 lines

created 6 years, 24 days ago
test_hyphen_filenames

    def test_hyphen_filenames(self):
        info = DummyRendererInfo({
            'name':'app:moon-and-world.mak',
            'package':None,
            'registry':self.config.registry,
            'settings':{},
            'type': ''
... view all 11 lines

created 6 years, 24 days ago
5d498f88-5e8c-4f08-b73a-27d50a56ac11

@view_config( route_name="template")
def template(request):
    # check if template exists before rendering
    from pkg_resources import resource_exists
    from pyramid.renderers import render_to_response

... view all 17 lines

created 6 years, 24 days ago
3165a602-db16-417d-8c03-e1bcff0ab644

(virtpy)[fox@blanka linkpeek]$ pserve development.ini --reload
Starting subprocess with file monitor
Starting server in PID 4365.
serving on 0.0.0.0:9001 view at http://127.0.0.1:9001
2012-09-22 01:19:26,731 ERROR [pyramid_debugtoolbar][worker 0] Exception at http://127.0.0.1:9001/how-much-does-linkpeek-cost
traceback url: http://127.0.0.1:9001/_debug_toolbar/exception?token=15fac23dae77dfb5b654&tb=54746512
Traceback (most recent call last):
... view all 35 lines

created 6 years, 26 days ago
2652d76d-e09c-4ac0-af9f-0e973e715e40

    if page['state'] != 'serving': # if the page is not serving
        waited = 0
        while page['state'] != 'serving':
            sleep( 1 )
            waited += 1
            page = request.db.api.find_one( { 'uri': uri } )
            if waited >= 30 or not page:
... view all 13 lines

created 6 years, 27 days ago
049bf5e1-1c89-4fa8-825b-94737ef8d93a

/api/v1?uri=http://davematthewsbandspotify.com/&apikey=e0a8tumxz&token=8ca9b4af907c59d90820198cf93effff&size=560x280

/api/v2/e0a8tumxz/8ca9b4af907c59d90820198cf93effff?uri=http://davematthewsbandspotify.com/&size=560x280
... view all 3 lines

created 6 years, 27 days ago
fb0f5474-c229-4b2c-8505-5fb54c8f5005

/api/v1?uri=http://davematthewsbandspotify.com/&apikey=e0a8tumxz&token=8ca9b4af907c59d90820198cf93effff&size=560x280

/api/v2/e0a8tumxz/8ca9b4af907c59d90820198cf93effff?target=http://davematthewsbandspotify.com/&size=560x280
... view all 3 lines

created 6 years, 30 days ago
pyramid-inject-renderer-globals-title-and-analytics

def inject_renderer_globals( event ):
    """Inject some renderer globals before passing to template"""

    request = event['request']

    # Build ${title} from the current request.path  
    event['title'] =  ' - '.join( request.path.replace( '-', ' ' ).split( '/' )[1:] ).title()
... view all 11 lines

pages 1 .. 28 29 30 31 32