Skip to content

Instantly share code, notes, and snippets.

@pratikmallya
pratikmallya / bobp-python.md
Created August 30, 2016 00:40 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@pratikmallya
pratikmallya / CreateJob.sh
Created August 29, 2016 19:53 — forked from stuart-warren/CreateJob.sh
Create a job in Jenkins (or folder) using the HTTP API
# check if job exists
curl -XGET 'http://jenkins/checkJobName?value=yourJobFolderName' --user user.name:YourAPIToken
# with folder plugin
curl -s -XPOST 'http://jenkins/job/FolderName/createItem?name=yourJobName' --data-binary @config.xml -H "Content-Type:text/xml" --user user.name:YourAPIToken
# without folder plugin
curl -s -XPOST 'http://jenkins/createItem?name=yourJobName' --data-binary @config.xml -H "Content-Type:text/xml" --user user.name:YourAPIToken
# create folder
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
@pratikmallya
pratikmallya / comprehensions.md
Created March 28, 2016 12:57 — forked from bearfrieze/comprehensions.md
Comprehensions in Python the Jedi way

Comprehensions in Python the Jedi way

Beautiful is better than ugly. Explicit is better than implicit.

-- The Zen of Python

I frequently deal with collections of things in the programs I write. Collections of droids, jedis, planets, lightsabers, starfighters, etc. When programming in Python, these collections of things are usually represented as lists, sets and dictionaries. Oftentimes, what I want to do with collections is to transform them in various ways. Comprehensions is a powerful syntax for doing just that. I use them extensively, and it's one of the things that keep me coming back to Python. Let me show you a few examples of the incredible usefulness of comprehensions.

All of the tasks presented in the examples can be accomplished with the extensive standard library available in Python. These solutions would arguably be more terse and efficient in some cases. I don't have anything against the standard library. To me there is a certain

heat_template_version: '2013-05-23'
outputs:
public_ip:
description: public IP address of the deployed compute instance
value:
get_attr: [compute_instance, accessIPv4]
parameters:
count: {default: 1, type: number}
flavor: {default: 512MB Standard Instance, type: string}
image: {default: 7fd88211-ce43-41bf-9a85-e73df4066581, type: string}
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
@pratikmallya
pratikmallya / bytesFilter.coffee
Last active August 29, 2015 14:02 — forked from thomseddon/gist:3511330
CoffeeScript Bytes Formatter
app.filter 'displayBytes', () ->
return (bytes, precision) ->
if isNaN(parseFloat(bytes)) || !isFinite(bytes))
return '-'
if typeof precision == 'undefined'
precision = 1
units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB']
number = Math.floor(Math.log(bytes) / Math.log(1024))
return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number]
1. Two space soft indents (fake tabs) OR tabs... BUT NEVER BOTH - DO NOT MIX
2. Whitespace, Parens, Braces, Linebreaks
if/else/for/while/try always have spaces, braces and multiple lines.
--------------------------------------------------------------------
ffprobe -v quiet -print_format json -show_format -show_streams "lolwut.mp4" > "lolwut.mp4.json"
1. Two space soft indents (fake tabs) OR tabs... BUT NEVER BOTH - DO NOT MIX
2. Whitespace, Parens, Braces, Linebreaks
if/else/for/while/try always have spaces, braces and multiple lines.
--------------------------------------------------------------------