Q:

How can I test several lines of quickly? 

Let's say I am browing hithub and I see some code in python I would like to run on my laptop. 
 Is there a way to just copy, paste it and run it without having to create a file, paste the code and run it ? 
I tried running ipython on the terminal, then %cpaste and finally pasted the code but it didn't work. 
Thanks ! 
UPDATE: (more information)
I tried to run this:
import scrapy

class RedditScraper(scrapy. Spider):
    keyword     =   raw_input("Enter the keyword to scrap: ")
    name        =   'redditscraper'
    oop_url     =   'https://www.reddit.com/r/'+keyword
    start_urls  =   [oop_url]

    def parse(self, response):
            for post in response.css('a.title.may-blank::text').extract():
                print post + "\n"

and I got this:
ariel@EscritorioPC:~$ ipython
Python 2.7.11+ (default, Apr 17 2016, 14:00:29) 
Type "copyright", "credits" or "license" for more information. 

IPython 2.4.1 -- An enhanced Interactive Python. 
?          -> Introduction and overview of IPython's features. 
%quickref -> Quick reference. 
help      -> Python's own help system. 
object?    -> Details about 'object', use 'object??'  for extra details. 

In [1]: %cpaste
Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
:import scrapy
:
:class RedditScraper(scrapy. Spider):
:       keyword 
Display all 341 possibilities? ( y or n)
%%! 
%%HTML
%%SVG
%%bash
%%capture
%%debug
%%file
%%html
%%javascript
%%latex
%%perl
%%prun
%%pypy
%%python
%%python2
%%python3
%%ruby
%%script
%%sh
%%svg
%%sx
%%system
%%time
%%timeit
%%writefile
%alias
%alias_magic
%autocall
%autoindent
%automagic
%bookmark
%cat
%cd
%clear
%colors
%config
%cp
%cpaste
%debug
%dhist
%dirs
%doctest_mode
%ed
%edit
%env
%gui
%hist
%history
%install_default_config
%install_ext
%install_profiles
%killbgscripts
%ldir
%less
%lf
%lk
%ll
%load
%load_ext
%loadpy
%logoff
%logon
%logstart
%logstate
%logstop
%ls
%lsmagic
%lx
%macro
%magic
%man
%matplotlib
%mkdir
%more
%mv
%notebook
%page
%paste
%pastebin
%pdb
%pdef
%pdoc
%pfile
%pinfo
%pinfo2
%popd
%pprint
%precision
%profile
%prun
%psearch
%psource
%pushd
%pwd
%pycat
%pylab
%quickref
%recall
%rehashx
%reload_ext
%rep
%rerun
%reset
%reset_selective
%rm
%rmdir
%run
%save
%sc
%store
%sx
%system
%tb
%time
%timeit
%unalias
%unload_ext
%who
%who_ls
%whos
%xdel
%xmode
Android
ArithmeticError
AssertionError
AttributeError
BaseException
BufferError
BytesWarning
DeprecationWarning
Desktop
Documents
Downloads
EOFError
Ellipsis
EnvironmentError
Exception
False
FloatingPointError
FutureWarning
GeneratorExit
IOError
ImportError
ImportWarning
In
IndentationError
IndexError
Kali-Linux-2.0.0-vm-amd64
KeyError
KeyboardInterrupt
LPCXpresso
LookupError
MemoryError
Music
NameError
None
NotImplemented
NotImplementedError
OSError
Out
OverflowError
PendingDeprecationWarning
Pictures
Programas
Public
ReferenceError
RuntimeError
RuntimeWarning
Screenshot\ from\ 2016-06-20\ 03_49_46.png
Screenshot\ from\ 2016-06-20\ 03_52_40.png
StandardError
StopIteration
SyntaxError
SyntaxWarning
SystemError
SystemExit
TabError
Templates
True
TypeError
UnboundLocalError
UnicodeDecodeError
UnicodeEncodeError
UnicodeError
UnicodeTranslateError
UnicodeWarning
UserWarning
ValueError
Videos
VirtualBox\ VMs
Warning
ZeroDivisionError
_
__
__IPYTHON__
__IPYTHON__active
___
__builtin__
__debug__
__doc__
__import__
__name__
__package__
_dh
_i
_i1
_ih
_ii
_iii
_oh
_sh
abs
all
and
any
apply
as
assert
basestring
bin
bool
break
buffer
bytearray
bytes
callable
chr
class
classmethod
cmp
coerce
compile
complex
continue
copyright
credits
def
del
delattr
dict
dir
divmod
dreload
elif
else
enumerate
eval
examples.desktop
except
exec
execfile
exit
file
filter
finally
float
for
format
from
frozenset
get_ipython
getattr
global
globals
hasattr
hash
help
hex
id
if
import
in
input
int
intel
intern
is
isinstance
issubclass
iter
kivy-1.9.1
lambda
len
license
list
locals
logs
long
man.pdf
map
max
memoryview
min
nano.save
next
not
object
oct
open
or
ord
pass
photorec.ses
pow
primerapp
print
property
quit
raise
range
raw_input
reduce
reload
repr
return
reversed
round
set
setattr
slice
sorted
staticmethod
str
sum
super
titanium.studio.linux.gtk.x86_64.zip
tools
try
tuple
type
unichr
unicode
vars
wget.log
while
with
www.draidel.com
xdk_web_linux64
xrange
yield
zip
:       keyword = 
Display all 313 possibilities? ( y or n)
%%!                         RuntimeWarning
%%HTML                     StandardError
%%SVG                      StopIteration
%%bash                     SyntaxError
%%capture                  SyntaxWarning
%%debug                    SystemError
%%file                     SystemExit
%%html                     TabError
%%javascript               True
%%latex                    TypeError
%%perl                     UnboundLocalError
%%prun                     UnicodeDecodeError
%%pypy                     UnicodeEncodeError
%%python                   UnicodeError
%%python2                  UnicodeTranslateError
%%python3                  UnicodeWarning
%%ruby                     UserWarning
%%script                   ValueError
%%sh                       Warning
%%svg                      ZeroDivisionError
%%sx                       _
%%system                   __
%%time                     __IPYTHON__
%%timeit                   __IPYTHON__active
%%writefile                ___
%alias                     __builtin__
%alias_magic               __debug__
%autocall                  __doc__
%autoindent                __import__
%automagic                 __name__
%bookmark                  __package__
%cat                       _dh
%cd                        _i
%clear                     _i1
%colors                    _ih
%config                    _ii
%cp                        _iii
%cpaste                    _oh
%debug                     _sh
%dhist                     abs
%dirs                      all
%doctest_mode              and
%ed                        any
%edit                      apply
%env                       as
%gui                       assert
%hist                      basestring
%history                   bin
%install_default_config    bool
%install_ext               break
%install_profiles          buffer
%killbgscripts             bytearray
%ldir                      bytes
%less                      callable
%lf                        chr
%lk                        class
%ll                        classmethod
%load                      cmp
%load_ext                  coerce
%loadpy                    compile
%logoff                    complex
%logon                     continue
%logstart                  copyright
%logstate                  credits
%logstop                   def
%ls                        del
%lsmagic                   delattr
%lx                        dict
%macro                     dir
%magic                     divmod
%man                       dreload
%matplotlib                elif
%mkdir                     else
%more                      enumerate
%mv                        eval
%notebook                  except
%page                      exec
%paste                     execfile
%pastebin                  exit
%pdb                       file
%pdef                      filter
%pdoc                      finally
%pfile                     float
%pinfo                     for
%pinfo2                    format
%popd                      from
%pprint                    frozenset
%precision                 get_ipython
%profile                   getattr
%prun                      global
%psearch                   globals
%psource                   hasattr
%pushd                     hash
%pwd                       help
%pycat                     hex
%pylab                     id
%quickref                  if
%recall                    import
%rehashx                   in
%reload_ext                input
%rep                       int
%rerun                     intern
%reset                     is
%reset_selective           isinstance
%rm                        issubclass
%rmdir                     iter
%run                       lambda
%save                      len
%sc                        license
%store                     list
%sx                        locals
%system                    long
%tb                        map
%time                      max
%timeit                    memoryview
%unalias                   min
%unload_ext                next
%who                       not
%who_ls                    object
%whos                      oct
%xdel                      open
%xmode                     or
ArithmeticError            ord
AssertionError             pass
AttributeError             pow
BaseException              print
BufferError                property
BytesWarning               quit
DeprecationWarning         raise
EOFError                   range
Ellipsis                   raw_input
EnvironmentError           reduce
Exception                  reload
False                      repr
FloatingPointError         return
FutureWarning              reversed
GeneratorExit              round
IOError                    set
ImportError                setattr
ImportWarning              slice
In                         sorted
IndentationError           staticmethod
IndexError                 str
KeyError                   sum
KeyboardInterrupt          super
LookupError                try
MemoryError                tuple
NameError                  type
None                       unichr
NotImplemented             unicode
NotImplementedError        vars
OSError                    while
Out                        with
OverflowError              xrange
PendingDeprecationWarning  yield
ReferenceError             zip
RuntimeError               
:       keyword = raw_input("Enter the keyword to scrap: ")
:       name=
Display all 313 possibilities? ( y or n)
%%!                         RuntimeWarning
%%HTML                     StandardError
%%SVG                      StopIteration
%%bash                     SyntaxError
%%capture                  SyntaxWarning
%%debug                    SystemError
%%file                     SystemExit
%%html                     TabError
%%javascript               True
%%latex                    TypeError
%%perl                     UnboundLocalError
%%prun                     UnicodeDecodeError
%%pypy                     UnicodeEncodeError
%%python                   UnicodeError
%%python2                  UnicodeTranslateError
%%python3                  UnicodeWarning
%%ruby                     UserWarning
%%script                   ValueError
%%sh                       Warning
%%svg                      ZeroDivisionError
%%sx                       _
%%system                   __
%%time                     __IPYTHON__
%%timeit                   __IPYTHON__active
%%writefile                ___
%alias                     __builtin__
%alias_magic               __debug__
%autocall                  __doc__
%autoindent                __import__
%automagic                 __name__
%bookmark                  __package__
%cat                       _dh
%cd                        _i
%clear                     _i1
%colors                    _ih
%config                    _ii
%cp                        _iii
%cpaste                    _oh
%debug                     _sh
%dhist                     abs
%dirs                      all
%doctest_mode              and
%ed                        any
%edit                      apply
%env                       as
%gui                       assert
%hist                      basestring
%history                   bin
%install_default_config    bool
%install_ext               break
%install_profiles          buffer
%killbgscripts             bytearray
%ldir                      bytes
%less                      callable
%lf                        chr
%lk                        class
%ll                        classmethod
%load                      cmp
%load_ext                  coerce
%loadpy                    compile
%logoff                    complex
%logon                     continue
%logstart                  copyright
%logstate                  credits
%logstop                   def
%ls                        del
%lsmagic                   delattr
%lx                        dict
%macro                     dir
%magic                     divmod
%man                       dreload
%matplotlib                elif
%mkdir                     else
%more                      enumerate
%mv                        eval
%notebook                  except
%page                      exec
%paste                     execfile
%pastebin                  exit
%pdb                       file
%pdef                      filter
%pdoc                      finally
%pfile                     float
%pinfo                     for
%pinfo2                    format
%popd                      from
%pprint                    frozenset
%precision                 get_ipython
%profile                   getattr
%prun                      global
%psearch                   globals
%psource                   hasattr
%pushd                     hash
%pwd                       help
%pycat                     hex
%pylab                     id
%quickref                  if
%recall                    import
%rehashx                   in
%reload_ext                input
%rep                       int
%rerun                     intern
%reset                     is
%reset_selective           isinstance
%rm                        issubclass
%rmdir                     iter
%run                       lambda
%save                      len
%sc                        license
%store                     list
%sx                        locals
%system                    long
%tb                        map
%time                      max
%timeit                    memoryview
%unalias                   min
%unload_ext                next
%who                       not
%who_ls                    object
%whos                      oct
%xdel                      open
%xmode                     or
ArithmeticError            ord
AssertionError             pass
AttributeError             pow
BaseException              print
BufferError                property
BytesWarning               quit
DeprecationWarning         raise
EOFError                   range
Ellipsis                   raw_input
EnvironmentError           reduce
Exception                  reload
False                      repr
FloatingPointError         return
FutureWarning              reversed
GeneratorExit              round
IOError                    set
ImportError                setattr
ImportWarning              slice
In                         sorted
IndentationError           staticmethod
IndexError                 str
KeyError                   sum
KeyboardInterrupt          super
LookupError                try
MemoryError                tuple
NameError                  type
None                       unichr
NotImplemented             unicode
NotImplementedError        vars
OSError                    while
Out                        with
OverflowError              xrange
PendingDeprecationWarning  yield
ReferenceError             zip
RuntimeError               
:       name='redditscraper'
:       oop_url=
Display all 313 possibilities? ( y or n)
%%!                         RuntimeWarning
%%HTML                     StandardError
%%SVG                      StopIteration
%%bash                     SyntaxError
%%capture                  SyntaxWarning
%%debug                    SystemError
%%file                     SystemExit
%%html                     TabError
%%javascript               True
%%latex                    TypeError
%%perl                     UnboundLocalError
%%prun                     UnicodeDecodeError
%%pypy                     UnicodeEncodeError
%%python                   UnicodeError
%%python2                  UnicodeTranslateError
%%python3                  UnicodeWarning
%%ruby                     UserWarning
%%script                   ValueError
%%sh                       Warning
%%svg                      ZeroDivisionError
%%sx                       _
%%system                   __
%%time                     __IPYTHON__
%%timeit                   __IPYTHON__active
%%writefile                ___
%alias                     __builtin__
%alias_magic               __debug__
%autocall                  __doc__
%autoindent                __import__
%automagic                 __name__
%bookmark                  __package__
%cat                       _dh
%cd                        _i
%clear                     _i1
%colors                    _ih
%config                    _ii
%cp                        _iii
%cpaste                    _oh
%debug                     _sh
%dhist                     abs
%dirs                      all
%doctest_mode              and
%ed                        any
%edit                      apply
%env                       as
%gui                       assert
%hist                      basestring
%history                   bin
%install_default_config    bool
%install_ext               break
%install_profiles          buffer
%killbgscripts             bytearray
%ldir                      bytes
%less                      callable
%lf                        chr
%lk                        class
%ll                        classmethod
%load                      cmp
%load_ext                  coerce
%loadpy                    compile
%logoff                    complex
%logon                     continue
%logstart                  copyright
%logstate                  credits
%logstop                   def
%ls                        del
%lsmagic                   delattr
%lx                        dict
%macro                     dir
%magic                     divmod
%man                       dreload
%matplotlib                elif
%mkdir                     else
%more                      enumerate
%mv                        eval
%notebook                  except
%page                      exec
%paste                     execfile
%pastebin                  exit
%pdb                       file
%pdef                      filter
%pdoc                      finally
%pfile                     float
%pinfo                     for
%pinfo2                    format
%popd                      from
%pprint                    frozenset
%precision                 get_ipython
%profile                   getattr
%prun                      global
%psearch                   globals
%psource                   hasattr
%pushd                     hash
%pwd                       help
%pycat                     hex
%pylab                     id
%quickref                  if
%recall                    import
%rehashx                   in
%reload_ext                input
%rep                       int
%rerun                     intern
%reset                     is
%reset_selective           isinstance
%rm                        issubclass
%rmdir                     iter
%run                       lambda
%save                      len
%sc                        license
%store                     list
%sx                        locals
%system                    long
%tb                        map
%time                      max
%timeit                    memoryview
%unalias                   min
%unload_ext                next
%who                       not
%who_ls                    object
%whos                      oct
%xdel                      open
%xmode                     or
ArithmeticError            ord
AssertionError             pass
AttributeError             pow
BaseException              print
BufferError                property
BytesWarning               quit
DeprecationWarning         raise
EOFError                   range
Ellipsis                   raw_input
EnvironmentError           reduce
Exception                  reload
False                      repr
FloatingPointError         return
FutureWarning              reversed
GeneratorExit              round
IOError                    set
ImportError                setattr
ImportWarning              slice
In                         sorted
IndentationError           staticmethod
IndexError                 str
KeyError                   sum
KeyboardInterrupt          super
LookupError                try
MemoryError                tuple
NameError                  type
None                       unichr
NotImplemented             unicode
NotImplementedError        vars
OSError                    while
Out                        with
OverflowError              xrange
PendingDeprecationWarning  yield
ReferenceError             zip
RuntimeError               
:       oop_url='https://www.reddit.com/r/'+keyword
:       start_urls 
Display all 341 possibilities? ( y or n)
%%! 
%%HTML
%%SVG
%%bash
%%capture
%%debug
%%file
%%html
%%javascript
%%latex
%%perl
%%prun
%%pypy
%%python
%%python2
%%python3
%%ruby
%%script
%%sh
%%svg
%%sx
%%system
%%time
%%timeit
%%writefile
%alias
%alias_magic
%autocall
%autoindent
%automagic
%bookmark
%cat
%cd
%clear
%colors
%config
%cp
%cpaste
%debug
%dhist
%dirs
%doctest_mode
%ed
%edit
%env
%gui
%hist
%history
%install_default_config
%install_ext
%install_profiles
%killbgscripts
%ldir
%less
%lf
%lk
%ll
%load
%load_ext
%loadpy
%logoff
%logon
%logstart
%logstate
%logstop
%ls
%lsmagic
%lx
%macro
%magic
%man
%matplotlib
%mkdir
%more

it continues.....

A:

%paste works for me.   
In editor I indent with tab
def foo(x):
--->return x

Do a copy
In [892]: %paste
def foo(x):
        return x

## -- End pasted text --

In [893]: foo(2)
Out[893]: 2

Actually ctrl v paste, with and without %cpaste works as well.   Which makes me wonder whether something else is going on.   Your paste from github doesn't preserve any funny characters. 
OK, it isn't the indentation tab that's causing the problem, is the internal ones.   If I add 2 more tabs to the function
def foo(x):
    x   =   34
    return x

%paste works fine, but during ctrl v, the interior tab triggers tab completion.   
Try this in your ipython session
<tab>x<tab>=3

