2015-07-28

PYTHON - List all first-level subdirectories

import os
os.chdir( '/YOUR/PATH/' )
for folder in sorted( os.listdir( os.getcwd() ) ):
    if not os.path.isfile( folder ):
        print folder

PYTHON - Extract string content between parenthesis (without regex)

print YOUR_STRING[ YOUR_STRING.find( '(' ) + 1 : YOUR_STRING.find( ')' ) ]

PYTHON - Short if-else

RESULT = [VALUE_IF_FALSE, VALUE_IF_TRUE][CONDITION]
 
r = [10, 20][0 == 0]

MacOS - How to toggle between windows of the same app

COMMAND-`

PS. To toggle between apps:  COMMAND-TAB

2015-07-27

2015-07-26

PYTHON - How to curl into a file?

(1) Install the pycurl package:
easy_install pycurl


(2) Sample script:

import pycurl
c = pycurl.Curl()
c.setopt(c.USERAGENT, 'Mozilla/5.0 (compatible; pycurl)' )

c.setopt(c.URL, 'http://website.com/page1.html')
with open('target_file_name.html', 'w') as f:
    c.setopt( c.WRITEFUNCTION, f.write )
    c.perform()
f.close()

2015-07-22

MacOS - How to customize your terminal prompt, adding a line after each command

(1) Open or create ~\.bash_profile (a text flat file at the root of your MacOS profile).

(2) Enter this line (cusomize... the dashes can be anything you want... the \n is a carriage return+line feed):

export PS1="----------------\n$"