SlideShare a Scribd company logo
Crosswise	
  
Brogramming - Python, Bash for Data Processing, and Git
¡  Python	
  
§  The	
  Zen	
  of	
  Python	
  
§  Conventions	
  and	
  PEP8	
  
§  Tips	
  &	
  Tricks,	
  Do’s	
  and	
  don’t’s	
  
¡  Bash	
  for	
  Data	
  Processing	
  
¡  Git	
  
§  Merge	
  vs	
  rebase	
  
§  Git	
  flow	
  
>>>	
  import	
  antigravity	
  
	
  
>>>	
  import	
  this	
  
	
  
The	
  Zen	
  of	
  Python,	
  by	
  Tim	
  Peters	
  
	
  
Beautiful	
  is	
  better	
  than	
  ugly.	
  
Explicit	
  is	
  better	
  than	
  implicit.	
  
Simple	
  is	
  better	
  than	
  complex.	
  
Complex	
  is	
  better	
  than	
  complicated.	
  
Flat	
  is	
  better	
  than	
  nested.	
  
Sparse	
  is	
  better	
  than	
  dense.	
  
Readability	
  counts.	
  
Special	
  cases	
  aren't	
  special	
  enough	
  to	
  break	
  the	
  rules.	
  
Although	
  practicality	
  beats	
  purity.	
  
Errors	
  should	
  never	
  pass	
  silently.	
  
Unless	
  explicitly	
  silenced.	
  
In	
  the	
  face	
  of	
  ambiguity,	
  refuse	
  the	
  temptation	
  to	
  guess.	
  
There	
  should	
  be	
  one-­‐-­‐	
  and	
  preferably	
  only	
  one	
  -­‐-­‐obvious	
  way	
  to	
  do	
  it.	
  
Although	
  that	
  way	
  may	
  not	
  be	
  obvious	
  at	
  first	
  unless	
  you're	
  Dutch.	
  
Now	
  is	
  better	
  than	
  never.	
  
Although	
  never	
  is	
  often	
  better	
  than	
  *right*	
  now.	
  
If	
  the	
  implementation	
  is	
  hard	
  to	
  explain,	
  it's	
  a	
  bad	
  idea.	
  
If	
  the	
  implementation	
  is	
  easy	
  to	
  explain,	
  it	
  may	
  be	
  a	
  good	
  idea.	
  
Namespaces	
  are	
  one	
  honking	
  great	
  idea	
  -­‐-­‐	
  let's	
  do	
  more	
  of	
  those!	
  
