Skip to content

Instantly share code, notes, and snippets.

#!/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: 2014-10-16
description: |
Test template for AWS supported resources
parameters:
resources:
#ssh_key:
# type: OS::Nova::KeyPair
heat_template_version: 2014-10-16
parameters:
flavor:
type: string
description: Flavor for the server to be created
default: 4353
hidden: true
resources:
test_server:
type: "OS::Heat::None"
#cloud-config
write_files:
- path: /root/hello-world.txt
content: |
#!/bin/bash
username=XXXXXX
APIkey=XXXXXX
dc=hkg
container=dn-container
file=xyz.tar.gz
heat_template_version: 2014-10-16
description: |
Creating Rackspace cloud server with user_data.
resources:
test_server:
type: "OS::Nova::Server"
properties:
name: test-server
heat_template_version: 2014-10-16
description: |
Creating Rackspace cloud server with user_data.
resources:
test_server:
type: "OS::Nova::Server"
properties:
name: test-server
@pratikmallya
pratikmallya / format_test.go
Last active September 18, 2015 01:12
Simple test which fails if code is not in the go format. Include this code in your package and code contributions will fail if not submitted with the correct format.
// include package name here
import (
"bytes"
"fmt"
"os/exec"
"testing"
)
func TestCodeFormattedCorrectly(t *testing.T) {
heat_template_version: 2014-10-16
description: |
Single node linux server with swift signaling.
resources:
signal_handle:
type: "OS::Heat::SwiftSignalHandle"
linux_server:
heat_template_version: 2013-05-23
parameters:
count:
type: number
default: 4
description: number of servers
resources:
rg:
type: OS::Heat::ResourceGroup