Skip to content

Instantly share code, notes, and snippets.

View a3linux's full-sized avatar

Allen Chen Jinlong a3linux

View GitHub Profile
from time import strftime,gmtime,time
import urllib2
import hmac
import hashlib
import base64
import string
def publishAmazonSnsMsg(Subject,TopicArn,Message,AWSAccessKeyId,privatekey):
#http://docs.amazonwebservices.com/AWSSimpleQueueService/2008-01-01/SQSDeveloperGuide/
amzsnshost = 'sns.us-east-1.amazonaws.com'
# -*- coding: utf-8 -*-
import signal
import boto.sns
def timeout(limit, topic, subject='Execution Timeout.', body='Please check program.', region='us-east-1'):
'''
使い方:指定した実行時間に終了しなかった場合、awsのsnsで通知するデコレータです。
@timeout(limit=3600, topic='arn:aws:sns:xxxxxxxx:yyyyyyy')
def long_time_function():
very_very_long_calc()
#!/usr/bin/env python
import sys
import boto
import pprint
del_flag = ''
if len(sys.argv) > 1:
del_flag = sys.argv[1]
#!/usr/bin/env ruby
require 'aws-sdk'
require 'pp'
AWS.config(:proxy_uri => ENV['http_proxy'])
config_path = File.expand_path(File.dirname(__FILE__)+"/keys.yml")
AWS.config(YAML.load(File.read(config_path)))
ec2 = AWS::EC2.new
@a3linux
a3linux / motd.erb
Created September 9, 2013 23:47 — forked from harlanbarnes/motd.erb
<% if @banner -%><%= @banner -%><% end -%>
+----------------------------------------
|
| Host name: <%= node[:hostname] %>
| FQDN: <%= node[:fqdn] %>
| Distro / Arch: <%= node[:platform] %> <%= node[:platform_version] %> <%= node.kernel.machine %>
<% if node.attribute?('applogic') -%>
| App name: <%= node[:applogic][:APP_NAME] %>
| Comp name: <%= node[:applogic][:COMP_NAME] %>
<% end -%>
@a3linux
a3linux / ec2.pp
Created September 9, 2013 23:51 — forked from jperras/ec2.pp
# ec2utils: puppet recipes for use with Amazon's Elastic Compute Cloud (and
# associated services)
#
# Copyright 2009 Flock, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
from boto.iam import IAMConnection
iam = IAMConnection(aws_key, aws_secret)
iam.create_user('user')
iam.create_group('group')
iam.put_group_policy('group', 'EC2', '{"Statement":[{"Effect":"Allow","Action":"ec2:*","Resource":"*"}]}')
iam.add_user_to_group('group', 'user')
iam.create_access_key('user')
import sys
import boto
import boto.ec2
def _launchAWSInstances():
connection = boto.ec2.connect_to_region(AWS_REGION, aws_access_key_id = AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_ACCESS_KEY_SECRET)
global reservation
reservation = connection.run_instances(AWS_AMI,
key_name=AWS_SSH_KEY_NAME,
instance_type=AWS_INSTANCE_SIZE,
# list_detail.object_list replacement with all the things I need
def object_list(request, queryset, extra_context=None,
template_name='', paginate_by=None):
class ObjectList(ListView):
def post(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)
def get_context_data(self, **kwargs):
c = super(ObjectList, self).get_context_data(**kwargs)
#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''将搜狗拼音导出的文本词库转换成ibus-libpinyin的用户词典
by Conanca
'''
content = open("搜狗词库导出_2014_1_6.txt").read().decode('utf16').encode('utf8')
lines = content.split('\n')
f=open('ibus.txt','w')