There should be one
and preferably only one
obvious way to do it.
(Although that way may not be obvious at first unless you're Dutch.)
¡  PEP	
  8	
  defines	
  the	
  standard	
  coding	
  
convention	
  for	
  the	
  global	
  Python	
  community.	
  	
  
¡  It	
  does	
  not	
  leave	
  much	
  room	
  for	
  different	
  
code	
  conventions	
  
¡  Makes	
  code	
  more	
  readable	
  
¡  Gets	
  people	
  to	
  easily	
  go	
  in	
  and	
  out	
  of	
  code	
  
which	
  they	
  did	
  not	
  write	
  
¡  Easy,	
  just	
  use	
  PyCharm.	
  	
  
¡  It	
  will	
  emit	
  warnings	
  if	
  your	
  code	
  is	
  not	
  PEP	
  8	
  
compliant.	
  
Brogramming - Python, Bash for Data Processing, and Git
Brogramming - Python, Bash for Data Processing, and Git
Spaces.	
  (4	
  of	
  them)	
  
Yes:	
  
	
  
#	
  Aligned	
  with	
  opening	
  delimiter.	
  
foo	
  =	
  long_function_name(var_one,	
  var_two,	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  var_three,	
  var_four)	
  
Yes	
  (please	
  use	
  hanging	
  indents	
  at	
  Crosswise):	
  
	
  
#	
  More	
  indentation	
  included	
  to	
  distinguish	
  this	
  from	
  the	
  rest.	
  
def	
  long_function_name(	
  
	
  	
  	
  	
  	
  	
  	
  	
  var_one,	
  var_two,	
  var_three,	
  
	
  	
  	
  	
  	
  	
  	
  	
  var_four):	
  
	
  	
  	
  	
  print(var_one)	
  	
  
	
  
#	
  Hanging	
  indents	
  should	
  add	
  a	
  level.	
  
foo	
  =	
  long_function_name(	
  
	
  	
  	
  	
  var_one,	
  var_two,	
  
	
  	
  	
  	
  var_three,	
  var_four)	
  
	
  
	
  
	
  
No:	
  
#	
  Arguments	
  on	
  first	
  line	
  forbidden	
  when	
  not	
  using	
  vertical	
  alignment.	
  
foo	
  =	
  long_function_name(var_one,	
  var_two,	
  
	
  	
  	
  	
  var_three,	
  var_four)	
  
	
  
#	
  Further	
  indentation	
  required	
  as	
  indentation	
  is	
  not	
  distinguishable.	
  
def	
  long_function_name(	
  
	
  	
  	
  	
  var_one,	
  var_two,	
  var_three,	
  
	
  	
  	
  	
  var_four):	
  
	
  	
  	
  	
  print(var_one)	
  
This	
  is	
  OK:	
  
my_list	
  =	
  [	
  
	
  	
  	
  	
  1,	
  2,	
  3,	
  
	
  	
  	
  	
  4,	
  5,	
  6,	
  
	
  	
  	
  	
  ]	
  
	
  
result	
  =	
  some_function_that_takes_arguments(	
  
	
  	
  	
  	
  'a',	
  'b',	
  'c',	
  
	
  	
  	
  	
  'd',	
  'e',	
  'f',	
  
	
  	
  	
  	
  )	
  
	
  
This	
  is	
  OK	
  too	
  (use	
  this	
  at	
  Crosswise):	
  
my_list	
  =	
  [	
  
	
  	
  	
  	
  1,	
  2,	
  3,	
  
	
  	
  	
  	
  4,	
  5,	
  6,	
  
]	
  
	
  
result	
  =	
  some_function_that_takes_arguments(	
  
	
  	
  	
  	
  'a',	
  'b',	
  'c',	
  
	
  	
  	
  	
  'd',	
  'e',	
  'f',	
  
)	
  
¡  PEP	
  8	
  -­‐	
  79	
  characters.	
  
¡  But	
  it’s	
  too	
  short,	
  so	
  we	
  use	
  120	
  (PyCharm).	
  
¡  Top	
  level	
  functions	
  and	
  classes	
  –	
  2	
  blank	
  lines:	
  
	
  
Class	
  Foo(object):	
  
	
  	
  	
  	
  pass	
  
	
  
	
  
Class	
  Bar(object):	
  
	
  	
  	
  	
  pass	
  
¡  Method	
  definitions	
  inside	
  a	
  class,	
  1	
  blank	
  line	
  
	
  
Class	
  Foo(object):	
  
	
  	
  	
  	
  def	
  foo1(self):	
  
	
  	
  	
  	
  	
  	
  	
  	
  pass	
  
	
  
	
  	
  	
  	
  def	
  foo2(self):	
  
	
  	
  	
  	
  	
  	
  	
  	
  pass	
  
¡  Use	
  blank	
  lines	
  in	
  functions,	
  sparingly,	
  to	
  
indicate	
  logical	
  sections.	
  
	
  
#	
  do	
  something	
  
something	
  =	
  [x	
  for	
  x	
  in	
  list]	
  
	
  
#	
  now	
  do	
  something	
  different	
  
something_different	
  =	
  do_it(something)	
  
Yes:	
  
	
  
import	
  os	
  
import	
  sys	
  
	
  
No:	
  
	
  
import	
  os,	
  sys	
  
	
  
Yes:	
	
from	
  subprocess	
  import	
  Popen,	
  PIPE	
  
	
  
¡  PEP	
  8	
  recommends	
  absolute	
  imports,	
  so	
  use	
  
them.	
  	
  
¡  They	
  avoid	
  confusion	
  and	
  duplicate	
  imports.	
  
	
  
from	
  foo.bar.yourclass	
  import	
  YourClass	
  
¡  Immediately	
  inside	
  parentheses,	
  brackets	
  or	
  
braces.	
  
Yes:	
  
	
  
spam(ham[1],	
  {eggs:	
  2})	
  
	
  
No:	
  	
  
	
  
spam(	
  ham[	
  1	
  ],	
  {	
  eggs:	
  2	
  }	
  )	
  
¡  Immediately	
  before	
  a	
  comma,	
  semicolon,	
  or	
  
colon:	
  
Yes:	
  
	
  
if	
  x	
  ==	
  4:	
  print	
  x,	
  y;	
  x,	
  y	
  =	
  y,	
  x	
  
	
  
No:	
  	
  
	
  
if	
  x	
  ==	
  4	
  :	
  print	
  x	
  ,	
  y	
  ;	
  x	
  ,	
  y	
  =	
  y	
  ,	
  x	
  
¡  Immediately	
  before	
  the	
  open	
  parenthesis	
  that	
  
starts	
  the	
  argument	
  list	
  of	
  a	
  function	
  call:	
  
Yes:	
  	
  
	
  
spam(1)	
  
	
  
No:	
  	
  
	
  
spam	
  (1)	
  
¡  More	
  than	
  one	
  space	
  around	
  an	
  assignment	
  (or	
  other)	
  
operator	
  to	
  align	
  it	
  with	
  another.	
  
	
  
Yes:	
  
	
  
x	
  =	
  1	
  
y	
  =	
  2	
  
long_variable	
  =	
  3	
  
	
  
No:	
  	
  
	
  
x	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  =	
  1	
  
y	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  =	
  2	
  
long_variable	
  =	
  3	
  
¡  Immediately	
  before	
  the	
  open	
  parenthesis	
  
that	
  starts	
  an	
  indexing	
  or	
  slicing:	
  
	
  
Yes:	
  	
  
	
  
dict['key']	
  =	
  list[index]	
  
	
  
No:	
  	
  
	
  
dict	
  ['key']	
  =	
  list	
  [index]	
  
¡  Don't	
  use	
  spaces	
  around	
  the	
  =	
  sign	
  when	
  used	
  to	
  
indicate	
  a	
  keyword	
  argument	
  or	
  a	
  default	
  parameter	
  
value.	
  
	
  
Yes:	
  	
  
	
  
def	
  complex(real,	
  imag=0.0):	
  
	
  	
  	
  	
  return	
  magic(r=real,	
  i=imag)	
  
	
  
No:	
  	
  
	
  
def	
  complex(real,	
  imag	
  =	
  0.0):	
  
	
  	
  	
  	
  return	
  magic(r	
  =	
  real,	
  i	
  =	
  imag)	
  
¡  Use	
  inline	
  comments	
  sparingly.	
  
¡  Don’t	
  document	
  obvious	
  things	
  –	
  if	
  you	
  write	
  
Python	
  expressive	
  enough,	
  you	
  might	
  need	
  
even	
  need	
  documentation	
  at	
  all.	
  
	
  
¡  Use	
  list	
  comprehensions	
  instead	
  of	
  map	
  with	
  lambdas.	
  
¡  If	
  you	
  want	
  to	
  apply	
  a	
  function,	
  use	
  map.	
  
¡  Generally,	
  map	
  and	
  filter	
  are	
  less	
  readable.	
  
Yes:	
  
	
  
result	
  =	
  [x	
  +	
  1	
  for	
  x	
  in	
  xrange(10)	
  if	
  x	
  %	
  2	
  ==	
  0]	
  
	
  
No:	
  
	
  
result	
  =	
  filter(lambda	
  x:	
  x	
  %	
  2	
  ==	
  0,	
  map(	
  
	
  	
  	
  	
  lambda	
  x:	
  x	
  +	
  1,	
  xrange(10)))	
  
	
  
Yes:	
  
	
  
result	
  =	
  map(get_data,	
  items)	
  
	
  
¡  Python	
  Facts	
  –	
  a	
  website	
  I	
  wrote:	
  
§  http://thingsyoumust.appspot.com/	
  
¡  Quora	
  
§  http://www.quora.com/Python-­‐programming-­‐
language-­‐1/What-­‐are-­‐some-­‐cool-­‐Python-­‐tricks
	
  	
  
Brogramming - Python, Bash for Data Processing, and Git
¡  Pipe	
  contents	
  of	
  file	
  into	
  another	
  file	
  
cat	
  file.txt	
  >	
  newfile.txt	
  
cat	
  file1.txt	
  file2.txt	
  >	
  newfile.txt	
  
	
  
¡  Pipe	
  contents	
  of	
  a	
  compressed	
  file	
  
	
  
gzcat	
  file.txt.gz	
  >	
  newfile.txt	
  
	
  
¡  Pipe	
  contents	
  of	
  a	
  compressed	
  file	
  and	
  write	
  it	
  to	
  a	
  
compressed	
  file	
  
	
  
gzcat	
  file.txt.gz	
  |	
  gzip	
  >	
  newfile.txt.gz	
  
	
  
echo	
  "1t2t3"	
  |	
  cut	
  -­‐f	
  2	
  
2	
  
	
  
echo	
  "1,2,3"	
  |	
  cut	
  -­‐f	
  2	
  -­‐d","	
  
2	
  
	
  
¡  awk	
  is	
  a	
  mini	
  programming	
  language	
  which	
  is	
  
very	
  convenient	
  mostly	
  for	
  outputting	
  a	
  
column/line	
  according	
  to	
  a	
  different	
  condition	
  
	
  
echo	
  "1t2t3n4t5t6t"	
  |	
  	
  
awk	
  '{	
  if	
  ($1	
  %	
  2	
  ==	
  0)	
  print	
  $2	
  }'	
  
