Skip to content

Instantly share code, notes, and snippets.

def triangles(level):
"""
Pirnt triagle for the levelth
"""
gles = [[0 for col in range(0, level)] for row in range(0, level)]
for row in range(0, level):
if row == 0:
gles[row][0] = 1
else:
for col in range(0, level):
@a3linux
a3linux / role_arn_to_session.py
Created April 11, 2018 08:09 — forked from gene1wood/role_arn_to_session.py
Simple python function to assume an AWS IAM Role from a role ARN and return a boto3 session object
import boto3
def role_arn_to_session(**args):
"""
Usage :
session = role_arn_to_session(
RoleArn='arn:aws:iam::012345678901:role/example-role',
RoleSessionName='ExampleSessionName')
client = session.client('sqs')
"""
AWSTemplateFormatVersion: '2010-09-09'
Resources:
LambdaRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
@a3linux
a3linux / ec2-ami-region-map.py
Created January 31, 2018 06:13 — forked from pacohope/ec2-ami-region-map.py
Given a starting public AWS AMI, generate a YAML list of AMI IDs for that AMI in all AWS regions.
#
# Given the ID of an Amazon public AMI in one region, figure out what the
# equivalent AMI IDs are for that same AMI in all other regions known.
# If that AMI isn't defined in a region, it prints the region's name, but
# comments it out.
#
from __future__ import print_function
import boto3
To get both the process output and the returned code:
from subprocess import Popen, PIPE
p = Popen(["ls", "non existent"], stdout=PIPE)
output = p.communicate()[0]
print(p.returncode)
subprocess.CalledProcessError is a class. To access returncode use the exception instance:
from subprocess import CalledProcessError, check_output
def md5(fname):
hash_md5 = hashlib.md5()
with open(fname, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
也忆江南
江南春色能断肠
烟雨空蒙应惆怅
落英缤纷惜华年
杨花扑面思故乡
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@a3linux
a3linux / .jsbeautifyrc
Created March 23, 2017 08:36 — forked from softwarespot/.jsbeautifyrc
JS Beautifier configuration
// Documentation: https://github.com/beautify-web/js-beautify
// Example URL: https://github.com/victorporof/Sublime-HTMLPrettify/blob/master/.jsbeautifyrc
// Based on Airbnb's JavaScript Style Guide, URL: https://github.com/airbnb/javascript
{
// Collapse curly brackets
"brace_style": "collapse",
// Break chained method calls across subsequent lines
"break_chained_methods": true,
@a3linux
a3linux / gist:4d0ab1cf13d11fcf0f96281a47692e8f
Created November 3, 2016 01:35 — forked from rhelmer/gist:d3d99bd60e81be10f759
quick sync setup runner for symbols
#!/bin/bash
set -e
. /home/socorro/.virtualenvs/aws/bin/activate
PRIVATE_BUCKET="org.mozilla.crash-stats.symbols-private/v1"
PUBLIC_BUCKET="org.mozilla.crash-stats.symbols-public/v1"
TOP_DIR="/mnt/socorro/symbols"
PRIVATE_DIRS="symbols_adobe"