5	
  
	
  
¡  awk	
  can	
  also	
  do	
  cool	
  stuff	
  like	
  sampling	
  a	
  file.	
  
	
  
echo	
  "1n2n3n4n5n6"	
  |	
  	
  
awk	
  'BEGIN	
  {srand()}	
  {if	
  (rand()	
  <	
  0.1)	
  print	
  $0}'	
  
	
  
	
  
echo	
  "2n1n3n10"	
  |	
  sort	
  
1	
  
10	
  
2	
  
3	
  
	
  
echo	
  "2n1n3n10"	
  |	
  sort	
  -­‐n	
  
1	
  
2	
  
3	
  
10	
  
¡  uniq	
  returns	
  unique	
  values,	
  assuming	
  the	
  input	
  is	
  sorted.	
  	
  
echo	
  "1n2n1"	
  |	
  uniq	
  
1	
  
2	
  
1	
  
	
  
echo	
  "1n2n1"	
  |	
  sort	
  |	
  uniq	
  
1	
  
2	
  
	
  
¡  uniq	
  also	
  knows	
  to	
  return	
  value	
  counts	
  for	
  each	
  value	
  using	
  –c.	
  
	
  
echo	
  "anbna"	
  |	
  sort	
  |	
  uniq	
  -­‐c	
  
	
  	
  	
  2	
  a	
  
	
  	
  	
  1	
  b	
  
	
  
	
  
echo	
  "a	
  b	
  cn1	
  2	
  3"	
  |	
  wc	
  -­‐l	
  
	
  	
  	
  	
  	
  	
  	
  2	
  
	
  
echo	
  "a	
  b	
  cn1	
  2	
  3"	
  |	
  wc	
  -­‐w	
  
	
  	
  	
  	
  	
  	
  	
  6	
  
¡  Counting	
  unique	
  values	
  in	
  a	
  column:	
  
	
  
cat	
  foo.txt	
  |	
  cut	
  –f	
  2	
  |	
  sort	
  |	
  uniq	
  |	
  wc	
  –l	
  
	
  
¡  Showing	
  the	
  value	
  counts	
  	
  
cat	
  foo.txt	
  |	
  cut	
  –f	
  2	
  |	
  sort	
  |	
  uniq	
  -­‐c	
  
	
  
¡  Git	
  is	
  a	
  distributed	
  version	
  control	
  system	
  
(DVCS)	
  
¡  Written	
  by	
  Linus	
  Torvalds,	
  the	
  author	
  of	
  
Linux,	
  in	
  order	
  to	
  maintain	
  the	
  open	
  source	
  
project	
  
 
	
  
	
  
	
  
Merge	
  
	
  
	
  
Rebase	
  
	
  
¡  Advantages	
  of	
  rebase	
  over	
  merge:	
  
§  Simplifies	
  history	
  –	
  merge	
  commits	
  are	
  ugly	
  
because	
  they	
  have	
  two	
  parents	
  
§  Each	
  commit	
  is	
  an	
  addition	
  over	
  the	
  existing	
  code	
  
¡  Advantages	
  of	
  merge	
  over	
  rebase:	
  
§  Preserves	
  the	
  commits	
  as	
  they	
  were	
  in	
  the	
  
developer’s	
  computer	
  
¡  HOWTO	
  	
  
	
  
http://danielkummer.github.io/git-­‐flow-­‐cheatsheet/	
  
http://nvie.com/posts/a-­‐successful-­‐git-­‐branching-­‐model/	
  
	
  
¡  Install	
  
	
  
brew	
  install	
  git-­‐flow-­‐avh	
  
	
  
	
  
¡  Git	
  flow	
  defines	
  a	
  universal	
  standard	
  for	
  
developing	
  features	
  and	
  maintaining	
  releases	
  
over	
  git.	
  
¡  There	
  are	
  3	
  commands	
  in	
  git	
  flow:	
  
§  feature	
  –	
  for	
  implementing	
  new	
  features	
  
§  release	
  –	
  for	
  adjusting	
  the	
  release	
  according	
  to	
  
feedback	
  from	
  QA	
  and	
  such	
  
§  hotfix	
  –	
  for	
  creating	
  a	
  new	
  release	
  on	
  top	
  of	
  a	
  
previous	
  release	
  
¡  Features	
  are	
  branched	
  in	
  and	
  out	
  of	
  develop	
  
¡  Releases	
  are	
  branched	
  in	
  and	
  out	
  of	
  develop	
  
and	
  master	
  
¡  Hotfixes	
  are	
  branched	
  in	
  and	
  out	
  of	
  master	
  
	
  
¡  There	
  are	
  3	
  operations:	
  
§  start	
  –	
  start	
  a	
  feature/release/hotfix	
  by	
  branching	
  
out	
  
§  publish	
  –	
  push	
  to	
  the	
  remote	
  repository	
  
§  finish	
  –	
  Merge	
  back	
  and	
  remove	
  the	
  branch	
  
▪  When	
  finishing,	
  please	
  use	
  the	
  -­‐r	
  feature	
  to	
  rebase	
  the	
  
changes	
  back	
  instead	
  of	
  merging	
  them,	
  so	
  we	
  would	
  
have	
  a	
  cleaner	
  history	
  to	
  look	
  at.	
  

More Related Content

What's hot (20)

PPT
Introduction to Python - Part Two
amiable_indian
 
PPSX
Programming with Python
Rasan Samarasinghe
 
PPTX
Grep - A powerful search utility
Nirajan Pant
 
PDF
Real World Haskell: Lecture 1
Bryan O'Sullivan
 
PDF
Python basic
Saifuddin Kaijar
 
PPT
Python scripting kick off
Andrea Gangemi
 
ODP
Introduction to Python - Training for Kids
Aimee Maree
 
PDF
Python Loop
Soba Arjun
 
PDF
Let’s Learn Python An introduction to Python
Jaganadh Gopinadhan
 
PPT
Regular Expressions grep and egrep
Tri Truong
 
DOCX
15 practical grep command examples in linux
Teja Bheemanapally
 
PDF
Python If Else | If Else Statement In Python | Edureka
Edureka!
 
PDF
Python revision tour i
Mr. Vikram Singh Slathia
 
DOCX
Learning Grep
Vikas Kumar CSM®
 
PPTX
Lexing and parsing
Elizabeth Smith
 
PDF
Ry pyconjp2015 turtle
Renyuan Lyu
 
PDF
Python revision tour II
Mr. Vikram Singh Slathia
 
PDF
Introduction to Python Pandas for Data Analytics
Phoenix
 
PDF
Matlab python-
Dr. Volkan OBAN
 
Introduction to Python - Part Two
amiable_indian
 
Programming with Python
Rasan Samarasinghe
 
Grep - A powerful search utility
Nirajan Pant
 
Real World Haskell: Lecture 1
Bryan O'Sullivan
 
Python basic
Saifuddin Kaijar
 
Python scripting kick off
Andrea Gangemi
 
Introduction to Python - Training for Kids
Aimee Maree
 
Python Loop
Soba Arjun
 
Let’s Learn Python An introduction to Python
Jaganadh Gopinadhan
 
Regular Expressions grep and egrep
Tri Truong
 
15 practical grep command examples in linux
Teja Bheemanapally
 
Python If Else | If Else Statement In Python | Edureka
Edureka!
 
Python revision tour i
Mr. Vikram Singh Slathia
 
Learning Grep
Vikas Kumar CSM®
 
Lexing and parsing
Elizabeth Smith
 
Ry pyconjp2015 turtle
Renyuan Lyu
 
Python revision tour II
Mr. Vikram Singh Slathia
 
Introduction to Python Pandas for Data Analytics
Phoenix
 
Matlab python-
Dr. Volkan OBAN
 

Viewers also liked (10)

PDF
Bootstrap 3 - Sleek, intuitive, and powerful mobile first front-end framework...
Cedric Spillebeen
 
PPTX
Bootstrap ppt
Ishtdeep Hora
 
PDF
Introduction to Bootstrap
Ron Reiter
 
PDF
HTML5 New Features and Resources
Ron Reiter
 
PDF
Wordpress Underscores & foundation5
Aum Watcharapol
 
PDF
Bootstrap 3 สำหรับมือใหม่ | CloudCourse.io
Thapwaris Chinsirirathkul
 
PDF
แนะนำ HTML5 แบบอ่านจบต้องรู้บ้างแหละ
Withoon Wangsa-Nguankit
 
PDF
การสร้างเว็บด้วย Bootstrap framework
สอนทำโปรเจคจบ วิทคอมไอทีคอมธุรกิจ
 
PPTX
Responsive web-design through bootstrap
Zunair Sagitarioux
 
PDF
Bootstrap 3 Basic - Bangkok WordPress Meetup
Woratana Perth Ngarmtrakulchol
 
Bootstrap 3 - Sleek, intuitive, and powerful mobile first front-end framework...
Cedric Spillebeen
 
Bootstrap ppt
Ishtdeep Hora
 
Introduction to Bootstrap
Ron Reiter
 
HTML5 New Features and Resources
Ron Reiter
 
Wordpress Underscores & foundation5
Aum Watcharapol
 
Bootstrap 3 สำหรับมือใหม่ | CloudCourse.io
Thapwaris Chinsirirathkul
 
แนะนำ HTML5 แบบอ่านจบต้องรู้บ้างแหละ
Withoon Wangsa-Nguankit
 
การสร้างเว็บด้วย Bootstrap framework
สอนทำโปรเจคจบ วิทคอมไอทีคอมธุรกิจ
 
Responsive web-design through bootstrap
Zunair Sagitarioux
 
Bootstrap 3 Basic - Bangkok WordPress Meetup
Woratana Perth Ngarmtrakulchol
 
Ad

Similar to Brogramming - Python, Bash for Data Processing, and Git (20)

PPTX
Code Like Pythonista
Chiyoung Song
 
PDF
Python Style Guide
Jiayun Zhou
 
PDF
Code with style
Clayton Parker
 
PDF
Ruby Gotchas
Dave Aronson
 
PDF
Code with Style - PyOhio
Clayton Parker
 
PDF
Theperlreview
Casiano Rodriguez-leon
 
ODP
Python quickstart for programmers: Python Kung Fu
climatewarrior
 
PPTX
Basic of Python- Hands on Session
Dharmesh Tank
 
PPT
Plunging Into Perl While Avoiding the Deep End (mostly)
Roy Zimmer
 
PDF
Mario Fusco - Lazy Java - Codemotion Milan 2018
Codemotion
 
PDF
Lazy Java
J On The Beach
 
PDF
Lazy Java
Nicola Pedot
 
PDF
Lazy java
Mario Fusco
 
PPT
C Tutorials
Sudharsan S
 
PPT
ppt3-conditionalstatementloopsdictionaryfunctions-240731050730-455ba0fa.ppt
avishekpradhan24
 
PPT
PPT3-CONDITIONAL STATEMENT LOOPS DICTIONARY FUNCTIONS.ppt
RahulKumar812056
 
PDF
Presentation pythonpppppppppppppppppppppppppppppppppyyyyyyyyyyyyyyyyyyytttttt...
manikbuma
 
PPTX
Improve Your Edge on Machine Learning - Day 1.pptx
CatherineVania1
 
PPTX
Functions, List and String methods
PranavSB
 
DOCX
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
priestmanmable
 
Code Like Pythonista
Chiyoung Song
 
Python Style Guide
Jiayun Zhou
 
Code with style
Clayton Parker
 
Ruby Gotchas
Dave Aronson
 
Code with Style - PyOhio
Clayton Parker
 
Theperlreview
Casiano Rodriguez-leon
 
Python quickstart for programmers: Python Kung Fu
climatewarrior
 
Basic of Python- Hands on Session
Dharmesh Tank
 
Plunging Into Perl While Avoiding the Deep End (mostly)
Roy Zimmer
 
Mario Fusco - Lazy Java - Codemotion Milan 2018
Codemotion
 
Lazy Java
J On The Beach
 
Lazy Java
Nicola Pedot
 
Lazy java
Mario Fusco
 
C Tutorials
Sudharsan S
 
ppt3-conditionalstatementloopsdictionaryfunctions-240731050730-455ba0fa.ppt
avishekpradhan24
 
PPT3-CONDITIONAL STATEMENT LOOPS DICTIONARY FUNCTIONS.ppt
RahulKumar812056
 
Presentation pythonpppppppppppppppppppppppppppppppppyyyyyyyyyyyyyyyyyyytttttt...
manikbuma
 
Improve Your Edge on Machine Learning - Day 1.pptx
CatherineVania1
 
Functions, List and String methods
PranavSB
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
priestmanmable
 
Ad

More from Ron Reiter (9)

PDF
Securing your Bitcoin wallet
Ron Reiter
 
PDF
BDX 2015 - Scaling out big-data computation & machine learning using Pig, Pyt...
Ron Reiter
 
PDF
jQuery Mobile Workshop
Ron Reiter
 
PDF
Multi screen HTML5
Ron Reiter
 
PDF
Mobile Spaces
Ron Reiter
 
PDF
Building Chrome Extensions
Ron Reiter
 
PDF
Introduction to App Engine Development
Ron Reiter
 
PPTX
Digital Audio & Signal Processing (Elad Gariany)
Ron Reiter
 
PPTX
Writing HTML5 Web Apps using Backbone.js and GAE
Ron Reiter
 
Securing your Bitcoin wallet
Ron Reiter
 
BDX 2015 - Scaling out big-data computation & machine learning using Pig, Pyt...
Ron Reiter
 
jQuery Mobile Workshop
Ron Reiter
 
Multi screen HTML5
Ron Reiter
 
Mobile Spaces
Ron Reiter
 
Building Chrome Extensions
Ron Reiter
 
Introduction to App Engine Development
Ron Reiter
 
Digital Audio & Signal Processing (Elad Gariany)
Ron Reiter
 
Writing HTML5 Web Apps using Backbone.js and GAE
Ron Reiter
 

Recently uploaded (20)

PDF
Zero carbon Building Design Guidelines V4
BassemOsman1
 
PPTX
ENSA_Module_7.pptx_wide_area_network_concepts
RanaMukherjee24
 
PPTX
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
PDF
STUDY OF NOVEL CHANNEL MATERIALS USING III-V COMPOUNDS WITH VARIOUS GATE DIEL...
ijoejnl
 
PPTX
quantum computing transition from classical mechanics.pptx
gvlbcy
 
PDF
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
PPTX
Information Retrieval and Extraction - Module 7
premSankar19
 
PDF
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
PPTX
Inventory management chapter in automation and robotics.
atisht0104
 
PDF
Air -Powered Car PPT by ER. SHRESTH SUDHIR KOKNE.pdf
SHRESTHKOKNE
 
PPTX
Ground improvement techniques-DEWATERING
DivakarSai4
 
PDF
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
PDF
AI-Driven IoT-Enabled UAV Inspection Framework for Predictive Maintenance and...
ijcncjournal019
 
PDF
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
PPTX
FUNDAMENTALS OF ELECTRIC VEHICLES UNIT-1
MikkiliSuresh
 
PPTX
Water resources Engineering GIS KRT.pptx
Krunal Thanki
 
PPTX
Introduction to Fluid and Thermal Engineering
Avesahemad Husainy
 
PDF
All chapters of Strength of materials.ppt
girmabiniyam1234
 
PDF
CAD-CAM U-1 Combined Notes_57761226_2025_04_22_14_40.pdf
shailendrapratap2002
 
PDF
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
Zero carbon Building Design Guidelines V4
BassemOsman1
 
ENSA_Module_7.pptx_wide_area_network_concepts
RanaMukherjee24
 
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
STUDY OF NOVEL CHANNEL MATERIALS USING III-V COMPOUNDS WITH VARIOUS GATE DIEL...
ijoejnl
 
quantum computing transition from classical mechanics.pptx
gvlbcy
 
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
Information Retrieval and Extraction - Module 7
premSankar19
 
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
Inventory management chapter in automation and robotics.
atisht0104
 
Air -Powered Car PPT by ER. SHRESTH SUDHIR KOKNE.pdf
SHRESTHKOKNE
 
Ground improvement techniques-DEWATERING
DivakarSai4
 
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
AI-Driven IoT-Enabled UAV Inspection Framework for Predictive Maintenance and...
ijcncjournal019
 
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
FUNDAMENTALS OF ELECTRIC VEHICLES UNIT-1
MikkiliSuresh
 
Water resources Engineering GIS KRT.pptx
Krunal Thanki
 
Introduction to Fluid and Thermal Engineering
Avesahemad Husainy
 
All chapters of Strength of materials.ppt
girmabiniyam1234
 
CAD-CAM U-1 Combined Notes_57761226_2025_04_22_14_40.pdf
shailendrapratap2002
 
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 

Brogramming - Python, Bash for Data Processing, and Git

  • 3. ¡  Python   §  The  Zen  of  Python   §  Conventions  and  PEP8   §  Tips  &  Tricks,  Do’s  and  don’t’s   ¡  Bash  for  Data  Processing   ¡  Git   §  Merge  vs  rebase   §  Git  flow  
  • 5. >>>  import  this     The  Zen  of  Python,  by  Tim  Peters     Beautiful  is  better  than  ugly.   Explicit  is  better  than  implicit.   Simple  is  better  than  complex.   Complex  is  better  than  complicated.   Flat  is  better  than  nested.   Sparse  is  better  than  dense.   Readability  counts.   Special  cases  aren't  special  enough  to  break  the  rules.   Although  practicality  beats  purity.   Errors  should  never  pass  silently.   Unless  explicitly  silenced.   In  the  face  of  ambiguity,  refuse  the  temptation  to  guess.   There  should  be  one-­‐-­‐  and  preferably  only  one  -­‐-­‐obvious  way  to  do  it.   Although  that  way  may  not  be  obvious  at  first  unless  you're  Dutch.   Now  is  better  than  never.   Although  never  is  often  better  than  *right*  now.   If  the  implementation  is  hard  to  explain,  it's  a  bad  idea.   If  the  implementation  is  easy  to  explain,  it  may  be  a  good  idea.   Namespaces  are  one  honking  great  idea  -­‐-­‐  let's  do  more  of  those!  
  • 6. There should be one and preferably only one obvious way to do it. (Although that way may not be obvious at first unless you're Dutch.)
  • 7. ¡  PEP  8  defines  the  standard  coding   convention  for  the  global  Python  community.     ¡  It  does  not  leave  much  room  for  different   code  conventions   ¡  Makes  code  more  readable   ¡  Gets  people  to  easily  go  in  and  out  of  code   which  they  did  not  write  
  • 8. ¡  Easy,  just  use  PyCharm.     ¡  It  will  emit  warnings  if  your  code  is  not  PEP  8   compliant.  
  • 11. Spaces.  (4  of  them)  
  • 12. Yes:     #  Aligned  with  opening  delimiter.   foo  =  long_function_name(var_one,  var_two,                                                    var_three,  var_four)  
  • 13. Yes  (please  use  hanging  indents  at  Crosswise):     #  More  indentation  included  to  distinguish  this  from  the  rest.   def  long_function_name(                  var_one,  var_two,  var_three,                  var_four):          print(var_one)       #  Hanging  indents  should  add  a  level.   foo  =  long_function_name(          var_one,  var_two,          var_three,  var_four)        
  • 14. No:   #  Arguments  on  first  line  forbidden  when  not  using  vertical  alignment.   foo  =  long_function_name(var_one,  var_two,          var_three,  var_four)     #  Further  indentation  required  as  indentation  is  not  distinguishable.   def  long_function_name(          var_one,  var_two,  var_three,          var_four):          print(var_one)  
  • 15. This  is  OK:   my_list  =  [          1,  2,  3,          4,  5,  6,          ]     result  =  some_function_that_takes_arguments(          'a',  'b',  'c',          'd',  'e',  'f',          )     This  is  OK  too  (use  this  at  Crosswise):   my_list  =  [          1,  2,  3,          4,  5,  6,   ]     result  =  some_function_that_takes_arguments(          'a',  'b',  'c',          'd',  'e',  'f',   )  
  • 16. ¡  PEP  8  -­‐  79  characters.   ¡  But  it’s  too  short,  so  we  use  120  (PyCharm).  
  • 17. ¡  Top  level  functions  and  classes  –  2  blank  lines:     Class  Foo(object):          pass       Class  Bar(object):          pass  
  • 18. ¡  Method  definitions  inside  a  class,  1  blank  line     Class  Foo(object):          def  foo1(self):                  pass            def  foo2(self):                  pass  
  • 19. ¡  Use  blank  lines  in  functions,  sparingly,  to   indicate  logical  sections.     #  do  something   something  =  [x  for  x  in  list]     #  now  do  something  different   something_different  =  do_it(something)  
  • 20. Yes:     import  os   import  sys     No:     import  os,  sys     Yes: from  subprocess  import  Popen,  PIPE    
  • 21. ¡  PEP  8  recommends  absolute  imports,  so  use   them.     ¡  They  avoid  confusion  and  duplicate  imports.     from  foo.bar.yourclass  import  YourClass  
  • 22. ¡  Immediately  inside  parentheses,  brackets  or   braces.   Yes:     spam(ham[1],  {eggs:  2})     No:       spam(  ham[  1  ],  {  eggs:  2  }  )  
  • 23. ¡  Immediately  before  a  comma,  semicolon,  or   colon:   Yes:     if  x  ==  4:  print  x,  y;  x,  y  =  y,  x     No:       if  x  ==  4  :  print  x  ,  y  ;  x  ,  y  =  y  ,  x  
  • 24. ¡  Immediately  before  the  open  parenthesis  that   starts  the  argument  list  of  a  function  call:   Yes:       spam(1)     No:       spam  (1)  
  • 25. ¡  More  than  one  space  around  an  assignment  (or  other)   operator  to  align  it  with  another.     Yes:     x  =  1   y  =  2   long_variable  =  3     No:       x                          =  1   y                          =  2   long_variable  =  3  
  • 26. ¡  Immediately  before  the  open  parenthesis   that  starts  an  indexing  or  slicing:     Yes:       dict['key']  =  list[index]     No:       dict  ['key']  =  list  [index]  
  • 27. ¡  Don't  use  spaces  around  the  =  sign  when  used  to   indicate  a  keyword  argument  or  a  default  parameter   value.     Yes:       def  complex(real,  imag=0.0):          return  magic(r=real,  i=imag)     No:       def  complex(real,  imag  =  0.0):          return  magic(r  =  real,  i  =  imag)  
  • 28. ¡  Use  inline  comments  sparingly.   ¡  Don’t  document  obvious  things  –  if  you  write   Python  expressive  enough,  you  might  need   even  need  documentation  at  all.    
  • 29. ¡  Use  list  comprehensions  instead  of  map  with  lambdas.   ¡  If  you  want  to  apply  a  function,  use  map.   ¡  Generally,  map  and  filter  are  less  readable.   Yes:     result  =  [x  +  1  for  x  in  xrange(10)  if  x  %  2  ==  0]     No:     result  =  filter(lambda  x:  x  %  2  ==  0,  map(          lambda  x:  x  +  1,  xrange(10)))     Yes:     result  =  map(get_data,  items)    
  • 30. ¡  Python  Facts  –  a  website  I  wrote:   §  http://thingsyoumust.appspot.com/   ¡  Quora   §  http://www.quora.com/Python-­‐programming-­‐ language-­‐1/What-­‐are-­‐some-­‐cool-­‐Python-­‐tricks    
  • 32. ¡  Pipe  contents  of  file  into  another  file   cat  file.txt  >  newfile.txt   cat  file1.txt  file2.txt  >  newfile.txt     ¡  Pipe  contents  of  a  compressed  file     gzcat  file.txt.gz  >  newfile.txt     ¡  Pipe  contents  of  a  compressed  file  and  write  it  to  a   compressed  file     gzcat  file.txt.gz  |  gzip  >  newfile.txt.gz    
  • 33. echo  "1t2t3"  |  cut  -­‐f  2   2     echo  "1,2,3"  |  cut  -­‐f  2  -­‐d","   2    
  • 34. ¡  awk  is  a  mini  programming  language  which  is   very  convenient  mostly  for  outputting  a   column/line  according  to  a  different  condition     echo  "1t2t3n4t5t6t"  |     awk  '{  if  ($1  %  2  ==  0)  print  $2  }'   5    
  • 35. ¡  awk  can  also  do  cool  stuff  like  sampling  a  file.     echo  "1n2n3n4n5n6"  |     awk  'BEGIN  {srand()}  {if  (rand()  <  0.1)  print  $0}'      
  • 36. echo  "2n1n3n10"  |  sort   1   10   2   3     echo  "2n1n3n10"  |  sort  -­‐n   1   2   3   10  
  • 37. ¡  uniq  returns  unique  values,  assuming  the  input  is  sorted.     echo  "1n2n1"  |  uniq   1   2   1     echo  "1n2n1"  |  sort  |  uniq   1   2     ¡  uniq  also  knows  to  return  value  counts  for  each  value  using  –c.     echo  "anbna"  |  sort  |  uniq  -­‐c        2  a        1  b      
  • 38. echo  "a  b  cn1  2  3"  |  wc  -­‐l                2     echo  "a  b  cn1  2  3"  |  wc  -­‐w                6  
  • 39. ¡  Counting  unique  values  in  a  column:     cat  foo.txt  |  cut  –f  2  |  sort  |  uniq  |  wc  –l     ¡  Showing  the  value  counts     cat  foo.txt  |  cut  –f  2  |  sort  |  uniq  -­‐c    
  • 40. ¡  Git  is  a  distributed  version  control  system   (DVCS)   ¡  Written  by  Linus  Torvalds,  the  author  of   Linux,  in  order  to  maintain  the  open  source   project  
  • 41.         Merge       Rebase    
  • 42. ¡  Advantages  of  rebase  over  merge:   §  Simplifies  history  –  merge  commits  are  ugly   because  they  have  two  parents   §  Each  commit  is  an  addition  over  the  existing  code   ¡  Advantages  of  merge  over  rebase:   §  Preserves  the  commits  as  they  were  in  the   developer’s  computer  
  • 43. ¡  HOWTO       http://danielkummer.github.io/git-­‐flow-­‐cheatsheet/   http://nvie.com/posts/a-­‐successful-­‐git-­‐branching-­‐model/     ¡  Install     brew  install  git-­‐flow-­‐avh      
  • 44. ¡  Git  flow  defines  a  universal  standard  for   developing  features  and  maintaining  releases   over  git.   ¡  There  are  3  commands  in  git  flow:   §  feature  –  for  implementing  new  features   §  release  –  for  adjusting  the  release  according  to   feedback  from  QA  and  such   §  hotfix  –  for  creating  a  new  release  on  top  of  a   previous  release  
  • 45. ¡  Features  are  branched  in  and  out  of  develop   ¡  Releases  are  branched  in  and  out  of  develop   and  master   ¡  Hotfixes  are  branched  in  and  out  of  master    
  • 46. ¡  There  are  3  operations:   §  start  –  start  a  feature/release/hotfix  by  branching   out   §  publish  –  push  to  the  remote  repository   §  finish  –  Merge  back  and  remove  the  branch   ▪  When  finishing,  please  use  the  -­‐r  feature  to  rebase  the   changes  back  instead  of  merging  them,  so  we  would   have  a  cleaner  history  to  look  at.